что-то очень странное происходит в этом проекте

This commit is contained in:
GokaPek 2024-04-29 22:15:15 +04:00
parent 63997bb081
commit 0b05b028f0
20 changed files with 1585 additions and 5 deletions

View File

@ -7,7 +7,7 @@ using UniversityContracts.ViewModels;
namespace UniversityBusinessLogic.BusinessLogics namespace UniversityBusinessLogic.BusinessLogics
{ {
partial class DisciplineLogic: IDisciplineLogic public class DisciplineLogic: IDisciplineLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDisciplineStorage _disciplineStorage; private readonly IDisciplineStorage _disciplineStorage;

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
@ -6,4 +6,15 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -7,6 +7,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" /> <ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -10,6 +10,7 @@ namespace UniversityContracts.SearchModels
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int TeacherId { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public DateTime? Date { get; set; } public DateTime? Date { get; set; }
} }

View File

@ -0,0 +1,461 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using UniversityDatabaseImplement;
#nullable disable
namespace UniversityDatabaseImplement.Migrations
{
[DbContext(typeof(UniversityDatabase))]
[Migration("20240429172128_InitDb")]
partial class InitDb
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FormOfEvaluation")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Score")
.HasColumnType("int");
b.Property<int>("StudentId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StudentId");
b.HasIndex("UserId");
b.ToTable("Attestations");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TeacherId");
b.HasIndex("UserId");
b.ToTable("Disciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FormOfStudy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Profile")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("PlanOfStudys");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlanOfStudyId")
.HasColumnType("int");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlanOfStudyId");
b.HasIndex("TeacherId");
b.ToTable("PlanOfStudyTeachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TeacherId");
b.HasIndex("UserId");
b.ToTable("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PlanOfStudyId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlanOfStudyId");
b.HasIndex("UserId");
b.ToTable("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DisciplineId")
.HasColumnType("int");
b.Property<int>("StudentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("StudentId");
b.ToTable("StudentDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AcademicDegree")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Position")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Teachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Role")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("Attestations")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Attestations")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("Disciplines")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Disciplines")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Teacher");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("PlanOfStudys")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy")
.WithMany("Teachers")
.HasForeignKey("PlanOfStudyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("PlanOfStudyTeachers")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlanOfStudy");
b.Navigation("Teacher");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("Statements")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Statements")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Teacher");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy")
.WithMany("Students")
.HasForeignKey("PlanOfStudyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Students")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlanOfStudy");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline")
.WithMany("Students")
.HasForeignKey("DisciplineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentDiscipline")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Discipline");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Teachers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Navigation("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.Navigation("Students");
b.Navigation("Teachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Navigation("Attestations");
b.Navigation("StudentDiscipline");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.Navigation("Disciplines");
b.Navigation("PlanOfStudyTeachers");
b.Navigation("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Navigation("Attestations");
b.Navigation("Disciplines");
b.Navigation("PlanOfStudys");
b.Navigation("Statements");
b.Navigation("Students");
b.Navigation("Teachers");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,339 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace UniversityDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitDb : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Role = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PlanOfStudys",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
Profile = table.Column<string>(type: "nvarchar(max)", nullable: false),
FormOfStudy = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanOfStudys", x => x.Id);
table.ForeignKey(
name: "FK_PlanOfStudys_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Teachers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
AcademicDegree = table.Column<string>(type: "nvarchar(max)", nullable: false),
Position = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teachers", x => x.Id);
table.ForeignKey(
name: "FK_Teachers_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
PlanOfStudyId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
table.ForeignKey(
name: "FK_Students_PlanOfStudys_PlanOfStudyId",
column: x => x.PlanOfStudyId,
principalTable: "PlanOfStudys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Students_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "Disciplines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
TeacherId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Disciplines", x => x.Id);
table.ForeignKey(
name: "FK_Disciplines_Teachers_TeacherId",
column: x => x.TeacherId,
principalTable: "Teachers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Disciplines_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "PlanOfStudyTeachers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlanOfStudyId = table.Column<int>(type: "int", nullable: false),
TeacherId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlanOfStudyTeachers", x => x.Id);
table.ForeignKey(
name: "FK_PlanOfStudyTeachers_PlanOfStudys_PlanOfStudyId",
column: x => x.PlanOfStudyId,
principalTable: "PlanOfStudys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlanOfStudyTeachers_Teachers_TeacherId",
column: x => x.TeacherId,
principalTable: "Teachers",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "Statements",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
TeacherId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Statements", x => x.Id);
table.ForeignKey(
name: "FK_Statements_Teachers_TeacherId",
column: x => x.TeacherId,
principalTable: "Teachers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Statements_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "Attestations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
StudentId = table.Column<int>(type: "int", nullable: false),
FormOfEvaluation = table.Column<string>(type: "nvarchar(max)", nullable: false),
Score = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Attestations", x => x.Id);
table.ForeignKey(
name: "FK_Attestations_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Attestations_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateTable(
name: "StudentDisciplines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StudentId = table.Column<int>(type: "int", nullable: false),
DisciplineId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StudentDisciplines", x => x.Id);
table.ForeignKey(
name: "FK_StudentDisciplines_Disciplines_DisciplineId",
column: x => x.DisciplineId,
principalTable: "Disciplines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StudentDisciplines_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});
migrationBuilder.CreateIndex(
name: "IX_Attestations_StudentId",
table: "Attestations",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_Attestations_UserId",
table: "Attestations",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Disciplines_TeacherId",
table: "Disciplines",
column: "TeacherId");
migrationBuilder.CreateIndex(
name: "IX_Disciplines_UserId",
table: "Disciplines",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_PlanOfStudys_UserId",
table: "PlanOfStudys",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_PlanOfStudyTeachers_PlanOfStudyId",
table: "PlanOfStudyTeachers",
column: "PlanOfStudyId");
migrationBuilder.CreateIndex(
name: "IX_PlanOfStudyTeachers_TeacherId",
table: "PlanOfStudyTeachers",
column: "TeacherId");
migrationBuilder.CreateIndex(
name: "IX_Statements_TeacherId",
table: "Statements",
column: "TeacherId");
migrationBuilder.CreateIndex(
name: "IX_Statements_UserId",
table: "Statements",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_StudentDisciplines_DisciplineId",
table: "StudentDisciplines",
column: "DisciplineId");
migrationBuilder.CreateIndex(
name: "IX_StudentDisciplines_StudentId",
table: "StudentDisciplines",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_Students_PlanOfStudyId",
table: "Students",
column: "PlanOfStudyId");
migrationBuilder.CreateIndex(
name: "IX_Students_UserId",
table: "Students",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Teachers_UserId",
table: "Teachers",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Attestations");
migrationBuilder.DropTable(
name: "PlanOfStudyTeachers");
migrationBuilder.DropTable(
name: "Statements");
migrationBuilder.DropTable(
name: "StudentDisciplines");
migrationBuilder.DropTable(
name: "Disciplines");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "Teachers");
migrationBuilder.DropTable(
name: "PlanOfStudys");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,458 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using UniversityDatabaseImplement;
#nullable disable
namespace UniversityDatabaseImplement.Migrations
{
[DbContext(typeof(UniversityDatabase))]
partial class UniversityDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FormOfEvaluation")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Score")
.HasColumnType("int");
b.Property<int>("StudentId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StudentId");
b.HasIndex("UserId");
b.ToTable("Attestations");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TeacherId");
b.HasIndex("UserId");
b.ToTable("Disciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FormOfStudy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Profile")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("PlanOfStudys");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlanOfStudyId")
.HasColumnType("int");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlanOfStudyId");
b.HasIndex("TeacherId");
b.ToTable("PlanOfStudyTeachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TeacherId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TeacherId");
b.HasIndex("UserId");
b.ToTable("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PlanOfStudyId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlanOfStudyId");
b.HasIndex("UserId");
b.ToTable("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DisciplineId")
.HasColumnType("int");
b.Property<int>("StudentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("StudentId");
b.ToTable("StudentDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AcademicDegree")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Position")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Teachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Role")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("Attestations")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Attestations")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("Disciplines")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Disciplines")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Teacher");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("PlanOfStudys")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy")
.WithMany("Teachers")
.HasForeignKey("PlanOfStudyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("PlanOfStudyTeachers")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlanOfStudy");
b.Navigation("Teacher");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher")
.WithMany("Statements")
.HasForeignKey("TeacherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Statements")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Teacher");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy")
.WithMany("Students")
.HasForeignKey("PlanOfStudyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Students")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlanOfStudy");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline")
.WithMany("Students")
.HasForeignKey("DisciplineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentDiscipline")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Discipline");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("Teachers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Navigation("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b =>
{
b.Navigation("Students");
b.Navigation("Teachers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Navigation("Attestations");
b.Navigation("StudentDiscipline");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b =>
{
b.Navigation("Disciplines");
b.Navigation("PlanOfStudyTeachers");
b.Navigation("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Navigation("Attestations");
b.Navigation("Disciplines");
b.Navigation("PlanOfStudys");
b.Navigation("Statements");
b.Navigation("Students");
b.Navigation("Teachers");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -15,7 +15,9 @@ namespace UniversityDatabaseImplement.Models
public class Attestation : IAttestationModel public class Attestation : IAttestationModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int UserId { get; private set; } public int UserId { get; private set; }
[Required]
public int StudentId { get; private set; } public int StudentId { get; private set; }
[Required] [Required]
public string FormOfEvaluation { get; private set; } = string.Empty; public string FormOfEvaluation { get; private set; } = string.Empty;

View File

@ -14,12 +14,16 @@ namespace UniversityDatabaseImplement.Models
public class Discipline : IDisciplineModel public class Discipline : IDisciplineModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int UserId { get; private set; }
[Required] [Required]
public int TeacherId { get; private set; } public int TeacherId { get; private set; }
[Required] [Required]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[Required] [Required]
public string Description { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty;
public virtual User User { get; set; } = new();
public virtual Teacher Teacher { get; set; } = new(); public virtual Teacher Teacher { get; set; } = new();
private Dictionary<int, IStudentModel>? _studentDisciplines = null; private Dictionary<int, IStudentModel>? _studentDisciplines = null;
[NotMapped] [NotMapped]
@ -42,7 +46,10 @@ namespace UniversityDatabaseImplement.Models
return new Discipline() return new Discipline()
{ {
Id = model.Id, Id = model.Id,
UserId = model.UserId,
User = context.Users.First(x => x.Id == model.UserId),
TeacherId = model.TeacherId, TeacherId = model.TeacherId,
Teacher = context.Teachers.First(x => x.Id == model.TeacherId),
Name = model.Name, Name = model.Name,
Description = model.Description, Description = model.Description,
Students = model.StudentDisciplines.Select(x => new Students = model.StudentDisciplines.Select(x => new
@ -59,6 +66,7 @@ namespace UniversityDatabaseImplement.Models
return; return;
} }
Id = model.Id; Id = model.Id;
UserId = model.UserId;
TeacherId = model.TeacherId; TeacherId = model.TeacherId;
Name = model.Name; Name = model.Name;
Description = model.Description; Description = model.Description;
@ -94,6 +102,7 @@ namespace UniversityDatabaseImplement.Models
public DisciplineViewModel GetViewModel => new() public DisciplineViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
UserId = UserId,
TeacherId = TeacherId, TeacherId = TeacherId,
Name = Name, Name = Name,
Description = Description, Description = Description,

View File

@ -14,6 +14,7 @@ namespace UniversityDatabaseImplement.Models
public class PlanOfStudy : IPlanOfStudyModel public class PlanOfStudy : IPlanOfStudyModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int UserId { get; private set; } public int UserId { get; private set; }
[Required] [Required]
public string Profile { get; private set; } = string.Empty; public string Profile { get; private set; } = string.Empty;

View File

@ -14,11 +14,14 @@ namespace UniversityDatabaseImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
public int UserId { get; private set; }
[Required]
public int TeacherId { get; private set; } public int TeacherId { get; private set; }
[Required] [Required]
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
[Required] [Required]
public DateTime Date { get; private set; } public DateTime Date { get; private set; }
public virtual User User { get; set; } = new ();
public virtual Teacher Teacher { get; set; } = new (); public virtual Teacher Teacher { get; set; } = new ();
public static Statement? Create(StatementBindingModel model) public static Statement? Create(StatementBindingModel model)
{ {
@ -29,6 +32,7 @@ namespace UniversityDatabaseImplement.Models
return new Statement() return new Statement()
{ {
Id = model.Id, Id = model.Id,
UserId = model.UserId,
TeacherId = model.TeacherId, TeacherId = model.TeacherId,
Name = model.Name, Name = model.Name,
Date = model.Date, Date = model.Date,
@ -39,6 +43,7 @@ namespace UniversityDatabaseImplement.Models
return new Statement() return new Statement()
{ {
Id = model.Id, Id = model.Id,
UserId = model.UserId,
TeacherId = model.TeacherId, TeacherId = model.TeacherId,
Name = model.Name, Name = model.Name,
Date = model.Date, Date = model.Date,
@ -51,6 +56,7 @@ namespace UniversityDatabaseImplement.Models
return; return;
} }
Id = model.Id; Id = model.Id;
UserId = model.UserId;
TeacherId = model.Id; TeacherId = model.Id;
Name = model.Name; Name = model.Name;
Date = model.Date; Date = model.Date;
@ -58,6 +64,7 @@ namespace UniversityDatabaseImplement.Models
public StatementViewModel GetViewModel => new() public StatementViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
UserId = UserId,
TeacherId = TeacherId, TeacherId = TeacherId,
Name = Name, Name = Name,
Date = Date, Date = Date,

View File

@ -15,7 +15,9 @@ namespace UniversityDatabaseImplement.Models
public class Student : IStudentModel public class Student : IStudentModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int UserId { get; private set; } public int UserId { get; private set; }
[Required]
public int PlanOfStudyId { get; private set; } public int PlanOfStudyId { get; private set; }
[Required] [Required]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;

View File

@ -25,6 +25,18 @@ namespace UniversityDatabaseImplement.Models
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Required] [Required]
public UserRole Role { get; set; } public UserRole Role { get; set; }
[ForeignKey("UserId")]
public virtual List<Statement> Statements { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Discipline> Disciplines { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Teacher> Teachers { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Attestation> Attestations { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<PlanOfStudy> PlanOfStudys { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Student> Students{ get; set; } = new();
public static User Create(UserBindingModel model) public static User Create(UserBindingModel model)
{ {
return new User return new User

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\UniversityDatabase;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -0,0 +1,74 @@
using Microsoft.AspNetCore.Mvc;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
namespace UniversityRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DisciplinesController : Controller
{
private readonly ILogger _logger;
private readonly IDisciplineLogic _logic;
public DisciplinesController(IDisciplineLogic logic, ILogger<DisciplinesController> logger)
{
_logic = logic;
_logger = logger;
}
[HttpGet]
public List<DisciplineViewModel>? GetDisciplines(int userId)
{
try
{
return _logic.ReadList(new DisciplineSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка дисциплин");
throw;
}
}
[HttpPost]
public void CreateDiscipline(DisciplineBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания дисциплины");
throw;
}
}
[HttpPut]
public void UpdateDiscipline(DisciplineBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления дисциплины");
throw;
}
}
[HttpDelete]
public void DeleteDiscipline(DisciplineBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления дисциплины");
throw;
}
}
}
}

View File

@ -0,0 +1,75 @@
using Microsoft.AspNetCore.Mvc;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using UniversityDataModels.Enums;
namespace UniversityRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class StatementController : Controller
{
private readonly ILogger _logger;
private readonly IStatementLogic _logic;
public StatementController(IStatementLogic logic, ILogger<StatementController> logger)
{
_logic = logic;
_logger = logger;
}
[HttpGet]
public List<StatementViewModel>? GetStatements(int teacherId)
{
try
{
return _logic.ReadList(new StatementSearchModel { TeacherId = teacherId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения ведомости id={Id}", teacherId);
throw;
}
}
[HttpPost]
public void CreateStatement(StatementBindingModel model)
{
try
{
_logic.Create(model);
} catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания ведомости");
throw;
}
}
[HttpPut]
public void UpdateStatement(StatementBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления ведомости");
throw;
}
}
[HttpDelete]
public void DeleteStatement(StatementBindingModel model)
{
try
{
_logic.Delete(model);
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка удаления ведомости");
throw;
}
}
}
}

View File

@ -0,0 +1,70 @@
using Microsoft.AspNetCore.Mvc;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
namespace UniversityRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class TeacherController : Controller
{
private readonly ILogger _logger;
private readonly ITeacherLogic _logic;
public TeacherController(ITeacherLogic logic, ILogger<TeacherController> logger)
{
_logic = logic;
_logger = logger;
}
[HttpGet]
public List<TeacherViewModel>? GetTeachers(int userId)
{
try
{
return _logic.ReadList(new TeacherSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка преподавателей пользователя id={Id}", userId);
throw;
}
}
public void CreateTeacher(TeacherBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания преподавателя");
throw;
}
}
public void UpdateTeacher(TeacherBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления преподавателя");
throw;
}
}
public void DeleteTeacher(TeacherBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления преподавателя");
throw;
}
}
}
}

View File

@ -1,11 +1,43 @@
using Microsoft.OpenApi.Models;
using UniversityBusinessLogic.BusinessLogics;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.StorageContracts;
using UniversityDatabaseImplement.Implements;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
// Add services to the container. // Add services to the container.
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IDisciplineStorage, DisciplineStorage>();
builder.Services.AddTransient<ITeacherStorage, TeacherStorage>();
builder.Services.AddTransient<IPlanOfStudyStorage, PlanOfStudyStorage>();
builder.Services.AddTransient<IAttestationStorage, AttestationStorage>();
builder.Services.AddTransient<IStatementStorage, StatementStorage>();
builder.Services.AddTransient<IStudentStorage, StudentStorage>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>();
builder.Services.AddTransient<ITeacherLogic, TeacherLogic>();
builder.Services.AddTransient<IPlanOfStudyLogic, PlanOfStudyLogic>();
builder.Services.AddTransient<IAttestationLogic, AttestationLogic>();
builder.Services.AddTransient<IStatementLogic, StatementLogic>();
builder.Services.AddTransient<IStudentLogic, StudentLogic>();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "UniversityRestApi",
Version
= "v1"
});
});
var app = builder.Build(); var app = builder.Build();
@ -13,7 +45,7 @@ var app = builder.Build();
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "UniversityRestApi v1"));
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View File

@ -7,12 +7,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\UniversityBusinessLogic\UniversityBusinessLogic.csproj" /> <ProjectReference Include="..\UniversityBusinessLogic\UniversityBusinessLogic.csproj" />
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" /> <ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="c:/temp/UniversityRestApi.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>