diff --git a/.vs/StudyLib/DesignTimeBuild/.dtbcache.v2 b/.vs/StudyLib/DesignTimeBuild/.dtbcache.v2 index 58a4633..640dd35 100644 Binary files a/.vs/StudyLib/DesignTimeBuild/.dtbcache.v2 and b/.vs/StudyLib/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/StudyLib/v16/.suo b/.vs/StudyLib/v16/.suo index 9214c04..5773998 100644 Binary files a/.vs/StudyLib/v16/.suo and b/.vs/StudyLib/v16/.suo differ diff --git a/API/Controllers/GroupCandidatesController.cs b/API/Controllers/GroupCandidatesController.cs index 583a48e..46134a7 100644 --- a/API/Controllers/GroupCandidatesController.cs +++ b/API/Controllers/GroupCandidatesController.cs @@ -23,13 +23,13 @@ namespace StudyLib.API.Controllers _context = context; } - [HttpGet("{groupId}")] + [HttpGet("list/{groupId}")] public async Task>> GetGroupCandidates(long groupId) { return await _context.GroupCandidates.Where(g => g.Group.ID == groupId).ToListAsync(); } - [HttpPost] + [HttpPost("join-request")] public async Task> GroupCandidate(GroupCandidate groupCandidate) { _context.GroupCandidates.Add(groupCandidate); @@ -38,7 +38,7 @@ namespace StudyLib.API.Controllers return CreatedAtAction("GetGroupCandidate", groupCandidate); } - [HttpDelete("{groupId}/{userId}")] + [HttpDelete("delete/{groupId}/{userId}")] public async Task DeleteGroupCandidate(long groupId, string userId) { var groupCandidate = await _context.GroupCandidates.Where(g => g.Group.ID == groupId && g.User.Id == userId).FirstAsync(); diff --git a/API/Controllers/GroupsController.cs b/API/Controllers/GroupsController.cs index 8a5ec98..8559fd4 100644 --- a/API/Controllers/GroupsController.cs +++ b/API/Controllers/GroupsController.cs @@ -20,13 +20,26 @@ namespace StudyLib.API.Controllers _context = context; } - [HttpGet] + [HttpGet("list")] public async Task>> GetGroups() { return await _context.Groups.Include(g => g.Users).Include(g => g.Subjects).ToListAsync(); } - [HttpGet("{id}")] + [HttpGet("current-user-groups/{userId}")] + public async Task>> GetCurrentUserGroups(string userId) + { + var user = await _context.Users.FindAsync(userId); + + if (user == null) + { + return NoContent(); + } + + return Ok(user.Groups); + } + + [HttpGet("get-by-id/{id}")] public async Task> GetGroup(long id) { var group = await _context.Groups.Where(g => g.ID == id).Include(g => g.Users).Include(g => g.Subjects).SingleOrDefaultAsync(); @@ -39,7 +52,7 @@ namespace StudyLib.API.Controllers return group; } - [HttpPut("{id}")] + [HttpPut("update/{id}")] public async Task PutGroup(long id, Group group) { if (id != group.ID) @@ -68,7 +81,37 @@ namespace StudyLib.API.Controllers return NoContent(); } - [HttpPost] + [HttpGet("leave/{id}/{userId}")] + public async Task LeaveGroup(long id, string userId) + { + var user = await _context.Users.FindAsync(userId); + + var groups = user.Groups.Where(g => g.ID != id).ToList(); + + user.Groups = groups; + + _context.Entry(user).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!GroupExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + [HttpPost("add")] public async Task> PostGroup(Group group) { _context.Groups.Add(group); @@ -78,7 +121,7 @@ namespace StudyLib.API.Controllers return CreatedAtAction("GetGroup", new { id = group.ID }, group); } - [HttpDelete("{id}")] + [HttpDelete("delete/{id}")] public async Task> DeleteGroup(long id) { var group = await _context.Groups.FindAsync(id); diff --git a/API/Controllers/SubjectDeleteRequestsController.cs b/API/Controllers/SubjectDeleteRequestsController.cs index 0bdaae5..4c2f376 100644 --- a/API/Controllers/SubjectDeleteRequestsController.cs +++ b/API/Controllers/SubjectDeleteRequestsController.cs @@ -21,13 +21,13 @@ namespace StudyLib.API.Controllers _context = context; } - [HttpGet("list")] - public async Task>> GetSubjectDeleteRequest() + [HttpGet("list-by-group-id/{groupId}")] + public async Task>> GetSubjectDeleteRequest(long groupId) { - return await _context.SubjectDeleteRequests.Include(s => s.Subject).ToListAsync(); + return await _context.SubjectDeleteRequests.Where(s => s.Subject.GroupId == groupId).Include(s => s.Subject).ToListAsync(); } - [HttpPost("approveDeletion")] + [HttpPost("approve")] public async Task> ApproveSubjectDeleteRequest(SubjectDeleteRequest deletionRequest) { var subjectDeleteRequest = await _context.SubjectDeleteRequests.Where(s => s.ID == deletionRequest.ID).Include(s => s.Subject).SingleOrDefaultAsync(); @@ -43,7 +43,7 @@ namespace StudyLib.API.Controllers return NoContent(); } - [HttpPost("addDeletionRequest")] + [HttpPost("add")] public async Task> AddSubjectDeleteRequest(SubjectDeleteRequest deletionRequest) { _context.SubjectDeleteRequests.Add(deletionRequest); @@ -52,7 +52,7 @@ namespace StudyLib.API.Controllers return NoContent(); } - [HttpDelete("cancelDeletion/{id}")] + [HttpDelete("cancel/{id}")] public async Task CancelSubjectDeleteRequest(long id) { var subjectDeleteRequest = await _context.SubjectDeleteRequests.FindAsync(id); diff --git a/API/Controllers/SubjectsController.cs b/API/Controllers/SubjectsController.cs index f8030bd..bc251f7 100644 --- a/API/Controllers/SubjectsController.cs +++ b/API/Controllers/SubjectsController.cs @@ -24,15 +24,13 @@ namespace StudyLib.API.Controllers _context = context; } - // GET: api/Subjects - [HttpGet] - public async Task>> GetSubjects() + [HttpGet("list-by-group-id/{groupId}")] + public async Task>> GetSubjects(long groupId) { - return await _context.Subjects.Include(s => s.Comments).Include(s => s.Assignments).Include(s => s.Tests).ToListAsync(); + return await _context.Subjects.Where(s => s.Group.ID == groupId).Include(s => s.Comments).Include(s => s.Assignments).Include(s => s.Tests).ToListAsync(); } - // GET: api/Subjects/5 - [HttpGet("{id}")] + [HttpGet("get-by-id/{id}")] public async Task> GetSubject(long id) { var subject = await _context.Subjects.Where(s => s.ID == id).Include(s => s.Comments).Include(s => s.Assignments).Include(s => s.Tests).SingleOrDefaultAsync(); @@ -45,10 +43,7 @@ namespace StudyLib.API.Controllers return subject; } - // PUT: api/Subjects/5 - // To protect from overposting attacks, enable the specific properties you want to bind to, for - // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. - [HttpPut("{id}")] + [HttpPut("update/{id}")] public async Task PutSubject(long id, Subject subject) { if (id != subject.ID) @@ -112,10 +107,7 @@ namespace StudyLib.API.Controllers return NoContent(); } - // POST: api/Subjects - // To protect from overposting attacks, enable the specific properties you want to bind to, for - // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. - [HttpPost] + [HttpPost("add")] public async Task> PostSubject(Subject subject) { _context.Subjects.Add(subject); @@ -126,7 +118,7 @@ namespace StudyLib.API.Controllers } // DELETE: api/Subjects/5 - [HttpDelete("{id}")] + [HttpDelete("delete/{id}")] public async Task> DeleteSubject(long id) { var subject = await _context.Subjects.FindAsync(id); diff --git a/API/Data/StudyLibDataSeeder.cs b/API/Data/StudyLibDataSeeder.cs index f560236..8bd931c 100644 --- a/API/Data/StudyLibDataSeeder.cs +++ b/API/Data/StudyLibDataSeeder.cs @@ -11,7 +11,7 @@ namespace StudyLib.API.Data public static void Initialize(StudyLibContext context) { - if (context.Subjects.Any()) + /* if (context.Subjects.Any()) { return; } @@ -60,7 +60,7 @@ namespace StudyLib.API.Data } ); - context.SaveChanges(); + context.SaveChanges();*/ } diff --git a/API/Models/Subject.cs b/API/Models/Subject.cs index 8cc96f3..6723a24 100644 --- a/API/Models/Subject.cs +++ b/API/Models/Subject.cs @@ -18,6 +18,10 @@ namespace StudyLib.Models public bool MainExam { get; set; } + public long GroupId { get; set; } + + public Group Group { get; set; } + public DateTime ExamDate { get; set; } public ICollection Tests { get; set; } diff --git a/Migrations/20201223201708_AddedGroupToSubject.Designer.cs b/Migrations/20201223201708_AddedGroupToSubject.Designer.cs new file mode 100644 index 0000000..0a0227d --- /dev/null +++ b/Migrations/20201223201708_AddedGroupToSubject.Designer.cs @@ -0,0 +1,570 @@ +// +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("20201223201708_AddedGroupToSubject")] + partial class AddedGroupToSubject + { + 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("GroupsID") + .HasColumnType("bigint"); + + b.Property("UsersId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("GroupsID", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("GroupUser"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("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", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("StudyLib.API.Models.Comment", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("SubjectId") + .HasColumnType("bigint"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.HasIndex("SubjectId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("StudyLib.API.Models.Group", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("AdminId") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("StudyLib.API.Models.GroupCandidate", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("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("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("SubjectId") + .HasColumnType("bigint"); + + b.HasKey("ID"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubjectDeleteRequests"); + }); + + modelBuilder.Entity("StudyLib.API.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("FullName") + .HasColumnType("nvarchar(max)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("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("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Deadline") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FinalMarkPercent") + .HasColumnType("float"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SubjectId") + .HasColumnType("bigint"); + + b.HasKey("ID"); + + b.HasIndex("SubjectId"); + + b.ToTable("Assignments"); + }); + + modelBuilder.Entity("StudyLib.Models.Subject", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("ExamDate") + .HasColumnType("datetime2"); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("LabTeacher") + .HasColumnType("nvarchar(max)"); + + b.Property("LectureTeacher") + .HasColumnType("nvarchar(max)"); + + b.Property("MainExam") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.HasIndex("GroupId"); + + b.ToTable("Subjects"); + }); + + modelBuilder.Entity("StudyLib.Models.Test", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .UseIdentityColumn(); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("FinalMarkPercent") + .HasColumnType("float"); + + b.Property("Scope") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("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", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("StudyLib.API.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("StudyLib.API.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", 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", 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", "Group") + .WithMany("Subjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + 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 + } + } +} diff --git a/Migrations/20201223201708_AddedGroupToSubject.cs b/Migrations/20201223201708_AddedGroupToSubject.cs new file mode 100644 index 0000000..f69c667 --- /dev/null +++ b/Migrations/20201223201708_AddedGroupToSubject.cs @@ -0,0 +1,75 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace StudyLib.Migrations +{ + public partial class AddedGroupToSubject : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Subjects_Groups_GroupID", + table: "Subjects"); + + migrationBuilder.RenameColumn( + name: "GroupID", + table: "Subjects", + newName: "GroupId"); + + migrationBuilder.RenameIndex( + name: "IX_Subjects_GroupID", + table: "Subjects", + newName: "IX_Subjects_GroupId"); + + migrationBuilder.AlterColumn( + name: "GroupId", + table: "Subjects", + type: "bigint", + nullable: false, + defaultValue: 0L, + oldClrType: typeof(long), + oldType: "bigint", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Subjects_Groups_GroupId", + table: "Subjects", + column: "GroupId", + principalTable: "Groups", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Subjects_Groups_GroupId", + table: "Subjects"); + + migrationBuilder.RenameColumn( + name: "GroupId", + table: "Subjects", + newName: "GroupID"); + + migrationBuilder.RenameIndex( + name: "IX_Subjects_GroupId", + table: "Subjects", + newName: "IX_Subjects_GroupID"); + + migrationBuilder.AlterColumn( + name: "GroupID", + table: "Subjects", + type: "bigint", + nullable: true, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AddForeignKey( + name: "FK_Subjects_Groups_GroupID", + table: "Subjects", + column: "GroupID", + principalTable: "Groups", + principalColumn: "ID", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/Migrations/StudyLibContextModelSnapshot.cs b/Migrations/StudyLibContextModelSnapshot.cs index cf98f3a..f7e8a55 100644 --- a/Migrations/StudyLibContextModelSnapshot.cs +++ b/Migrations/StudyLibContextModelSnapshot.cs @@ -359,7 +359,7 @@ namespace StudyLib.Migrations b.Property("ExamDate") .HasColumnType("datetime2"); - b.Property("GroupID") + b.Property("GroupId") .HasColumnType("bigint"); b.Property("LabTeacher") @@ -377,7 +377,7 @@ namespace StudyLib.Migrations b.HasKey("ID"); - b.HasIndex("GroupID"); + b.HasIndex("GroupId"); b.ToTable("Subjects"); }); @@ -527,9 +527,13 @@ namespace StudyLib.Migrations modelBuilder.Entity("StudyLib.Models.Subject", b => { - b.HasOne("StudyLib.API.Models.Group", null) + b.HasOne("StudyLib.API.Models.Group", "Group") .WithMany("Subjects") - .HasForeignKey("GroupID"); + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); }); modelBuilder.Entity("StudyLib.Models.Test", b => diff --git a/Program.cs b/Program.cs index 63371c8..5da24d9 100644 --- a/Program.cs +++ b/Program.cs @@ -14,7 +14,7 @@ namespace StudyLib { var services = scope.ServiceProvider; var context = services.GetService(); - StudyLibDataSeeder.Initialize(context); + //StudyLibDataSeeder.Initialize(context); } host.Run(); // CreateHostBuilder(args).Build().Run(); diff --git a/bin/Debug/net5.0/StudyLib.dll b/bin/Debug/net5.0/StudyLib.dll index f35b604..ddc55b2 100644 Binary files a/bin/Debug/net5.0/StudyLib.dll and b/bin/Debug/net5.0/StudyLib.dll differ diff --git a/bin/Debug/net5.0/StudyLib.pdb b/bin/Debug/net5.0/StudyLib.pdb index a32add5..c6ee5c3 100644 Binary files a/bin/Debug/net5.0/StudyLib.pdb and b/bin/Debug/net5.0/StudyLib.pdb differ diff --git a/bin/Debug/net5.0/ref/StudyLib.dll b/bin/Debug/net5.0/ref/StudyLib.dll index d987f15..6f29a0e 100644 Binary files a/bin/Debug/net5.0/ref/StudyLib.dll and b/bin/Debug/net5.0/ref/StudyLib.dll differ diff --git a/obj/Debug/net5.0/StudyLib.csproj.CoreCompileInputs.cache b/obj/Debug/net5.0/StudyLib.csproj.CoreCompileInputs.cache index da5ba41..f6e547c 100644 --- a/obj/Debug/net5.0/StudyLib.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net5.0/StudyLib.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -73a2189dbe3e51a4bc9dfe1696e53c26fb2ec4ea +60b4309f39d35789ac308a57134eb3df9d09f22e diff --git a/obj/Debug/net5.0/StudyLib.csprojAssemblyReference.cache b/obj/Debug/net5.0/StudyLib.csprojAssemblyReference.cache index a714065..5abd609 100644 Binary files a/obj/Debug/net5.0/StudyLib.csprojAssemblyReference.cache and b/obj/Debug/net5.0/StudyLib.csprojAssemblyReference.cache differ diff --git a/obj/Debug/net5.0/StudyLib.dll b/obj/Debug/net5.0/StudyLib.dll index f35b604..ddc55b2 100644 Binary files a/obj/Debug/net5.0/StudyLib.dll and b/obj/Debug/net5.0/StudyLib.dll differ diff --git a/obj/Debug/net5.0/StudyLib.pdb b/obj/Debug/net5.0/StudyLib.pdb index a32add5..c6ee5c3 100644 Binary files a/obj/Debug/net5.0/StudyLib.pdb and b/obj/Debug/net5.0/StudyLib.pdb differ diff --git a/obj/Debug/net5.0/ref/StudyLib.dll b/obj/Debug/net5.0/ref/StudyLib.dll index d987f15..6f29a0e 100644 Binary files a/obj/Debug/net5.0/ref/StudyLib.dll and b/obj/Debug/net5.0/ref/StudyLib.dll differ