Added groups
This commit is contained in:
parent
2e8ccf4849
commit
a27049568b
Binary file not shown.
62
API/Controllers/GroupCandidatesController.cs
Normal file
62
API/Controllers/GroupCandidatesController.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StudyLib.API.Data;
|
||||
using StudyLib.API.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudyLib.API.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class GroupCandidatesController : ControllerBase
|
||||
{
|
||||
private readonly StudyLibContext _context;
|
||||
|
||||
public GroupCandidatesController(StudyLibContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet("{groupId}")]
|
||||
public async Task<ActionResult<IEnumerable<GroupCandidate>>> GetGroupCandidates(long groupId)
|
||||
{
|
||||
return await _context.GroupCandidates.Where(g => g.Group.ID == groupId).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<GroupCandidate>> GroupCandidate(GroupCandidate groupCandidate)
|
||||
{
|
||||
_context.GroupCandidates.Add(groupCandidate);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction("GetGroupCandidate", groupCandidate);
|
||||
}
|
||||
|
||||
[HttpDelete("{groupId}/{userId}")]
|
||||
public async Task<IActionResult> DeleteGroupCandidate(long groupId, string userId)
|
||||
{
|
||||
var groupCandidate = await _context.GroupCandidates.Where(g => g.Group.ID == groupId && g.User.Id == userId).FirstAsync();
|
||||
if (groupCandidate == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.GroupCandidates.Remove(groupCandidate);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private bool GroupCandidateExists(long groupId, string userId)
|
||||
{
|
||||
return _context.GroupCandidates.Any(g => g.Group.ID == groupId && g.User.Id == userId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
101
API/Controllers/GroupsController.cs
Normal file
101
API/Controllers/GroupsController.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StudyLib.API.Data;
|
||||
using StudyLib.API.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudyLib.API.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GroupsController : ControllerBase
|
||||
{
|
||||
private readonly StudyLibContext _context;
|
||||
|
||||
public GroupsController(StudyLibContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Group>>> GetGroups()
|
||||
{
|
||||
return await _context.Groups.Include(g => g.Users).Include(g => g.Subjects).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Group>> GetGroup(long id)
|
||||
{
|
||||
var group = await _context.Groups.Where(g => g.ID == id).Include(g => g.Users).Include(g => g.Subjects).SingleOrDefaultAsync();
|
||||
|
||||
if (group == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutGroup(long id, Group group)
|
||||
{
|
||||
if (id != group.ID)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
_context.Entry(group).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!GroupExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Group>> PostGroup(Group group)
|
||||
{
|
||||
_context.Groups.Add(group);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction("GetGroup", new { id = group.ID }, group);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<Group>> DeleteGroup(long id)
|
||||
{
|
||||
var group = await _context.Groups.FindAsync(id);
|
||||
if (group == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.Groups.Remove(group);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
private bool GroupExists(long id)
|
||||
{
|
||||
return _context.Groups.Any(g => g.ID == id);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,5 +19,7 @@ namespace StudyLib.API.Data
|
||||
public DbSet<Test> Tests { get; set; }
|
||||
public DbSet<SubjectDeleteRequest> SubjectDeleteRequests { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Group> Groups { get; set; }
|
||||
public DbSet<GroupCandidate> GroupCandidates { get; set; }
|
||||
}
|
||||
}
|
||||
|
20
API/Models/Group.cs
Normal file
20
API/Models/Group.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using StudyLib.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudyLib.API.Models
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Year { get; set; }
|
||||
public string AdminId { get; set; }
|
||||
public ICollection<User> Users { get; set; }
|
||||
public ICollection<GroupCandidate> GroupCandidates { get; set; }
|
||||
public ICollection<Subject> Subjects { get; set; }
|
||||
}
|
||||
}
|
16
API/Models/GroupCandidate.cs
Normal file
16
API/Models/GroupCandidate.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudyLib.API.Models
|
||||
{
|
||||
public class GroupCandidate
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public long GroupId { get; set; }
|
||||
public Group Group { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace StudyLib.API.Models
|
||||
@ -6,5 +7,7 @@ namespace StudyLib.API.Models
|
||||
public class User : IdentityUser
|
||||
{
|
||||
public string FullName { get; set; }
|
||||
|
||||
public ICollection<Group> Groups { get; set; }
|
||||
}
|
||||
}
|
||||
|
566
Migrations/20201221192214_AddedAdminId.Designer.cs
generated
Normal file
566
Migrations/20201221192214_AddedAdminId.Designer.cs
generated
Normal file
@ -0,0 +1,566 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using StudyLib.API.Data;
|
||||
|
||||
namespace StudyLib.Migrations
|
||||
{
|
||||
[DbContext(typeof(StudyLibContext))]
|
||||
[Migration("20201221192214_AddedAdminId")]
|
||||
partial class AddedAdminId
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.UseIdentityColumns()
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.0");
|
||||
|
||||
modelBuilder.Entity("GroupUser", b =>
|
||||
{
|
||||
b.Property<long>("GroupsID")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("UsersId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("GroupsID", "UsersId");
|
||||
|
||||
b.HasIndex("UsersId");
|
||||
|
||||
b.ToTable("GroupUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex")
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("nvarchar(128)");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("nvarchar(128)");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("nvarchar(128)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("nvarchar(128)");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Comment", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<long>("SubjectId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Group", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<string>("AdminId")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Year")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.GroupCandidate", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<long>("GroupId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("GroupCandidates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.SubjectDeleteRequest", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<long>("SubjectId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("SubjectDeleteRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex")
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Assignment", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<DateTime>("Deadline")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("FinalMarkPercent")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<long>("SubjectId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("Assignments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Subject", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<DateTime>("ExamDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<long?>("GroupID")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("LabTeacher")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("LectureTeacher")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("MainExam")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("GroupID");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Test", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<double>("FinalMarkPercent")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("Scope")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<long>("SubjectId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("SubjectId");
|
||||
|
||||
b.ToTable("Tests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("GroupUser", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupsID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UsersId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
.WithMany("Comments")
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.GroupCandidate", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", "Group")
|
||||
.WithMany("GroupCandidates")
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("StudyLib.API.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.SubjectDeleteRequest", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
.WithMany()
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Assignment", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
.WithMany("Assignments")
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Subject", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", null)
|
||||
.WithMany("Subjects")
|
||||
.HasForeignKey("GroupID");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Test", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
.WithMany("Tests")
|
||||
.HasForeignKey("SubjectId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Group", b =>
|
||||
{
|
||||
b.Navigation("GroupCandidates");
|
||||
|
||||
b.Navigation("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Subject", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
|
||||
b.Navigation("Comments");
|
||||
|
||||
b.Navigation("Tests");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
133
Migrations/20201221192214_AddedAdminId.cs
Normal file
133
Migrations/20201221192214_AddedAdminId.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace StudyLib.Migrations
|
||||
{
|
||||
public partial class AddedAdminId : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "GroupID",
|
||||
table: "Subjects",
|
||||
type: "bigint",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Groups",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Year = table.Column<int>(type: "int", nullable: false),
|
||||
AdminId = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Groups", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "GroupCandidates",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: true),
|
||||
GroupId = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_GroupCandidates", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_GroupCandidates_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_GroupCandidates_Groups_GroupId",
|
||||
column: x => x.GroupId,
|
||||
principalTable: "Groups",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "GroupUser",
|
||||
columns: table => new
|
||||
{
|
||||
GroupsID = table.Column<long>(type: "bigint", nullable: false),
|
||||
UsersId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_GroupUser", x => new { x.GroupsID, x.UsersId });
|
||||
table.ForeignKey(
|
||||
name: "FK_GroupUser_AspNetUsers_UsersId",
|
||||
column: x => x.UsersId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_GroupUser_Groups_GroupsID",
|
||||
column: x => x.GroupsID,
|
||||
principalTable: "Groups",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Subjects_GroupID",
|
||||
table: "Subjects",
|
||||
column: "GroupID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GroupCandidates_GroupId",
|
||||
table: "GroupCandidates",
|
||||
column: "GroupId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GroupCandidates_UserId",
|
||||
table: "GroupCandidates",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GroupUser_UsersId",
|
||||
table: "GroupUser",
|
||||
column: "UsersId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Subjects_Groups_GroupID",
|
||||
table: "Subjects",
|
||||
column: "GroupID",
|
||||
principalTable: "Groups",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Subjects_Groups_GroupID",
|
||||
table: "Subjects");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "GroupCandidates");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "GroupUser");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Groups");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Subjects_GroupID",
|
||||
table: "Subjects");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "GroupID",
|
||||
table: "Subjects");
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,21 @@ namespace StudyLib.Migrations
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.0");
|
||||
|
||||
modelBuilder.Entity("GroupUser", b =>
|
||||
{
|
||||
b.Property<long>("GroupsID")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("UsersId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("GroupsID", "UsersId");
|
||||
|
||||
b.HasIndex("UsersId");
|
||||
|
||||
b.ToTable("GroupUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
@ -175,6 +190,49 @@ namespace StudyLib.Migrations
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Group", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<string>("AdminId")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Year")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.GroupCandidate", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.UseIdentityColumn();
|
||||
|
||||
b.Property<long>("GroupId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("GroupCandidates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.SubjectDeleteRequest", b =>
|
||||
{
|
||||
b.Property<long>("ID")
|
||||
@ -301,6 +359,9 @@ namespace StudyLib.Migrations
|
||||
b.Property<DateTime>("ExamDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<long?>("GroupID")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("LabTeacher")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
@ -316,6 +377,8 @@ namespace StudyLib.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("GroupID");
|
||||
|
||||
b.ToTable("Subjects");
|
||||
});
|
||||
|
||||
@ -346,6 +409,21 @@ namespace StudyLib.Migrations
|
||||
b.ToTable("Tests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("GroupUser", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("GroupsID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("StudyLib.API.Models.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UsersId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
@ -408,6 +486,23 @@ namespace StudyLib.Migrations
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.GroupCandidate", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", "Group")
|
||||
.WithMany("GroupCandidates")
|
||||
.HasForeignKey("GroupId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("StudyLib.API.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Group");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.SubjectDeleteRequest", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
@ -430,6 +525,13 @@ namespace StudyLib.Migrations
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Subject", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.API.Models.Group", null)
|
||||
.WithMany("Subjects")
|
||||
.HasForeignKey("GroupID");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Test", b =>
|
||||
{
|
||||
b.HasOne("StudyLib.Models.Subject", "Subject")
|
||||
@ -441,6 +543,13 @@ namespace StudyLib.Migrations
|
||||
b.Navigation("Subject");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.API.Models.Group", b =>
|
||||
{
|
||||
b.Navigation("GroupCandidates");
|
||||
|
||||
b.Navigation("Subjects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("StudyLib.Models.Subject", b =>
|
||||
{
|
||||
b.Navigation("Assignments");
|
||||
|
@ -22,9 +22,5 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"StudyLibContext": "Server=DESKTOP-VC7B1FD;Database=StudyLibDB;Trusted_Connection=True;MultipleActiveResultSets=true",
|
||||
"StudyLibContext": "Server=DESKTOP-VC7B1FD;Database=StudyLibDB;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
},
|
||||
"ApplicationSettings": {
|
||||
"JWTSecret": "1234567890123456789"
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
fe729000b955e513eea29f2e3a68726f74652572
|
||||
73a2189dbe3e51a4bc9dfe1696e53c26fb2ec4ea
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user