From 44d091674e6df319b7496378e45705727683bd13 Mon Sep 17 00:00:00 2001 From: 1eG0ist Date: Thu, 12 Dec 2024 10:21:45 +0300 Subject: [PATCH] wtfMan --- data/DAO/Attendance.cs | 23 ++ data/DAO/Group.cs | 12 +- data/DAO/GroupSubject.cs | 22 ++ data/DAO/Presence.cs | 12 - data/DAO/Semester.cs | 17 + data/DAO/Student.cs | 19 + data/DAO/Subject.cs | 18 + data/DAO/User.cs | 16 - data/DAO/Visit.cs | 16 + .../20241116153223_InitialCreate.Designer.cs | 83 ----- .../20241116153223_InitialCreate.cs | 63 ---- ...0241212071056_InitialCreate123.Designer.cs | 320 +++++++++++++++++ .../20241212071056_InitialCreate123.cs | 243 +++++++++++++ .../20241212071851_InitialCreate2.Designer.cs | 320 +++++++++++++++++ .../20241212071851_InitialCreate2.cs | 243 +++++++++++++ .../20241212072022_InitialCreate2.Designer.cs | 320 +++++++++++++++++ .../20241212072022_InitialCreate2.cs | 243 +++++++++++++ .../RemoteDatabaseContextModelSnapshot.cs | 291 +++++++++++++-- data/RemoteDatabaseContext.cs | 35 +- data/Repository/IGroupRepository.cs | 56 ++- data/Repository/SQLGroupRepository.cs | 335 ++++++++++++++++-- 21 files changed, 2460 insertions(+), 247 deletions(-) create mode 100644 data/DAO/Attendance.cs create mode 100644 data/DAO/GroupSubject.cs delete mode 100644 data/DAO/Presence.cs create mode 100644 data/DAO/Semester.cs create mode 100644 data/DAO/Student.cs create mode 100644 data/DAO/Subject.cs delete mode 100644 data/DAO/User.cs create mode 100644 data/DAO/Visit.cs delete mode 100644 data/Migrations/20241116153223_InitialCreate.Designer.cs delete mode 100644 data/Migrations/20241116153223_InitialCreate.cs create mode 100644 data/Migrations/20241212071056_InitialCreate123.Designer.cs create mode 100644 data/Migrations/20241212071056_InitialCreate123.cs create mode 100644 data/Migrations/20241212071851_InitialCreate2.Designer.cs create mode 100644 data/Migrations/20241212071851_InitialCreate2.cs create mode 100644 data/Migrations/20241212072022_InitialCreate2.Designer.cs create mode 100644 data/Migrations/20241212072022_InitialCreate2.cs diff --git a/data/DAO/Attendance.cs b/data/DAO/Attendance.cs new file mode 100644 index 0000000..05881a0 --- /dev/null +++ b/data/DAO/Attendance.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class Attendance + { + public int AttendanceId { get; set; } + public DateOnly Date { get; set; } + public int GroupSubjectId { get; set; } + public virtual GroupSubject GroupSubject { get; set; } + public int StudentId { get; set; } + public virtual Student Student { get; set; } + public int GroupId { get; set; } + public virtual Group Group { get; set; } + public int VisitId { get; set; } + public virtual Visit Visit { get; set; } + public int LessonNumber { get; set; } + } +} diff --git a/data/DAO/Group.cs b/data/DAO/Group.cs index 10a1d0f..1de58be 100644 --- a/data/DAO/Group.cs +++ b/data/DAO/Group.cs @@ -4,13 +4,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace data.DAO +namespace Data.DAO { - public class GroupDAO + public class Group { - public int Id { get; set; } - public String Name { get; set; } - public virtual IEnumerable Users { get; set; } + public int GroupId { get; set; } + public string GroupName { get; set; } + public virtual IEnumerable Students { get; set; } + public virtual ICollection Subjects { get; set; } + public virtual ICollection GroupSubjects { get; set; } } } diff --git a/data/DAO/GroupSubject.cs b/data/DAO/GroupSubject.cs new file mode 100644 index 0000000..d52a8f3 --- /dev/null +++ b/data/DAO/GroupSubject.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class GroupSubject + { + public int GroupSubjectId { get; set; } + + public int SemesterId { get; set; } + public virtual Semester Semester { get; set; } + public int GroupId { get; set; } + public int SubjectId { get; set; } + public virtual Group Group { get; set; } + public virtual Subject Subject { get; set; } + + public virtual ICollection Attendances { get; set; } + } +} diff --git a/data/DAO/Presence.cs b/data/DAO/Presence.cs deleted file mode 100644 index 2fb92e5..0000000 --- a/data/DAO/Presence.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace data.DAO -{ - internal class Presence - { - } -} diff --git a/data/DAO/Semester.cs b/data/DAO/Semester.cs new file mode 100644 index 0000000..29cafcb --- /dev/null +++ b/data/DAO/Semester.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class Semester + { + public int SemesterId { get; set; } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } + + public virtual ICollection GroupSubjects { get; set; } + } +} diff --git a/data/DAO/Student.cs b/data/DAO/Student.cs new file mode 100644 index 0000000..374bef5 --- /dev/null +++ b/data/DAO/Student.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class Student + { + public int StudentId { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Patronymic { get; set; } + public int GroupId { get; set; } + public virtual Group Group { get; set; } + public virtual ICollection Attendances { get; set; } + } +} diff --git a/data/DAO/Subject.cs b/data/DAO/Subject.cs new file mode 100644 index 0000000..1a2ad94 --- /dev/null +++ b/data/DAO/Subject.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class Subject + { + public int SubjectId { get; set; } + public string SubjectName { get; set; } + public int GroupId { get; set; } + public virtual Group Group { get; set; } + + public virtual ICollection GroupSubjects { get; set; } + } +} diff --git a/data/DAO/User.cs b/data/DAO/User.cs deleted file mode 100644 index 385afa6..0000000 --- a/data/DAO/User.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace data.DAO -{ - public class UserDAO - { - public Guid Guid { get; set; } - public string Name { get; set; } - public virtual GroupDAO Group { get; set; } - - } -} diff --git a/data/DAO/Visit.cs b/data/DAO/Visit.cs new file mode 100644 index 0000000..09fdcfc --- /dev/null +++ b/data/DAO/Visit.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data.DAO +{ + public class Visit + { + public int VisitId { get; set; } + public string VisitName { get; set; } + + public virtual ICollection Attendances { get; set; } + } +} diff --git a/data/Migrations/20241116153223_InitialCreate.Designer.cs b/data/Migrations/20241116153223_InitialCreate.Designer.cs deleted file mode 100644 index 84632d7..0000000 --- a/data/Migrations/20241116153223_InitialCreate.Designer.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using data; - -#nullable disable - -namespace data.Migrations -{ - [DbContext(typeof(RemoteDatabaseContext))] - [Migration("20241116153223_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.10") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("data.DAO.GroupDAO", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("groups"); - }); - - modelBuilder.Entity("data.DAO.UserDAO", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Guid"); - - b.HasIndex("GroupId"); - - b.ToTable("users"); - }); - - modelBuilder.Entity("data.DAO.UserDAO", b => - { - b.HasOne("data.DAO.GroupDAO", "Group") - .WithMany("Users") - .HasForeignKey("GroupId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Group"); - }); - - modelBuilder.Entity("data.DAO.GroupDAO", b => - { - b.Navigation("Users"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/data/Migrations/20241116153223_InitialCreate.cs b/data/Migrations/20241116153223_InitialCreate.cs deleted file mode 100644 index d14854e..0000000 --- a/data/Migrations/20241116153223_InitialCreate.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace data.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "groups", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_groups", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "users", - columns: table => new - { - Guid = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "text", nullable: false), - GroupId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_users", x => x.Guid); - table.ForeignKey( - name: "FK_users_groups_GroupId", - column: x => x.GroupId, - principalTable: "groups", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_users_GroupId", - table: "users", - column: "GroupId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "users"); - - migrationBuilder.DropTable( - name: "groups"); - } - } -} diff --git a/data/Migrations/20241212071056_InitialCreate123.Designer.cs b/data/Migrations/20241212071056_InitialCreate123.Designer.cs new file mode 100644 index 0000000..bda813c --- /dev/null +++ b/data/Migrations/20241212071056_InitialCreate123.Designer.cs @@ -0,0 +1,320 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using data; + +#nullable disable + +namespace data.Migrations +{ + [DbContext(typeof(RemoteDatabaseContext))] + [Migration("20241212071056_InitialCreate123")] + partial class InitialCreate123 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.Property("AttendanceId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AttendanceId")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("GroupSubjectId") + .HasColumnType("integer"); + + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("VisitId") + .HasColumnType("integer"); + + b.HasKey("AttendanceId"); + + b.HasIndex("GroupId"); + + b.HasIndex("GroupSubjectId"); + + b.HasIndex("StudentId"); + + b.HasIndex("VisitId"); + + b.ToTable("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Property("GroupId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupId")); + + b.Property("GroupName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("GroupId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Property("GroupSubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupSubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SemesterId") + .HasColumnType("integer"); + + b.Property("SubjectId") + .HasColumnType("integer"); + + b.HasKey("GroupSubjectId"); + + b.HasIndex("GroupId"); + + b.HasIndex("SemesterId"); + + b.HasIndex("SubjectId"); + + b.ToTable("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Property("SemesterId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SemesterId")); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("SemesterId"); + + b.ToTable("Semesters"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Property("StudentId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("StudentId")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("StudentId"); + + b.HasIndex("GroupId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Property("SubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SubjectName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("SubjectId"); + + b.HasIndex("GroupId"); + + b.ToTable("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Property("VisitId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VisitId")); + + b.Property("VisitName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("VisitId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.GroupSubject", "GroupSubject") + .WithMany("Attendances") + .HasForeignKey("GroupSubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Student", "Student") + .WithMany("Attendances") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Visit", "Visit") + .WithMany("Attendances") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("GroupSubject"); + + b.Navigation("Student"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("GroupSubjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Semester", "Semester") + .WithMany("GroupSubjects") + .HasForeignKey("SemesterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Subject", "Subject") + .WithMany("GroupSubjects") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("Semester"); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Students") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Subjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Navigation("GroupSubjects"); + + b.Navigation("Students"); + + b.Navigation("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Navigation("Attendances"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/data/Migrations/20241212071056_InitialCreate123.cs b/data/Migrations/20241212071056_InitialCreate123.cs new file mode 100644 index 0000000..8297a5b --- /dev/null +++ b/data/Migrations/20241212071056_InitialCreate123.cs @@ -0,0 +1,243 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace data.Migrations +{ + /// + public partial class InitialCreate123 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + GroupId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + GroupName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.GroupId); + }); + + migrationBuilder.CreateTable( + name: "Semesters", + columns: table => new + { + SemesterId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StartTime = table.Column(type: "timestamp with time zone", nullable: false), + EndTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Semesters", x => x.SemesterId); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + VisitId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + VisitName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.VisitId); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + StudentId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + Patronymic = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.StudentId); + table.ForeignKey( + name: "FK_Students_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Subjects", + columns: table => new + { + SubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SubjectName = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subjects", x => x.SubjectId); + table.ForeignKey( + name: "FK_Subjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "GroupSubjects", + columns: table => new + { + GroupSubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SemesterId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + SubjectId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GroupSubjects", x => x.GroupSubjectId); + table.ForeignKey( + name: "FK_GroupSubjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Semesters_SemesterId", + column: x => x.SemesterId, + principalTable: "Semesters", + principalColumn: "SemesterId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Subjects_SubjectId", + column: x => x.SubjectId, + principalTable: "Subjects", + principalColumn: "SubjectId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Attendances", + columns: table => new + { + AttendanceId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + GroupSubjectId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + VisitId = table.Column(type: "integer", nullable: false), + LessonNumber = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Attendances", x => x.AttendanceId); + table.ForeignKey( + name: "FK_Attendances_GroupSubjects_GroupSubjectId", + column: x => x.GroupSubjectId, + principalTable: "GroupSubjects", + principalColumn: "GroupSubjectId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "StudentId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "VisitId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupId", + table: "Attendances", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupSubjectId", + table: "Attendances", + column: "GroupSubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_StudentId", + table: "Attendances", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_VisitId", + table: "Attendances", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_GroupId", + table: "GroupSubjects", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SemesterId", + table: "GroupSubjects", + column: "SemesterId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SubjectId", + table: "GroupSubjects", + column: "SubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Students_GroupId", + table: "Students", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Subjects_GroupId", + table: "Subjects", + column: "GroupId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attendances"); + + migrationBuilder.DropTable( + name: "GroupSubjects"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Semesters"); + + migrationBuilder.DropTable( + name: "Subjects"); + + migrationBuilder.DropTable( + name: "Groups"); + } + } +} diff --git a/data/Migrations/20241212071851_InitialCreate2.Designer.cs b/data/Migrations/20241212071851_InitialCreate2.Designer.cs new file mode 100644 index 0000000..7aff100 --- /dev/null +++ b/data/Migrations/20241212071851_InitialCreate2.Designer.cs @@ -0,0 +1,320 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using data; + +#nullable disable + +namespace data.Migrations +{ + [DbContext(typeof(RemoteDatabaseContext))] + [Migration("20241212071851_InitialCreate2")] + partial class InitialCreate2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.Property("AttendanceId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AttendanceId")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("GroupSubjectId") + .HasColumnType("integer"); + + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("VisitId") + .HasColumnType("integer"); + + b.HasKey("AttendanceId"); + + b.HasIndex("GroupId"); + + b.HasIndex("GroupSubjectId"); + + b.HasIndex("StudentId"); + + b.HasIndex("VisitId"); + + b.ToTable("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Property("GroupId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupId")); + + b.Property("GroupName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("GroupId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Property("GroupSubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupSubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SemesterId") + .HasColumnType("integer"); + + b.Property("SubjectId") + .HasColumnType("integer"); + + b.HasKey("GroupSubjectId"); + + b.HasIndex("GroupId"); + + b.HasIndex("SemesterId"); + + b.HasIndex("SubjectId"); + + b.ToTable("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Property("SemesterId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SemesterId")); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("SemesterId"); + + b.ToTable("Semesters"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Property("StudentId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("StudentId")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("StudentId"); + + b.HasIndex("GroupId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Property("SubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SubjectName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("SubjectId"); + + b.HasIndex("GroupId"); + + b.ToTable("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Property("VisitId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VisitId")); + + b.Property("VisitName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("VisitId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.GroupSubject", "GroupSubject") + .WithMany("Attendances") + .HasForeignKey("GroupSubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Student", "Student") + .WithMany("Attendances") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Visit", "Visit") + .WithMany("Attendances") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("GroupSubject"); + + b.Navigation("Student"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("GroupSubjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Semester", "Semester") + .WithMany("GroupSubjects") + .HasForeignKey("SemesterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Subject", "Subject") + .WithMany("GroupSubjects") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("Semester"); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Students") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Subjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Navigation("GroupSubjects"); + + b.Navigation("Students"); + + b.Navigation("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Navigation("Attendances"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/data/Migrations/20241212071851_InitialCreate2.cs b/data/Migrations/20241212071851_InitialCreate2.cs new file mode 100644 index 0000000..4239d81 --- /dev/null +++ b/data/Migrations/20241212071851_InitialCreate2.cs @@ -0,0 +1,243 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace data.Migrations +{ + /// + public partial class InitialCreate2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + GroupId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + GroupName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.GroupId); + }); + + migrationBuilder.CreateTable( + name: "Semesters", + columns: table => new + { + SemesterId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StartTime = table.Column(type: "timestamp with time zone", nullable: false), + EndTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Semesters", x => x.SemesterId); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + VisitId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + VisitName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.VisitId); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + StudentId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + Patronymic = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.StudentId); + table.ForeignKey( + name: "FK_Students_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Subjects", + columns: table => new + { + SubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SubjectName = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subjects", x => x.SubjectId); + table.ForeignKey( + name: "FK_Subjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "GroupSubjects", + columns: table => new + { + GroupSubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SemesterId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + SubjectId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GroupSubjects", x => x.GroupSubjectId); + table.ForeignKey( + name: "FK_GroupSubjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Semesters_SemesterId", + column: x => x.SemesterId, + principalTable: "Semesters", + principalColumn: "SemesterId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Subjects_SubjectId", + column: x => x.SubjectId, + principalTable: "Subjects", + principalColumn: "SubjectId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Attendances", + columns: table => new + { + AttendanceId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + GroupSubjectId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + VisitId = table.Column(type: "integer", nullable: false), + LessonNumber = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Attendances", x => x.AttendanceId); + table.ForeignKey( + name: "FK_Attendances_GroupSubjects_GroupSubjectId", + column: x => x.GroupSubjectId, + principalTable: "GroupSubjects", + principalColumn: "GroupSubjectId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "StudentId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "VisitId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupId", + table: "Attendances", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupSubjectId", + table: "Attendances", + column: "GroupSubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_StudentId", + table: "Attendances", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_VisitId", + table: "Attendances", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_GroupId", + table: "GroupSubjects", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SemesterId", + table: "GroupSubjects", + column: "SemesterId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SubjectId", + table: "GroupSubjects", + column: "SubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Students_GroupId", + table: "Students", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Subjects_GroupId", + table: "Subjects", + column: "GroupId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attendances"); + + migrationBuilder.DropTable( + name: "GroupSubjects"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Semesters"); + + migrationBuilder.DropTable( + name: "Subjects"); + + migrationBuilder.DropTable( + name: "Groups"); + } + } +} diff --git a/data/Migrations/20241212072022_InitialCreate2.Designer.cs b/data/Migrations/20241212072022_InitialCreate2.Designer.cs new file mode 100644 index 0000000..6b81669 --- /dev/null +++ b/data/Migrations/20241212072022_InitialCreate2.Designer.cs @@ -0,0 +1,320 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using data; + +#nullable disable + +namespace data.Migrations +{ + [DbContext(typeof(RemoteDatabaseContext))] + [Migration("20241212072022_InitialCreate2")] + partial class InitialCreate2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.Property("AttendanceId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AttendanceId")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("GroupSubjectId") + .HasColumnType("integer"); + + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("VisitId") + .HasColumnType("integer"); + + b.HasKey("AttendanceId"); + + b.HasIndex("GroupId"); + + b.HasIndex("GroupSubjectId"); + + b.HasIndex("StudentId"); + + b.HasIndex("VisitId"); + + b.ToTable("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Property("GroupId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupId")); + + b.Property("GroupName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("GroupId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Property("GroupSubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupSubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SemesterId") + .HasColumnType("integer"); + + b.Property("SubjectId") + .HasColumnType("integer"); + + b.HasKey("GroupSubjectId"); + + b.HasIndex("GroupId"); + + b.HasIndex("SemesterId"); + + b.HasIndex("SubjectId"); + + b.ToTable("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Property("SemesterId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SemesterId")); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("SemesterId"); + + b.ToTable("Semesters"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Property("StudentId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("StudentId")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("StudentId"); + + b.HasIndex("GroupId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Property("SubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SubjectName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("SubjectId"); + + b.HasIndex("GroupId"); + + b.ToTable("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Property("VisitId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VisitId")); + + b.Property("VisitName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("VisitId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.GroupSubject", "GroupSubject") + .WithMany("Attendances") + .HasForeignKey("GroupSubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Student", "Student") + .WithMany("Attendances") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Visit", "Visit") + .WithMany("Attendances") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("GroupSubject"); + + b.Navigation("Student"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("GroupSubjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Semester", "Semester") + .WithMany("GroupSubjects") + .HasForeignKey("SemesterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Subject", "Subject") + .WithMany("GroupSubjects") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("Semester"); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Students") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Subjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Navigation("GroupSubjects"); + + b.Navigation("Students"); + + b.Navigation("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Navigation("Attendances"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/data/Migrations/20241212072022_InitialCreate2.cs b/data/Migrations/20241212072022_InitialCreate2.cs new file mode 100644 index 0000000..4239d81 --- /dev/null +++ b/data/Migrations/20241212072022_InitialCreate2.cs @@ -0,0 +1,243 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace data.Migrations +{ + /// + public partial class InitialCreate2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Groups", + columns: table => new + { + GroupId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + GroupName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Groups", x => x.GroupId); + }); + + migrationBuilder.CreateTable( + name: "Semesters", + columns: table => new + { + SemesterId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StartTime = table.Column(type: "timestamp with time zone", nullable: false), + EndTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Semesters", x => x.SemesterId); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + VisitId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + VisitName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.VisitId); + }); + + migrationBuilder.CreateTable( + name: "Students", + columns: table => new + { + StudentId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + Patronymic = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Students", x => x.StudentId); + table.ForeignKey( + name: "FK_Students_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Subjects", + columns: table => new + { + SubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SubjectName = table.Column(type: "text", nullable: false), + GroupId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subjects", x => x.SubjectId); + table.ForeignKey( + name: "FK_Subjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "GroupSubjects", + columns: table => new + { + GroupSubjectId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SemesterId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + SubjectId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GroupSubjects", x => x.GroupSubjectId); + table.ForeignKey( + name: "FK_GroupSubjects_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Semesters_SemesterId", + column: x => x.SemesterId, + principalTable: "Semesters", + principalColumn: "SemesterId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GroupSubjects_Subjects_SubjectId", + column: x => x.SubjectId, + principalTable: "Subjects", + principalColumn: "SubjectId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Attendances", + columns: table => new + { + AttendanceId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + GroupSubjectId = table.Column(type: "integer", nullable: false), + StudentId = table.Column(type: "integer", nullable: false), + GroupId = table.Column(type: "integer", nullable: false), + VisitId = table.Column(type: "integer", nullable: false), + LessonNumber = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Attendances", x => x.AttendanceId); + table.ForeignKey( + name: "FK_Attendances_GroupSubjects_GroupSubjectId", + column: x => x.GroupSubjectId, + principalTable: "GroupSubjects", + principalColumn: "GroupSubjectId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Groups_GroupId", + column: x => x.GroupId, + principalTable: "Groups", + principalColumn: "GroupId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Students_StudentId", + column: x => x.StudentId, + principalTable: "Students", + principalColumn: "StudentId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Attendances_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "VisitId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupId", + table: "Attendances", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_GroupSubjectId", + table: "Attendances", + column: "GroupSubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_StudentId", + table: "Attendances", + column: "StudentId"); + + migrationBuilder.CreateIndex( + name: "IX_Attendances_VisitId", + table: "Attendances", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_GroupId", + table: "GroupSubjects", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SemesterId", + table: "GroupSubjects", + column: "SemesterId"); + + migrationBuilder.CreateIndex( + name: "IX_GroupSubjects_SubjectId", + table: "GroupSubjects", + column: "SubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Students_GroupId", + table: "Students", + column: "GroupId"); + + migrationBuilder.CreateIndex( + name: "IX_Subjects_GroupId", + table: "Subjects", + column: "GroupId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attendances"); + + migrationBuilder.DropTable( + name: "GroupSubjects"); + + migrationBuilder.DropTable( + name: "Students"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Semesters"); + + migrationBuilder.DropTable( + name: "Subjects"); + + migrationBuilder.DropTable( + name: "Groups"); + } + } +} diff --git a/data/Migrations/RemoteDatabaseContextModelSnapshot.cs b/data/Migrations/RemoteDatabaseContextModelSnapshot.cs index c5848d9..4ea2eb7 100644 --- a/data/Migrations/RemoteDatabaseContextModelSnapshot.cs +++ b/data/Migrations/RemoteDatabaseContextModelSnapshot.cs @@ -22,47 +22,244 @@ namespace data.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("data.DAO.GroupDAO", b => + modelBuilder.Entity("Data.DAO.Attendance", b => { - b.Property("Id") + b.Property("AttendanceId") .ValueGeneratedOnAdd() .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AttendanceId")); - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("groups"); - }); - - modelBuilder.Entity("data.DAO.UserDAO", b => - { - b.Property("Guid") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + b.Property("Date") + .HasColumnType("date"); b.Property("GroupId") .HasColumnType("integer"); - b.Property("Name") - .IsRequired() - .HasColumnType("text"); + b.Property("GroupSubjectId") + .HasColumnType("integer"); - b.HasKey("Guid"); + b.Property("LessonNumber") + .HasColumnType("integer"); + + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("VisitId") + .HasColumnType("integer"); + + b.HasKey("AttendanceId"); b.HasIndex("GroupId"); - b.ToTable("users"); + b.HasIndex("GroupSubjectId"); + + b.HasIndex("StudentId"); + + b.HasIndex("VisitId"); + + b.ToTable("Attendances"); }); - modelBuilder.Entity("data.DAO.UserDAO", b => + modelBuilder.Entity("Data.DAO.Group", b => { - b.HasOne("data.DAO.GroupDAO", "Group") - .WithMany("Users") + b.Property("GroupId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupId")); + + b.Property("GroupName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("GroupId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Property("GroupSubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("GroupSubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SemesterId") + .HasColumnType("integer"); + + b.Property("SubjectId") + .HasColumnType("integer"); + + b.HasKey("GroupSubjectId"); + + b.HasIndex("GroupId"); + + b.HasIndex("SemesterId"); + + b.HasIndex("SubjectId"); + + b.ToTable("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Property("SemesterId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SemesterId")); + + b.Property("EndTime") + .HasColumnType("timestamp with time zone"); + + b.Property("StartTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("SemesterId"); + + b.ToTable("Semesters"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Property("StudentId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("StudentId")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("StudentId"); + + b.HasIndex("GroupId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Property("SubjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SubjectId")); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("SubjectName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("SubjectId"); + + b.HasIndex("GroupId"); + + b.ToTable("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Property("VisitId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("VisitId")); + + b.Property("VisitName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("VisitId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("Data.DAO.Attendance", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.GroupSubject", "GroupSubject") + .WithMany("Attendances") + .HasForeignKey("GroupSubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Student", "Student") + .WithMany("Attendances") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Visit", "Visit") + .WithMany("Attendances") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("GroupSubject"); + + b.Navigation("Student"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("GroupSubjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Semester", "Semester") + .WithMany("GroupSubjects") + .HasForeignKey("SemesterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Data.DAO.Subject", "Subject") + .WithMany("GroupSubjects") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("Semester"); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Students") .HasForeignKey("GroupId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -70,9 +267,49 @@ namespace data.Migrations b.Navigation("Group"); }); - modelBuilder.Entity("data.DAO.GroupDAO", b => + modelBuilder.Entity("Data.DAO.Subject", b => { - b.Navigation("Users"); + b.HasOne("Data.DAO.Group", "Group") + .WithMany("Subjects") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("Data.DAO.Group", b => + { + b.Navigation("GroupSubjects"); + + b.Navigation("Students"); + + b.Navigation("Subjects"); + }); + + modelBuilder.Entity("Data.DAO.GroupSubject", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Semester", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Student", b => + { + b.Navigation("Attendances"); + }); + + modelBuilder.Entity("Data.DAO.Subject", b => + { + b.Navigation("GroupSubjects"); + }); + + modelBuilder.Entity("Data.DAO.Visit", b => + { + b.Navigation("Attendances"); }); #pragma warning restore 612, 618 } diff --git a/data/RemoteDatabaseContext.cs b/data/RemoteDatabaseContext.cs index b8ba21e..36cd3a6 100644 --- a/data/RemoteDatabaseContext.cs +++ b/data/RemoteDatabaseContext.cs @@ -1,4 +1,4 @@ -using data.DAO; +using Data.DAO; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -15,18 +15,37 @@ namespace data optionsBuilder.UseNpgsql("Host=localhost;port=5432;Password=admin;Username=postgres;Database=semesterWork"); } - public DbSet groups { get; set; } + //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + //{ + // optionsBuilder.UseNpgsql("Host=45.67.56.214; Port=5454; Username=user3; Password=VOTfZ8PQ; Database=user3"); + //} - public DbSet users { get; set; } + + public DbSet Groups { get; set; } + public DbSet Students { get; set; } + public DbSet Attendances { get; set; } + public DbSet GroupSubjects { get; set; } + public DbSet Semesters { get; set; } + public DbSet Subjects { get; set; } + public DbSet Visits { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasKey(it => it.Guid); - modelBuilder.Entity().HasKey(it => it.Id); - - modelBuilder.Entity().Property(it => it.Guid).ValueGeneratedOnAdd(); - modelBuilder.Entity().Property(it => it.Id).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(it => it.StudentId); + modelBuilder.Entity().HasKey(it => it.GroupId); + modelBuilder.Entity().HasKey(it => it.GroupSubjectId); + modelBuilder.Entity().HasKey(it => it.SemesterId); + modelBuilder.Entity().HasKey(it => it.VisitId); + modelBuilder.Entity().HasKey(it => it.SubjectId); + modelBuilder.Entity().HasKey(it => it.AttendanceId); + modelBuilder.Entity().Property(it => it.StudentId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.GroupId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.GroupSubjectId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.SemesterId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.VisitId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.SubjectId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(it => it.AttendanceId).ValueGeneratedOnAdd(); } } } diff --git a/data/Repository/IGroupRepository.cs b/data/Repository/IGroupRepository.cs index 5bee0c6..f497497 100644 --- a/data/Repository/IGroupRepository.cs +++ b/data/Repository/IGroupRepository.cs @@ -1,4 +1,4 @@ -using data.DAO; +using Data.DAO; using System; using System.Collections.Generic; using System.Linq; @@ -9,9 +9,55 @@ namespace data.Repository { public interface IGroupRepository { - public IEnumerable getAllGroup(); - public Task> getAllGroupAsync(); - public bool addGroup(GroupDAO group); - public bool addGroupWithStudents(GroupDAO group, IEnumerable userDAOs); + public IEnumerable GetAllGroup(); + + public bool AddGroup(Group group); + + public bool addGroupWithStudent(Group groups, IEnumerable students); + + public bool DeleteGroup(int groupId); + + public Group GetGroupWithSubjects(int groupId); + + public void AddStudentsToGroup(List students); + + public Group GetGroupById(int groupId); + + + public Subject GetSubjectById(int subjectId); + + public Subject GetSubjectByName(string subjectName); + + public void AddSubject(Subject subject); + + List GetGroupSubjects(int groupId); + + List GetSubjectsByGroupId(int groupId); + + bool AddSubjectToGroup(int groupId, Subject subject); + + + public void DeleteAllAttendances(); + public void DeleteAttendancesByGroup(int groupId); + + + void AddAttendance(Attendance attendance); + + + Visit GetVisitById(int visitId); + + + int GetGroupIdBySubjectName(string subjectName); + + public IEnumerable GetAttendances(int groupId, string subject = null, DateTime? date = null, int? studentId = null); + + Attendance GetAttendanceByDateStudentAndLesson(DateTime date, int studentId, int lessonNumber); + void UpdateAttendance(Attendance attendance); + + void RemoveStudentsFromGroup(int groupId); + + + void RemoveStudentsFromGroupByIds(int groupId, List studentIds); + } } diff --git a/data/Repository/SQLGroupRepository.cs b/data/Repository/SQLGroupRepository.cs index 25bcdbb..27e6430 100644 --- a/data/Repository/SQLGroupRepository.cs +++ b/data/Repository/SQLGroupRepository.cs @@ -1,4 +1,4 @@ -using data.DAO; +using Data.DAO; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -9,60 +9,339 @@ using System.Threading.Tasks; namespace data.Repository { public class SQLGroupRepository : IGroupRepository + { - public readonly RemoteDatabaseContext dbContext; - public SQLGroupRepository(RemoteDatabaseContext remoteDatabaseContext) + private readonly RemoteDatabaseContext _dbContext; + public SQLGroupRepository(RemoteDatabaseContext remoteDatabaseContext) { _dbContext = remoteDatabaseContext; } + + public bool AddGroup(Group group) { - dbContext = remoteDatabaseContext; + var maxGroupId = _dbContext.Groups.Max(g => (int?)g.GroupId) ?? 0; + + group.GroupId = maxGroupId + 1; + + _dbContext.Groups.Add(group); + return _dbContext.SaveChanges() > 0; } - public bool addGroup(GroupDAO group) + + + public bool addGroupWithStudent(Group groups, IEnumerable students) { + using var transaction = _dbContext.Database.BeginTransaction(); try { - dbContext.groups.Add(group); - return dbContext.SaveChanges() > 1; + _dbContext.Groups.Add(groups); + _dbContext.SaveChanges(); + + _dbContext.Groups.Add(groups); + foreach (var item in students) + { + item.Group = groups; + _dbContext.Students.Add(item); + } + + + _dbContext.SaveChanges(); + transaction.Commit(); + return true; } - catch (Exception ex) { + catch (Exception ex) + { + transaction.Rollback(); + Console.WriteLine(ex.Message); return false; } } - public IEnumerable getAllGroup() + public void AddStudentsToGroup(List students) { - try + var maxStudentId = _dbContext.Students.Max(s => (int?)s.StudentId) ?? 0; + + foreach (var student in students) { - return dbContext.groups.Include(group => group.Users).ToList(); - } - catch (Exception ex) { - return new List(); + student.StudentId = ++maxStudentId; } + + _dbContext.Students.AddRange(students); + _dbContext.SaveChanges(); } - public bool addGroupWithStudents(GroupDAO groupDAO, IEnumerable userDAOs) + + public bool DeleteGroup(int groupId) { - using var transaction = dbContext.Database.BeginTransaction(); + using var transaction = _dbContext.Database.BeginTransaction(); try { - dbContext.groups.Add(groupDAO); - dbContext.SaveChanges(); - foreach (var item in userDAOs) + var group = _dbContext.Groups + .Include(g => g.Students) + .FirstOrDefault(g => g.GroupId == groupId); + + if (group != null) { - item.Group = groupDAO; - dbContext.users.Add(item); + _dbContext.Students.RemoveRange(group.Students); + _dbContext.Groups.Remove(group); + _dbContext.SaveChanges(); + transaction.Commit(); + return true; } - dbContext.SaveChanges(); - transaction.Commit(); - return true; - } catch + return false; + } + catch { transaction.Rollback(); + throw; } - return false; } - public async Task> getAllGroupAsync() + public IEnumerable GetAllGroup() { - return await dbContext.groups.Include(group => group.Users).ToListAsync(); + return _dbContext.Groups + .Include(group => group.Students) + .Include(group => group.GroupSubjects) + .ThenInclude(gs => gs.Subject) + .ToList(); + } + + public Group GetGroupById(int groupId) + { + return _dbContext.Groups + .Include(group => group.Students) + .Include(group => group.Subjects) + .FirstOrDefault(group => group.GroupId == groupId); + } + + public Group GetGroupWithSubjects(int groupId) + { + return _dbContext.Groups + .Include(group => group.Subjects) + .FirstOrDefault(group => group.GroupId == groupId); + } + + public void AddSubjectsToGroup(List groupSubjects) + { + using var transaction = _dbContext.Database.BeginTransaction(); + try + { + foreach (var groupSubject in groupSubjects) + { + var group = _dbContext.Groups.Include(g => g.Subjects).FirstOrDefault(g => g.GroupId == groupSubject.GroupId); + if (group == null) + { + throw new KeyNotFoundException($"Group with ID {groupSubject.GroupId} not found."); + } + + var subject = _dbContext.Subjects.FirstOrDefault(s => s.SubjectId == groupSubject.SubjectId); + if (subject == null) + { + throw new KeyNotFoundException($"Group with ID {groupSubject.SubjectId} not found."); + } + + if (!group.Subjects.Any(s => s.SubjectId == subject.SubjectId)) + { + group.Subjects.Add(subject); + } + } + + _dbContext.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public Subject GetSubjectById(int subjectId) + { + return _dbContext.Subjects.FirstOrDefault(s => s.SubjectId == subjectId); + } + + public Subject GetSubjectByName(string subjectName) + { + return _dbContext.Subjects.FirstOrDefault(s => s.SubjectName == subjectName); + } + + public void AddSubject(Subject subject) + { + _dbContext.Subjects.Add(subject); + _dbContext.SaveChanges(); + } + + + public List GetGroupSubjects(int groupId) + { + return _dbContext.Groups + .Where(group => group.GroupId == groupId) + .SelectMany(group => group.Subjects) + .ToList(); + } + + public Subject GetSubjectByGroup(int subjectId) + { + var groupSubject = _dbContext.GroupSubjects + .Include(gs => gs.Subject) + .FirstOrDefault(gs => gs.SubjectId == subjectId); + + if (groupSubject == null || groupSubject.Subject == null) + { + throw new KeyNotFoundException($"Предмет с ID {subjectId} не найден."); + } + + return groupSubject.Subject; + } + + public List GetSubjectsByGroupId(int groupId) + { + var group = _dbContext.Groups + .Include(g => g.GroupSubjects) + .ThenInclude(gs => gs.Subject) + .FirstOrDefault(g => g.GroupId == groupId); + + if (group == null) + { + throw new KeyNotFoundException($"Группа с ID {groupId} не найдена."); + } + + return group.GroupSubjects + .Select(gs => gs.Subject) + .ToList(); + } + + public bool AddSubjectToGroup(int groupId, Subject subject) + { + using (var transaction = _dbContext.Database.BeginTransaction()) + { + try + { + var group = _dbContext.Groups.Include(g => g.Subjects).FirstOrDefault(g => g.GroupId == groupId); + + if (group == null) + { + transaction.Rollback(); + return false; + } + + int maxSubjectId = _dbContext.Subjects.Any() + ? _dbContext.Subjects.Max(s => s.SubjectId) + : 0; + + subject.SubjectId = maxSubjectId + 1; + subject.Group = group; + + _dbContext.Subjects.Add(subject); + + _dbContext.SaveChanges(); + + transaction.Commit(); + return true; + } + catch (Exception) + { + transaction.Rollback(); + throw; + } + } + } + + public void DeleteAllAttendances() + { + using var context = new RemoteDatabaseContext(); + var allAttendances = context.Attendances.ToList(); + context.Attendances.RemoveRange(allAttendances); + context.SaveChanges(); + } + + public void DeleteAttendancesByGroup(int groupId) + { + using var context = new RemoteDatabaseContext(); + var attendancesByGroup = context.Attendances.Where(a => a.GroupId == groupId).ToList(); + context.Attendances.RemoveRange(attendancesByGroup); + context.SaveChanges(); + } + + public void AddAttendance(Attendance attendance) + { + _dbContext.Attendances.Add(attendance); + _dbContext.SaveChanges(); + } + + public Visit GetVisitById(int visitId) + { + return _dbContext.Visits.FirstOrDefault(v => v.VisitId == visitId); + } + + public int GetGroupIdBySubjectName(string subjectName) + { + var subject = _dbContext.Subjects.Include(s => s.Group) + .FirstOrDefault(s => s.SubjectName == subjectName); + + if (subject == null || subject.Group == null) + { + throw new InvalidOperationException($"Предмет с названием '{subjectName}' или его группа не найдены."); + } + + return subject.Group.GroupId; + } + + public IEnumerable GetAttendances(int groupId, string subject = null, DateTime? date = null, int? studentId = null) + { + var query = _dbContext.Attendances.AsQueryable(); + + query = query.Where(a => a.GroupId == groupId); + + if (!string.IsNullOrEmpty(subject)) + { + query = query.Where(a => a.GroupSubject.Subject.SubjectName == subject); + } + + if (date.HasValue) + { + var dateOnly = DateOnly.FromDateTime(date.Value); + query = query.Where(a => a.Date == dateOnly); + } + + if (studentId.HasValue) + { + query = query.Where(a => a.StudentId == studentId.Value); + } + + return query.ToList(); + } + + public Attendance GetAttendanceByDateStudentAndLesson(DateTime date, int studentId, int lessonNumber) + { + var dateOnly = DateOnly.FromDateTime(date); + return _dbContext.Attendances + .FirstOrDefault(a => a.Date == dateOnly && a.StudentId == studentId && a.LessonNumber == lessonNumber); + } + + public void UpdateAttendance(Attendance attendance) + { + _dbContext.Attendances.Update(attendance); + _dbContext.SaveChanges(); + } + + + public void RemoveStudentsFromGroup(int groupId) + { + var students = _dbContext.Students.Where(s => s.GroupId == groupId).ToList(); + _dbContext.Students.RemoveRange(students); + _dbContext.SaveChanges(); + } + + + public void RemoveStudentsFromGroupByIds(int groupId, List studentIds) + { + var studentsToRemove = _dbContext.Students + .Where(s => s.GroupId == groupId && studentIds.Contains(s.StudentId)) + .ToList(); + + if (studentsToRemove.Any()) + { + _dbContext.Students.RemoveRange(studentsToRemove); + _dbContext.SaveChanges(); + } } } }