This commit is contained in:
1eG0ist 2024-12-12 10:21:45 +03:00
parent 61d110fd62
commit 44d091674e
21 changed files with 2460 additions and 247 deletions

23
data/DAO/Attendance.cs Normal file
View File

@ -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; }
}
}

View File

@ -4,13 +4,15 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace data.DAO namespace Data.DAO
{ {
public class GroupDAO public class Group
{ {
public int Id { get; set; } public int GroupId { get; set; }
public String Name { get; set; } public string GroupName { get; set; }
public virtual IEnumerable<UserDAO> Users { get; set; }
public virtual IEnumerable<Student> Students { get; set; }
public virtual ICollection<Subject> Subjects { get; set; }
public virtual ICollection<GroupSubject> GroupSubjects { get; set; }
} }
} }

22
data/DAO/GroupSubject.cs Normal file
View File

@ -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<Attendance> Attendances { get; set; }
}
}

View File

@ -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
{
}
}

17
data/DAO/Semester.cs Normal file
View File

@ -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<GroupSubject> GroupSubjects { get; set; }
}
}

19
data/DAO/Student.cs Normal file
View File

@ -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<Attendance> Attendances { get; set; }
}
}

18
data/DAO/Subject.cs Normal file
View File

@ -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<GroupSubject> GroupSubjects { get; set; }
}
}

View File

@ -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; }
}
}

16
data/DAO/Visit.cs Normal file
View File

@ -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<Attendance> Attendances { get; set; }
}
}

View File

@ -1,83 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("groups");
});
modelBuilder.Entity("data.DAO.UserDAO", b =>
{
b.Property<Guid>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("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
}
}
}

View File

@ -1,63 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "groups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
Guid = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "users");
migrationBuilder.DropTable(
name: "groups");
}
}
}

View File

@ -0,0 +1,320 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("AttendanceId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("AttendanceId"));
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("GroupSubjectId")
.HasColumnType("integer");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("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<int>("GroupId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupId"));
b.Property<string>("GroupName")
.IsRequired()
.HasColumnType("text");
b.HasKey("GroupId");
b.ToTable("Groups");
});
modelBuilder.Entity("Data.DAO.GroupSubject", b =>
{
b.Property<int>("GroupSubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupSubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("SemesterId")
.HasColumnType("integer");
b.Property<int>("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<int>("SemesterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SemesterId"));
b.Property<DateTime>("EndTime")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("StartTime")
.HasColumnType("timestamp with time zone");
b.HasKey("SemesterId");
b.ToTable("Semesters");
});
modelBuilder.Entity("Data.DAO.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("StudentId"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("text");
b.HasKey("StudentId");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("Data.DAO.Subject", b =>
{
b.Property<int>("SubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("SubjectName")
.IsRequired()
.HasColumnType("text");
b.HasKey("SubjectId");
b.HasIndex("GroupId");
b.ToTable("Subjects");
});
modelBuilder.Entity("Data.DAO.Visit", b =>
{
b.Property<int>("VisitId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("VisitId"));
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,243 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate123 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
GroupId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GroupName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.GroupId);
});
migrationBuilder.CreateTable(
name: "Semesters",
columns: table => new
{
SemesterId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StartTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndTime = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
VisitName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.VisitId);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
StudentId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Patronymic = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SubjectName = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SemesterId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
SubjectId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateOnly>(type: "date", nullable: false),
GroupSubjectId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
VisitId = table.Column<int>(type: "integer", nullable: false),
LessonNumber = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,320 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("AttendanceId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("AttendanceId"));
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("GroupSubjectId")
.HasColumnType("integer");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("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<int>("GroupId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupId"));
b.Property<string>("GroupName")
.IsRequired()
.HasColumnType("text");
b.HasKey("GroupId");
b.ToTable("Groups");
});
modelBuilder.Entity("Data.DAO.GroupSubject", b =>
{
b.Property<int>("GroupSubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupSubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("SemesterId")
.HasColumnType("integer");
b.Property<int>("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<int>("SemesterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SemesterId"));
b.Property<DateTime>("EndTime")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("StartTime")
.HasColumnType("timestamp with time zone");
b.HasKey("SemesterId");
b.ToTable("Semesters");
});
modelBuilder.Entity("Data.DAO.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("StudentId"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("text");
b.HasKey("StudentId");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("Data.DAO.Subject", b =>
{
b.Property<int>("SubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("SubjectName")
.IsRequired()
.HasColumnType("text");
b.HasKey("SubjectId");
b.HasIndex("GroupId");
b.ToTable("Subjects");
});
modelBuilder.Entity("Data.DAO.Visit", b =>
{
b.Property<int>("VisitId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("VisitId"));
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,243 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
GroupId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GroupName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.GroupId);
});
migrationBuilder.CreateTable(
name: "Semesters",
columns: table => new
{
SemesterId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StartTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndTime = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
VisitName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.VisitId);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
StudentId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Patronymic = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SubjectName = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SemesterId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
SubjectId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateOnly>(type: "date", nullable: false),
GroupSubjectId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
VisitId = table.Column<int>(type: "integer", nullable: false),
LessonNumber = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,320 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("AttendanceId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("AttendanceId"));
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("GroupSubjectId")
.HasColumnType("integer");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("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<int>("GroupId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupId"));
b.Property<string>("GroupName")
.IsRequired()
.HasColumnType("text");
b.HasKey("GroupId");
b.ToTable("Groups");
});
modelBuilder.Entity("Data.DAO.GroupSubject", b =>
{
b.Property<int>("GroupSubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupSubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("SemesterId")
.HasColumnType("integer");
b.Property<int>("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<int>("SemesterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SemesterId"));
b.Property<DateTime>("EndTime")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("StartTime")
.HasColumnType("timestamp with time zone");
b.HasKey("SemesterId");
b.ToTable("Semesters");
});
modelBuilder.Entity("Data.DAO.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("StudentId"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("text");
b.HasKey("StudentId");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("Data.DAO.Subject", b =>
{
b.Property<int>("SubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("SubjectName")
.IsRequired()
.HasColumnType("text");
b.HasKey("SubjectId");
b.HasIndex("GroupId");
b.ToTable("Subjects");
});
modelBuilder.Entity("Data.DAO.Visit", b =>
{
b.Property<int>("VisitId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("VisitId"));
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,243 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
GroupId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
GroupName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.GroupId);
});
migrationBuilder.CreateTable(
name: "Semesters",
columns: table => new
{
SemesterId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StartTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndTime = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
VisitName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.VisitId);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
StudentId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Patronymic = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SubjectName = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SemesterId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
SubjectId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateOnly>(type: "date", nullable: false),
GroupSubjectId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false),
VisitId = table.Column<int>(type: "integer", nullable: false),
LessonNumber = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -22,47 +22,244 @@ namespace data.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("data.DAO.GroupDAO", b => modelBuilder.Entity("Data.DAO.Attendance", b =>
{ {
b.Property<int>("Id") b.Property<int>("AttendanceId")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("integer"); .HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("AttendanceId"));
b.Property<string>("Name") b.Property<DateOnly>("Date")
.IsRequired() .HasColumnType("date");
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("groups");
});
modelBuilder.Entity("data.DAO.UserDAO", b =>
{
b.Property<Guid>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("GroupId") b.Property<int>("GroupId")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<string>("Name") b.Property<int>("GroupSubjectId")
.IsRequired() .HasColumnType("integer");
.HasColumnType("text");
b.HasKey("Guid"); b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("VisitId")
.HasColumnType("integer");
b.HasKey("AttendanceId");
b.HasIndex("GroupId"); 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") b.Property<int>("GroupId")
.WithMany("Users") .ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupId"));
b.Property<string>("GroupName")
.IsRequired()
.HasColumnType("text");
b.HasKey("GroupId");
b.ToTable("Groups");
});
modelBuilder.Entity("Data.DAO.GroupSubject", b =>
{
b.Property<int>("GroupSubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("GroupSubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<int>("SemesterId")
.HasColumnType("integer");
b.Property<int>("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<int>("SemesterId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SemesterId"));
b.Property<DateTime>("EndTime")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("StartTime")
.HasColumnType("timestamp with time zone");
b.HasKey("SemesterId");
b.ToTable("Semesters");
});
modelBuilder.Entity("Data.DAO.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("StudentId"));
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("text");
b.HasKey("StudentId");
b.HasIndex("GroupId");
b.ToTable("Students");
});
modelBuilder.Entity("Data.DAO.Subject", b =>
{
b.Property<int>("SubjectId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SubjectId"));
b.Property<int>("GroupId")
.HasColumnType("integer");
b.Property<string>("SubjectName")
.IsRequired()
.HasColumnType("text");
b.HasKey("SubjectId");
b.HasIndex("GroupId");
b.ToTable("Subjects");
});
modelBuilder.Entity("Data.DAO.Visit", b =>
{
b.Property<int>("VisitId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("VisitId"));
b.Property<string>("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") .HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -70,9 +267,49 @@ namespace data.Migrations
b.Navigation("Group"); 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 #pragma warning restore 612, 618
} }

View File

@ -1,4 +1,4 @@
using data.DAO; using Data.DAO;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,18 +15,37 @@ namespace data
optionsBuilder.UseNpgsql("Host=localhost;port=5432;Password=admin;Username=postgres;Database=semesterWork"); optionsBuilder.UseNpgsql("Host=localhost;port=5432;Password=admin;Username=postgres;Database=semesterWork");
} }
public DbSet<GroupDAO> 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<UserDAO> users { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<Attendance> Attendances { get; set; }
public DbSet<GroupSubject> GroupSubjects { get; set; }
public DbSet<Semester> Semesters { get; set; }
public DbSet<Subject> Subjects { get; set; }
public DbSet<Visit> Visits { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<UserDAO>().HasKey(it => it.Guid); modelBuilder.Entity<Student>().HasKey(it => it.StudentId);
modelBuilder.Entity<GroupDAO>().HasKey(it => it.Id); modelBuilder.Entity<Group>().HasKey(it => it.GroupId);
modelBuilder.Entity<GroupSubject>().HasKey(it => it.GroupSubjectId);
modelBuilder.Entity<UserDAO>().Property(it => it.Guid).ValueGeneratedOnAdd(); modelBuilder.Entity<Semester>().HasKey(it => it.SemesterId);
modelBuilder.Entity<GroupDAO>().Property(it => it.Id).ValueGeneratedOnAdd(); modelBuilder.Entity<Visit>().HasKey(it => it.VisitId);
modelBuilder.Entity<Subject>().HasKey(it => it.SubjectId);
modelBuilder.Entity<Attendance>().HasKey(it => it.AttendanceId);
modelBuilder.Entity<Student>().Property(it => it.StudentId).ValueGeneratedOnAdd();
modelBuilder.Entity<Group>().Property(it => it.GroupId).ValueGeneratedOnAdd();
modelBuilder.Entity<GroupSubject>().Property(it => it.GroupSubjectId).ValueGeneratedOnAdd();
modelBuilder.Entity<Semester>().Property(it => it.SemesterId).ValueGeneratedOnAdd();
modelBuilder.Entity<Visit>().Property(it => it.VisitId).ValueGeneratedOnAdd();
modelBuilder.Entity<Subject>().Property(it => it.SubjectId).ValueGeneratedOnAdd();
modelBuilder.Entity<Attendance>().Property(it => it.AttendanceId).ValueGeneratedOnAdd();
} }
} }
} }

View File

@ -1,4 +1,4 @@
using data.DAO; using Data.DAO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,9 +9,55 @@ namespace data.Repository
{ {
public interface IGroupRepository public interface IGroupRepository
{ {
public IEnumerable<GroupDAO> getAllGroup(); public IEnumerable<Group> GetAllGroup();
public Task<IEnumerable<GroupDAO>> getAllGroupAsync();
public bool addGroup(GroupDAO group); public bool AddGroup(Group group);
public bool addGroupWithStudents(GroupDAO group, IEnumerable<UserDAO> userDAOs);
public bool addGroupWithStudent(Group groups, IEnumerable<Student> students);
public bool DeleteGroup(int groupId);
public Group GetGroupWithSubjects(int groupId);
public void AddStudentsToGroup(List<Student> students);
public Group GetGroupById(int groupId);
public Subject GetSubjectById(int subjectId);
public Subject GetSubjectByName(string subjectName);
public void AddSubject(Subject subject);
List<Subject> GetGroupSubjects(int groupId);
List<Subject> 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<Attendance> 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<int> studentIds);
} }
} }

View File

@ -1,4 +1,4 @@
using data.DAO; using Data.DAO;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -9,60 +9,339 @@ using System.Threading.Tasks;
namespace data.Repository namespace data.Repository
{ {
public class SQLGroupRepository : IGroupRepository public class SQLGroupRepository : IGroupRepository
{ {
public readonly RemoteDatabaseContext dbContext; private readonly RemoteDatabaseContext _dbContext;
public SQLGroupRepository(RemoteDatabaseContext remoteDatabaseContext) 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<Student> students)
{ {
using var transaction = _dbContext.Database.BeginTransaction();
try try
{ {
dbContext.groups.Add(group); _dbContext.Groups.Add(groups);
return dbContext.SaveChanges() > 1; _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; return false;
} }
} }
public IEnumerable<GroupDAO> getAllGroup() public void AddStudentsToGroup(List<Student> 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(); student.StudentId = ++maxStudentId;
}
catch (Exception ex) {
return new List<GroupDAO>();
} }
_dbContext.Students.AddRange(students);
_dbContext.SaveChanges();
} }
public bool addGroupWithStudents(GroupDAO groupDAO, IEnumerable<UserDAO> userDAOs)
public bool DeleteGroup(int groupId)
{ {
using var transaction = dbContext.Database.BeginTransaction(); using var transaction = _dbContext.Database.BeginTransaction();
try try
{ {
dbContext.groups.Add(groupDAO); var group = _dbContext.Groups
dbContext.SaveChanges(); .Include(g => g.Students)
foreach (var item in userDAOs) .FirstOrDefault(g => g.GroupId == groupId);
if (group != null)
{ {
item.Group = groupDAO; _dbContext.Students.RemoveRange(group.Students);
dbContext.users.Add(item); _dbContext.Groups.Remove(group);
_dbContext.SaveChanges();
transaction.Commit();
return true;
} }
dbContext.SaveChanges(); return false;
transaction.Commit(); }
return true; catch
} catch
{ {
transaction.Rollback(); transaction.Rollback();
throw;
} }
return false;
} }
public async Task<IEnumerable<GroupDAO>> getAllGroupAsync() public IEnumerable<Group> 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<GroupSubject> 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<Subject> 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<Subject> 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<Attendance> 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<int> studentIds)
{
var studentsToRemove = _dbContext.Students
.Where(s => s.GroupId == groupId && studentIds.Contains(s.StudentId))
.ToList();
if (studentsToRemove.Any())
{
_dbContext.Students.RemoveRange(studentsToRemove);
_dbContext.SaveChanges();
}
} }
} }
} }