Compare commits

..

44 Commits

Author SHA1 Message Date
MaxKarme
aaf990fe04 Merge branch 'BuisnessLogic' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into main 2023-04-09 01:22:03 +04:00
MaxKarme
367d2a147c Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into main 2023-04-09 01:21:51 +04:00
MaxKarme
890333de46 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into main 2023-04-09 01:21:42 +04:00
MaxKarme
aa08035ab4 make migration 2023-04-09 01:20:49 +04:00
MaxKarme
6c8921128b fix reportLogic 2023-04-09 01:18:06 +04:00
MaxKarme
2b6b0c2c97 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-09 01:15:36 +04:00
MaxKarme
9ae67bcc97 Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-09 01:11:34 +04:00
MaxKarme
d07365e746 add statements in database discipline model 2023-04-09 01:11:16 +04:00
MaxKarme
53fe0986cf Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-09 01:07:44 +04:00
MaxKarme
48db39218d add user database links 2023-04-09 00:45:19 +04:00
MaxKarme
2bf631e109 finilized report logic 2023-04-09 00:38:43 +04:00
MaxKarme
c59b0e725c Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-09 00:36:04 +04:00
MaxKarme
c5a57a6421 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-09 00:26:30 +04:00
MaxKarme
8eb66e60c5 Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-09 00:18:39 +04:00
MaxKarme
cc04070287 refactoring and add date filter 2023-04-09 00:18:16 +04:00
MaxKarme
7c1c32175a Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-09 00:17:21 +04:00
MaxKarme
cba1478c86 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-09 00:10:18 +04:00
MaxKarme
6abd26ea3c make report logic student discipline 2023-04-08 23:34:04 +04:00
MaxKarme
f29365f88c delete files which out of folder BuisnessLogic 2023-04-08 23:28:50 +04:00
MaxKarme
80257228e0 Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-08 23:27:12 +04:00
MaxKarme
d36d38e353 change dictionaries in database implement 2023-04-08 23:26:45 +04:00
MaxKarme
4379b3a531 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-08 23:20:41 +04:00
MaxKarme
a15ead57dd Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-08 23:18:02 +04:00
MaxKarme
b4e77f7c87 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-08 22:32:40 +04:00
MaxKarme
5264595708 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-08 22:28:15 +04:00
MaxKarme
e2c272c024 move files to buisnessLogic 2023-04-08 22:21:05 +04:00
MaxKarme
9c32f553ec add user logic 2023-04-08 17:54:42 +04:00
MaxKarme
fe3f9b12d5 Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-08 17:39:36 +04:00
MaxKarme
92cfe7ad61 add user 2023-04-08 17:38:34 +04:00
MaxKarme
7a7a1f2ed3 fix 2023-04-08 17:38:26 +04:00
MaxKarme
a17a5f38cd Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-08 16:48:36 +04:00
MaxKarme
9238169d0d Merge branch 'DatabaseImplement' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-07 17:44:30 +04:00
MaxKarme
f281f7a009 add dictionaries and refactoring 2023-04-07 17:44:00 +04:00
MaxKarme
f1c38528b2 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-07 16:04:11 +04:00
MaxKarme
0f67b42c70 Merge branch 'BuisnessLogic' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into main 2023-04-05 20:25:28 +04:00
MaxKarme
6ce1acb921 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into main 2023-04-05 20:25:01 +04:00
MaxKarme
c7004b1db7 implement base logic operations 2023-04-05 20:24:16 +04:00
MaxKarme
761ed545c7 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into BuisnessLogic 2023-04-05 20:13:50 +04:00
MaxKarme
1503a5c132 add databaseImplement 2023-04-04 22:36:39 +04:00
MaxKarme
4a787d1931 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-04 22:35:38 +04:00
MaxKarme
fb0fcd5c18 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-04 22:01:18 +04:00
MaxKarme
bbf2dae2f8 Merge branch 'ModelsAndContracts' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-04 18:14:56 +04:00
MaxKarme
d6faa35d6d Merge branch 'main' of http://student.git.athene.tech/maxKarme/PIbd-22_Karamushko_M_K_University_CourseWork into DatabaseImplement 2023-04-02 18:16:40 +04:00
MaxKarme
41dc907c53 add modelas and implements files 2023-04-02 17:39:42 +04:00
35 changed files with 3379 additions and 2 deletions

View File

@ -0,0 +1,75 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement.Implements
{
internal class ActivityStorage : IActivityStorage
{
public List<ActivityViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Activities.Select(x => x.GetViewModel).ToList();
}
public List<ActivityViewModel> GetFilteredList(ActivitySearchModel model)
{
using var context = new UniversityDatabase();
return context.Activities
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id)
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public ActivityViewModel? GetElement(ActivitySearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Activities
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ActivityViewModel? Insert(ActivityBindingModel model)
{
var newActivity = Activity.Create(model);
if (newActivity == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Activities.Add(newActivity);
context.SaveChanges();
return newActivity.GetViewModel;
}
public ActivityViewModel? Update(ActivityBindingModel model)
{
using var context = new UniversityDatabase();
var activity = context.Activities.FirstOrDefault(x => x.Id == model.Id);
if (activity == null)
{
return null;
}
activity.Update(model);
context.SaveChanges();
return activity.GetViewModel;
}
public ActivityViewModel? Delete(ActivityBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Activities.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Activities.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,81 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class DisciplineStorage : IDisciplineStorage
{
public List<DisciplineViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Disciplines
.Include(x => x.Statements)
.Select(x => x.GetViewModel).ToList();
}
public List<DisciplineViewModel> GetFilteredList(DisciplineSearchModel model)
{
using var context = new UniversityDatabase();
return context.Disciplines
.Include(x => x.Statements)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public DisciplineViewModel? GetElement(DisciplineSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Disciplines
.Include(x => x.Statements)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public DisciplineViewModel? Insert(DisciplineBindingModel model)
{
var newDiscipline = Discipline.Create(model);
if (newDiscipline == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Disciplines.Add(newDiscipline);
context.SaveChanges();
return newDiscipline.GetViewModel;
}
public DisciplineViewModel? Update(DisciplineBindingModel model)
{
using var context = new UniversityDatabase();
var discipline = context.Disciplines.FirstOrDefault(x => x.Id == model.Id);
if (discipline == null)
{
return null;
}
discipline.Update(model);
context.SaveChanges();
return discipline.GetViewModel;
}
public DisciplineViewModel? Delete(DisciplineBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Disciplines.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,85 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class ExaminationResultStorage : IExaminationResultStorage
{
public List<ExaminationResultViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.ExaminationResults
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.Student)
.Select(x => x.GetViewModel).ToList();
}
public List<ExaminationResultViewModel> GetFilteredList(ExaminationResultSearchModel model)
{
using var context = new UniversityDatabase();
return context.ExaminationResults
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.Student)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.From.HasValue || x.Date >= model.From) &&
(!model.To.HasValue || x.Date <= model.To)
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public ExaminationResultViewModel? GetElement(ExaminationResultSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ExaminationResults
.Include(x => x.StudentExaminationResults)
.ThenInclude(x => x.Student)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ExaminationResultViewModel? Insert(ExaminationResultBindingModel model)
{
var newExaminationResult = ExaminationResult.Create(model);
if (newExaminationResult == null)
{
return null;
}
using var context = new UniversityDatabase();
context.ExaminationResults.Add(newExaminationResult);
context.SaveChanges();
return newExaminationResult.GetViewModel;
}
public ExaminationResultViewModel? Update(ExaminationResultBindingModel model)
{
using var context = new UniversityDatabase();
var examinationResult = context.ExaminationResults.FirstOrDefault(x => x.Id == model.Id);
if (examinationResult == null)
{
return null;
}
examinationResult.Update(model);
context.SaveChanges();
return examinationResult.GetViewModel;
}
public ExaminationResultViewModel? Delete(ExaminationResultBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.ExaminationResults.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ExaminationResults.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,77 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement.Implements
{
internal class ReportTypeStorage : IReportTypeStorage
{
public List<ReportTypeViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.ReportTypes.Select(x => x.GetViewModel).ToList();
}
public List<ReportTypeViewModel> GetFilteredList(ReportTypeSearchModel model)
{
using var context = new UniversityDatabase();
return context.ReportTypes
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public ReportTypeViewModel? GetElement(ReportTypeSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.ReportTypes
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ReportTypeViewModel? Insert(ReportTypeBindingModel model)
{
var newReportType = ReportType.Create(model);
if (newReportType == null)
{
return null;
}
using var context = new UniversityDatabase();
context.ReportTypes.Add(newReportType);
context.SaveChanges();
return newReportType.GetViewModel;
}
public ReportTypeViewModel? Update(ReportTypeBindingModel model)
{
using var context = new UniversityDatabase();
var reportType = context.ReportTypes.FirstOrDefault(x => x.Id == model.Id);
if (reportType == null)
{
return null;
}
reportType.Update(model);
context.SaveChanges();
return reportType.GetViewModel;
}
public ReportTypeViewModel? Delete(ReportTypeBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.ReportTypes.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ReportTypes.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,80 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class StatementStorage : IStatementStorage
{
public List<StatementViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Statements
.Select(x => x.GetViewModel)
.ToList();
}
public List<StatementViewModel> GetFilteredList(StatementSearchModel model)
{
using var context = new UniversityDatabase();
return context.Statements
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.From.HasValue || x.Date >= model.From) &&
(!model.To.HasValue || x.Date <= model.To)
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public StatementViewModel? GetElement(StatementSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Statements
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public StatementViewModel? Insert(StatementBindingModel model)
{
var newStatement = Statement.Create(model);
if (newStatement == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Statements.Add(newStatement);
context.SaveChanges();
return newStatement.GetViewModel;
}
public StatementViewModel? Update(StatementBindingModel model)
{
using var context = new UniversityDatabase();
var statement = context.Statements.FirstOrDefault(x => x.Id == model.Id);
if (statement == null)
{
return null;
}
statement.Update(model);
context.SaveChanges();
return statement.GetViewModel;
}
public StatementViewModel? Delete(StatementBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Statements.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,86 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement.Implements
{
internal class StudentStorage : IStudentStorage
{
public List<StudentViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Students
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Statement)
.Select(x => x.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{
using var context = new UniversityDatabase();
return context.Students
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Statement)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Students
.Include(x => x.StatementStudents)
.ThenInclude(x => x.Statement)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name== model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public StudentViewModel? Insert(StudentBindingModel model)
{
var newStudent = Student.Create(model);
if (newStudent == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Students.Add(newStudent);
context.SaveChanges();
return newStudent.GetViewModel;
}
public StudentViewModel? Update(StudentBindingModel model)
{
using var context = new UniversityDatabase();
var student = context.Students.FirstOrDefault(x => x.Id == model.Id);
if (student == null)
{
return null;
}
student.Update(model);
context.SaveChanges();
return student.GetViewModel;
}
public StudentViewModel? Delete(StudentBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Students.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,78 @@
using UniversityContracts.BindingModels;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
namespace UniversityDatabaseImplement.Implements
{
internal class UserStorage : IUserStorage
{
public List<UserViewModel> GetFullList()
{
using var context = new UniversityDatabase();
return context.Users.Select(x => x.GetViewModel).ToList();
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
using var context = new UniversityDatabase();
return context.Users
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.Login) || x.Login.Contains(model.Login)) &&
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))
)
)
.Select(x => x.GetViewModel)
.ToList();
}
public UserViewModel? GetElement(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
{
return null;
}
using var context = new UniversityDatabase();
return context.Users
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(!string.IsNullOrEmpty(model.Password) && x.Password == model.Password) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public UserViewModel? Insert(UserBindingModel model)
{
var newUser = User.Create(model);
if (newUser == null)
{
return null;
}
using var context = new UniversityDatabase();
context.Users.Add(newUser);
context.SaveChanges();
return newUser.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new UniversityDatabase();
var user = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (user == null)
{
return null;
}
user.Update(model);
context.SaveChanges();
return user.GetViewModel;
}
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new UniversityDatabase();
var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,497 @@
// <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 UniversityDatabaseImplement;
#nullable disable
namespace UniversityDatabaseImplement.Migrations
{
[DbContext(typeof(UniversityDatabase))]
[Migration("20230408211938_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ExaminationResultId")
.HasColumnType("integer");
b.Property<int>("Number")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExaminationResultId");
b.ToTable("Activities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Department")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Disciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("ExaminationForm")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Mark")
.HasColumnType("integer");
b.Property<int?>("StatementId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StatementId");
b.ToTable("ExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", 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("ReportTypes");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActivityId")
.HasColumnType("integer");
b.Property<int>("ReportTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActivityId");
b.HasIndex("ReportTypeId");
b.ToTable("ReportTypeActivities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DisciplineId")
.HasColumnType("integer");
b.Property<int>("ReportTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("ReportTypeId");
b.ToTable("ReportTypeDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("DisciplineId")
.HasColumnType("integer");
b.Property<int>("HoursCount")
.HasColumnType("integer");
b.Property<int?>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("UserId");
b.ToTable("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("StatementId")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("StudentTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StatementId");
b.HasIndex("StudentId");
b.ToTable("StatementStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecordCardNumber")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ExaminationResultId")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExaminationResultId");
b.HasIndex("StudentId");
b.ToTable("StudentExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Position")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("StudentTypeId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StudentId");
b.HasIndex("UserId");
b.ToTable("UserStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", null)
.WithMany("Activities")
.HasForeignKey("ExaminationResultId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Statement", null)
.WithMany("ExaminationResults")
.HasForeignKey("StatementId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Activity", "Activity")
.WithMany("ReportTypeActivities")
.HasForeignKey("ActivityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType")
.WithMany("ReportTypeActivities")
.HasForeignKey("ReportTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Activity");
b.Navigation("ReportType");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline")
.WithMany("ReportTypeDisciplines")
.HasForeignKey("DisciplineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType")
.WithMany("ReportTypeDisciplines")
.HasForeignKey("ReportTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Discipline");
b.Navigation("ReportType");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", null)
.WithMany("Statements")
.HasForeignKey("DisciplineId");
b.HasOne("UniversityDatabaseImplement.Models.User", null)
.WithMany("Statements")
.HasForeignKey("UserId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Statement", "Statement")
.WithMany("StatementStudents")
.HasForeignKey("StatementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StatementStudents")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Statement");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", "ExaminationResult")
.WithMany("StudentExaminationResults")
.HasForeignKey("ExaminationResultId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentExaminationResults")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ExaminationResult");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentUsers")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("StudentUsers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.Navigation("ReportTypeActivities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Navigation("ReportTypeDisciplines");
b.Navigation("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.Navigation("Activities");
b.Navigation("StudentExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b =>
{
b.Navigation("ReportTypeActivities");
b.Navigation("ReportTypeDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Navigation("ExaminationResults");
b.Navigation("StatementStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Navigation("StatementStudents");
b.Navigation("StudentExaminationResults");
b.Navigation("StudentUsers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Navigation("Statements");
b.Navigation("StudentUsers");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,384 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace UniversityDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Disciplines",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Department = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Disciplines", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ReportTypes",
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_ReportTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
RecordCardNumber = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Surname = table.Column<string>(type: "text", nullable: false),
PhoneNumber = table.Column<string>(type: "text", nullable: false),
Position = table.Column<string>(type: "text", nullable: false),
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ReportTypeDisciplines",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ReportTypeId = table.Column<int>(type: "integer", nullable: false),
DisciplineId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ReportTypeDisciplines", x => x.Id);
table.ForeignKey(
name: "FK_ReportTypeDisciplines_Disciplines_DisciplineId",
column: x => x.DisciplineId,
principalTable: "Disciplines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ReportTypeDisciplines_ReportTypes_ReportTypeId",
column: x => x.ReportTypeId,
principalTable: "ReportTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Statements",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
HoursCount = table.Column<int>(type: "integer", nullable: false),
DisciplineId = table.Column<int>(type: "integer", nullable: true),
UserId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Statements", x => x.Id);
table.ForeignKey(
name: "FK_Statements_Disciplines_DisciplineId",
column: x => x.DisciplineId,
principalTable: "Disciplines",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Statements_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "UserStudents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StudentTypeId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserStudents", x => x.Id);
table.ForeignKey(
name: "FK_UserStudents_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UserStudents_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExaminationResults",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ExaminationForm = table.Column<string>(type: "text", nullable: false),
Mark = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
StatementId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ExaminationResults", x => x.Id);
table.ForeignKey(
name: "FK_ExaminationResults_Statements_StatementId",
column: x => x.StatementId,
principalTable: "Statements",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "StatementStudents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StudentTypeId = table.Column<int>(type: "integer", nullable: false),
StatementId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StatementStudents", x => x.Id);
table.ForeignKey(
name: "FK_StatementStudents_Statements_StatementId",
column: x => x.StatementId,
principalTable: "Statements",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StatementStudents_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Activities",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Number = table.Column<int>(type: "integer", nullable: false),
ExaminationResultId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Activities", x => x.Id);
table.ForeignKey(
name: "FK_Activities_ExaminationResults_ExaminationResultId",
column: x => x.ExaminationResultId,
principalTable: "ExaminationResults",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "StudentExaminationResults",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ExaminationResultId = table.Column<int>(type: "integer", nullable: false),
StudentId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StudentExaminationResults", x => x.Id);
table.ForeignKey(
name: "FK_StudentExaminationResults_ExaminationResults_ExaminationRes~",
column: x => x.ExaminationResultId,
principalTable: "ExaminationResults",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StudentExaminationResults_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ReportTypeActivities",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ReportTypeId = table.Column<int>(type: "integer", nullable: false),
ActivityId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ReportTypeActivities", x => x.Id);
table.ForeignKey(
name: "FK_ReportTypeActivities_Activities_ActivityId",
column: x => x.ActivityId,
principalTable: "Activities",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ReportTypeActivities_ReportTypes_ReportTypeId",
column: x => x.ReportTypeId,
principalTable: "ReportTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Activities_ExaminationResultId",
table: "Activities",
column: "ExaminationResultId");
migrationBuilder.CreateIndex(
name: "IX_ExaminationResults_StatementId",
table: "ExaminationResults",
column: "StatementId");
migrationBuilder.CreateIndex(
name: "IX_ReportTypeActivities_ActivityId",
table: "ReportTypeActivities",
column: "ActivityId");
migrationBuilder.CreateIndex(
name: "IX_ReportTypeActivities_ReportTypeId",
table: "ReportTypeActivities",
column: "ReportTypeId");
migrationBuilder.CreateIndex(
name: "IX_ReportTypeDisciplines_DisciplineId",
table: "ReportTypeDisciplines",
column: "DisciplineId");
migrationBuilder.CreateIndex(
name: "IX_ReportTypeDisciplines_ReportTypeId",
table: "ReportTypeDisciplines",
column: "ReportTypeId");
migrationBuilder.CreateIndex(
name: "IX_Statements_DisciplineId",
table: "Statements",
column: "DisciplineId");
migrationBuilder.CreateIndex(
name: "IX_Statements_UserId",
table: "Statements",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_StatementStudents_StatementId",
table: "StatementStudents",
column: "StatementId");
migrationBuilder.CreateIndex(
name: "IX_StatementStudents_StudentId",
table: "StatementStudents",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_StudentExaminationResults_ExaminationResultId",
table: "StudentExaminationResults",
column: "ExaminationResultId");
migrationBuilder.CreateIndex(
name: "IX_StudentExaminationResults_StudentId",
table: "StudentExaminationResults",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_UserStudents_StudentId",
table: "UserStudents",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_UserStudents_UserId",
table: "UserStudents",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ReportTypeActivities");
migrationBuilder.DropTable(
name: "ReportTypeDisciplines");
migrationBuilder.DropTable(
name: "StatementStudents");
migrationBuilder.DropTable(
name: "StudentExaminationResults");
migrationBuilder.DropTable(
name: "UserStudents");
migrationBuilder.DropTable(
name: "Activities");
migrationBuilder.DropTable(
name: "ReportTypes");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "ExaminationResults");
migrationBuilder.DropTable(
name: "Statements");
migrationBuilder.DropTable(
name: "Disciplines");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,494 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
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", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ExaminationResultId")
.HasColumnType("integer");
b.Property<int>("Number")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExaminationResultId");
b.ToTable("Activities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Department")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Disciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("ExaminationForm")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Mark")
.HasColumnType("integer");
b.Property<int?>("StatementId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StatementId");
b.ToTable("ExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", 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("ReportTypes");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActivityId")
.HasColumnType("integer");
b.Property<int>("ReportTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActivityId");
b.HasIndex("ReportTypeId");
b.ToTable("ReportTypeActivities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DisciplineId")
.HasColumnType("integer");
b.Property<int>("ReportTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("ReportTypeId");
b.ToTable("ReportTypeDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("DisciplineId")
.HasColumnType("integer");
b.Property<int>("HoursCount")
.HasColumnType("integer");
b.Property<int?>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DisciplineId");
b.HasIndex("UserId");
b.ToTable("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("StatementId")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("StudentTypeId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StatementId");
b.HasIndex("StudentId");
b.ToTable("StatementStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecordCardNumber")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Students");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ExaminationResultId")
.HasColumnType("integer");
b.Property<int>("StudentId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExaminationResultId");
b.HasIndex("StudentId");
b.ToTable("StudentExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Position")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("StudentId")
.HasColumnType("integer");
b.Property<int>("StudentTypeId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StudentId");
b.HasIndex("UserId");
b.ToTable("UserStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", null)
.WithMany("Activities")
.HasForeignKey("ExaminationResultId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Statement", null)
.WithMany("ExaminationResults")
.HasForeignKey("StatementId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeActivity", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Activity", "Activity")
.WithMany("ReportTypeActivities")
.HasForeignKey("ActivityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType")
.WithMany("ReportTypeActivities")
.HasForeignKey("ReportTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Activity");
b.Navigation("ReportType");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportTypeDiscipline", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline")
.WithMany("ReportTypeDisciplines")
.HasForeignKey("DisciplineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.ReportType", "ReportType")
.WithMany("ReportTypeDisciplines")
.HasForeignKey("ReportTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Discipline");
b.Navigation("ReportType");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Discipline", null)
.WithMany("Statements")
.HasForeignKey("DisciplineId");
b.HasOne("UniversityDatabaseImplement.Models.User", null)
.WithMany("Statements")
.HasForeignKey("UserId");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StatementStudent", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Statement", "Statement")
.WithMany("StatementStudents")
.HasForeignKey("StatementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StatementStudents")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Statement");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentExaminationResult", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.ExaminationResult", "ExaminationResult")
.WithMany("StudentExaminationResults")
.HasForeignKey("ExaminationResultId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentExaminationResults")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ExaminationResult");
b.Navigation("Student");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.UserStudent", b =>
{
b.HasOne("UniversityDatabaseImplement.Models.Student", "Student")
.WithMany("StudentUsers")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("UniversityDatabaseImplement.Models.User", "User")
.WithMany("StudentUsers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("User");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Activity", b =>
{
b.Navigation("ReportTypeActivities");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b =>
{
b.Navigation("ReportTypeDisciplines");
b.Navigation("Statements");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ExaminationResult", b =>
{
b.Navigation("Activities");
b.Navigation("StudentExaminationResults");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.ReportType", b =>
{
b.Navigation("ReportTypeActivities");
b.Navigation("ReportTypeDisciplines");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b =>
{
b.Navigation("ExaminationResults");
b.Navigation("StatementStudents");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b =>
{
b.Navigation("StatementStudents");
b.Navigation("StudentExaminationResults");
b.Navigation("StudentUsers");
});
modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b =>
{
b.Navigation("Statements");
b.Navigation("StudentUsers");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,45 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class Activity : IActivityModel
{
public int Id { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public int Number { get; set; }
[ForeignKey("ActivityId")]
public virtual List<ReportTypeActivity> ReportTypeActivities { get; set; } = new();
public static Activity Create(ActivityBindingModel model)
{
return new Activity
{
Id = model.Id,
Date = model.Date,
Number = model.Number
};
}
public void Update(ActivityBindingModel model)
{
if (model == null) return;
Id = model.Id;
Date = model.Date;
Number = model.Number;
}
public ActivityViewModel GetViewModel => new()
{
Id = Id,
Date = Date,
Number = Number
};
}
}

View File

@ -0,0 +1,62 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class Discipline : IDisciplineModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Department { get; set; } = string.Empty;
[ForeignKey("DisciplineId")]
public virtual List<Statement> Statements { get; set; } = new();
[ForeignKey("DisciplineId")]
public virtual List<ReportTypeDiscipline> ReportTypeDisciplines { get; set; } = new();
private Dictionary<int, IStatementModel>? _disciplineStatements;
[NotMapped]
public Dictionary<int, IStatementModel> DisciplineStatements
{
get
{
if (_disciplineStatements == null)
{
_disciplineStatements = Statements.ToDictionary(
x => x.Id, x => x as IStatementModel);
}
return _disciplineStatements;
}
}
public static Discipline Create(DisciplineBindingModel model)
{
return new Discipline
{
Id = model.Id,
Name = model.Name,
Department = model.Department
};
}
public void Update(DisciplineBindingModel model)
{
if (model == null) return;
Id = model.Id;
Name = model.Name;
Department = model.Department;
}
public DisciplineViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Department = Department
};
}
}

View File

@ -0,0 +1,67 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using UniversityDataModels.Enums;
namespace UniversityDatabaseImplement.Models
{
public class ExaminationResult : IExaminationResultModel
{
public int Id { get; set; }
public string ExaminationForm { get; set; } = string.Empty;
[Required]
public MarkType Mark { get; set; }
[Required]
public DateTime Date { get; set; }
[ForeignKey("ExaminationResultId")]
public virtual List<Activity> Activities { get; set; } = new();
[ForeignKey("ExaminationResultId")]
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
private Dictionary<int, IStudentModel>? _students;
[NotMapped]
public Dictionary<int, IStudentModel> Students
{
get
{
if (_students == null)
{
_students = StudentExaminationResults.ToDictionary(
x => x.Student.Id, x => x.Student as IStudentModel);
}
return _students;
}
}
public static ExaminationResult Create(ExaminationResultBindingModel model)
{
return new ExaminationResult
{
Id = model.Id,
ExaminationForm = model.ExaminationForm,
Mark = model.Mark,
Date = model.Date
};
}
public void Update(ExaminationResultBindingModel model)
{
if (model == null) return;
Id = model.Id;
ExaminationForm = model.ExaminationForm;
Mark = model.Mark;
Date = model.Date;
}
public ExaminationResultViewModel GetViewModel => new()
{
Id = Id,
ExaminationForm = ExaminationForm,
Mark = Mark,
Date = Date
};
}
}

View File

@ -0,0 +1,40 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class ReportType : IReportTypeModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[ForeignKey("ReportTypeId")]
public virtual List<ReportTypeActivity> ReportTypeActivities { get; set; } = new();
[ForeignKey("ReportTypeId")]
public virtual List<ReportTypeDiscipline> ReportTypeDisciplines { get; set; } = new();
public static ReportType Create(ReportTypeBindingModel model)
{
return new ReportType
{
Id = model.Id,
Name = model.Name
};
}
public void Update(ReportTypeBindingModel model)
{
if (model == null) return;
Id = model.Id;
Name = model.Name;
}
public ReportTypeViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class ReportTypeActivity
{
public int Id { get; set; }
[Required]
public int ReportTypeId { get; set; }
[Required]
public int ActivityId { get; set; }
public virtual ReportType ReportType { get; set; } = new();
public virtual Activity Activity { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class ReportTypeDiscipline
{
public int Id { get; set; }
[Required]
public int ReportTypeId { get; set; }
[Required]
public int DisciplineId { get; set; }
public virtual ReportType ReportType { get; set; } = new();
public virtual Discipline Discipline { get; set; } = new();
}
}

View File

@ -0,0 +1,46 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class Statement : IStatementModel
{
public int Id { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public int HoursCount { get; set; }
[ForeignKey("StatementId")]
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
[ForeignKey("StatementId")]
public virtual List<ExaminationResult> ExaminationResults { get; set; } = new();
public static Statement Create(StatementBindingModel model)
{
return new Statement
{
Id = model.Id,
Date = model.Date,
HoursCount = model.HoursCount
};
}
public void Update(StatementBindingModel model)
{
if (model == null) return;
Id = model.Id;
Date = model.Date;
HoursCount = model.HoursCount;
}
public StatementViewModel GetViewModel => new()
{
Id = Id,
Date = Date,
HoursCount = HoursCount,
};
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class StatementStudent
{
public int Id { get; set; }
[Required]
public int StudentTypeId { get; set; }
[Required]
public int StatementId { get; set; }
public virtual Student Student { get; set; } = new();
public virtual Statement Statement { get; set; } = new();
}
}

View File

@ -0,0 +1,65 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class Student : IStudentModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string RecordCardNumber { get; set; } = string.Empty;
[ForeignKey("StudentId")]
public virtual List<StatementStudent> StatementStudents { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<StudentExaminationResult> StudentExaminationResults { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<UserStudent> StudentUsers { get; set; } = new();
private Dictionary<int, IStatementModel>? _statements;
[NotMapped]
public Dictionary<int, IStatementModel> Statements
{
get
{
if (_statements == null)
{
_statements = StatementStudents.ToDictionary(
x => x.Statement.Id, x => x.Statement as IStatementModel);
}
return _statements;
}
}
public static Student Create(StudentBindingModel model)
{
return new Student
{
Id = model.Id,
Name = model.Name,
RecordCardNumber = model.RecordCardNumber
};
}
public void Update(StudentBindingModel model)
{
if (model == null) return;
Id = model.Id;
Name = model.Name;
RecordCardNumber = model.RecordCardNumber;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
RecordCardNumber = RecordCardNumber,
Statements = Statements
};
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class StudentExaminationResult
{
public int Id { get; set; }
[Required]
public int ExaminationResultId { get; set; }
[Required]
public int StudentId { get; set; }
public virtual ExaminationResult ExaminationResult { get; set; } = new();
public virtual Student Student { get; set; } = new();
}
}

View File

@ -0,0 +1,66 @@
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UniversityDatabaseImplement.Models
{
public class User : IUserModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
[Required]
public string Position { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("UserId")]
public virtual List<UserStudent> StudentUsers { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Statement> Statements { get; set; } = new();
public static User Create(UserBindingModel model)
{
return new User
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
PhoneNumber = model.PhoneNumber,
Position = model.Position,
Login = model.Login,
Password = model.Password
};
}
public void Update(UserBindingModel model)
{
if (model == null) return;
Id = model.Id;
Name = model.Name;
Surname = model.Surname;
PhoneNumber = model.PhoneNumber;
Position = model.Position;
Login = model.Login;
Password = model.Password;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
PhoneNumber = PhoneNumber,
Position = Position,
Login = Login,
Password = Password
};
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace UniversityDatabaseImplement.Models
{
public class UserStudent
{
public int Id { get; set; }
[Required]
public int StudentTypeId { get; set; }
[Required]
public int UserId { get; set; }
public virtual Student Student { get; set; } = new();
public virtual User User { get; set; } = new();
}
}

View File

@ -0,0 +1,29 @@
using UniversityDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace UniversityDatabaseImplement
{
public class UniversityDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=UniversityDatabase;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Activity> Activities { set; get; }
public virtual DbSet<Discipline> Disciplines { set; get; }
public virtual DbSet<ExaminationResult> ExaminationResults { set; get; }
public virtual DbSet<ReportType> ReportTypes { set; get; }
public virtual DbSet<ReportTypeActivity> ReportTypeActivities { set; get; }
public virtual DbSet<ReportTypeDiscipline> ReportTypeDisciplines { set; get; }
public virtual DbSet<Statement> Statements { set; get; }
public virtual DbSet<StatementStudent> StatementStudents { set; get; }
public virtual DbSet<Student> Students { set; get; }
public virtual DbSet<StudentExaminationResult> StudentExaminationResults { set; get; }
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<UserStudent> UserStudents { set; get; }
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -5,9 +5,13 @@ VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "University", "University\University.csproj", "{34B9CDDB-BFE5-48B9-AA3A-1A01D99A765D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDataModels", "UniversityDataModels\UniversityDataModels.csproj", "{36B2DE4B-7689-4287-911E-892FCD27AE84}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDataModels", "UniversityDataModels\UniversityDataModels.csproj", "{36B2DE4B-7689-4287-911E-892FCD27AE84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{BACEFD46-1073-4730-BC42-15B0D0D359C9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{BACEFD46-1073-4730-BC42-15B0D0D359C9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDatabaseImplement", "DatabaseImplement\UniversityDatabaseImplement.csproj", "{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityBuisnessLogic", "UniversityBuisnessLogic\UniversityBuisnessLogic.csproj", "{F29FD127-9597-44ED-A9A2-3CFB8E856442}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{BACEFD46-1073-4730-BC42-15B0D0D359C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BACEFD46-1073-4730-BC42-15B0D0D359C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BACEFD46-1073-4730-BC42-15B0D0D359C9}.Release|Any CPU.Build.0 = Release|Any CPU
{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E90DAE97-8D0D-4E8E-89BC-82D3B54DA067}.Release|Any CPU.Build.0 = Release|Any CPU
{F29FD127-9597-44ED-A9A2-3CFB8E856442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F29FD127-9597-44ED-A9A2-3CFB8E856442}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F29FD127-9597-44ED-A9A2-3CFB8E856442}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F29FD127-9597-44ED-A9A2-3CFB8E856442}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -8,4 +8,15 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DatabaseImplement\UniversityDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,102 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class ActivityLogic : IActivityLogic
{
private readonly ILogger _logger;
private readonly IActivityStorage _activityStorage;
public ActivityLogic(ILogger<ActivityLogic> logger, IActivityStorage activityStorage)
{
_logger = logger;
_activityStorage = activityStorage;
}
public bool Create(ActivityBindingModel model)
{
CheckModel(model);
if (_activityStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ActivityBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_activityStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ActivityViewModel? ReadElement(ActivitySearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _activityStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ActivityViewModel>? ReadList(ActivitySearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _activityStorage.GetFullList() : _activityStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ActivityBindingModel model)
{
CheckModel(model);
if (_activityStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ActivityBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Number <= 0)
{
throw new ArgumentNullException("Номер занятия должен быть больше 0", nameof(model.Number));
}
_logger.LogInformation("Activity. Number:{ComponentName}. Id: {Id}", model.Number, model.Id);
}
}
}

View File

@ -0,0 +1,117 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class DisciplineLogic : IDisciplineLogic
{
private readonly ILogger _logger;
private readonly IDisciplineStorage _disciplineStorage;
public DisciplineLogic(ILogger<DisciplineLogic> logger, IDisciplineStorage disciplineStorage)
{
_logger = logger;
_disciplineStorage = disciplineStorage;
}
public bool Create(DisciplineBindingModel model)
{
CheckModel(model);
if (_disciplineStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(DisciplineBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_disciplineStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DisciplineViewModel? ReadElement(DisciplineSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DisciplineName:{Name}. Id:{Id}", model.Name, model.Id);
var element = _disciplineStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<DisciplineViewModel>? ReadList(DisciplineSearchModel? model)
{
_logger.LogInformation("ReadList. DisciplineName: {Name}. Id:{Id}", model?.Name, model?.Id);
var list = model == null ? _disciplineStorage.GetFullList() : _disciplineStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(DisciplineBindingModel model)
{
CheckModel(model);
if (_disciplineStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(DisciplineBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия дисциплины", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Department))
{
throw new ArgumentNullException("Нет названия кафедры", nameof(model.Name));
}
_logger.LogInformation("Discipline. Name:{Name}. Department:{Department}. Id: {Id}", model.Name, model.Department, model.Id);
var element = _disciplineStorage.GetElement(new DisciplineSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Дисциплина с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,103 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class ExaminationResultLogic : IExaminationResultLogic
{
private readonly ILogger _logger;
private readonly IExaminationResultStorage _examinationResultStorage;
public ExaminationResultLogic(ILogger<ExaminationResultLogic> logger, IExaminationResultStorage examinationResultStorage)
{
_logger = logger;
_examinationResultStorage = examinationResultStorage;
}
public bool Create(ExaminationResultBindingModel model)
{
CheckModel(model);
if (_examinationResultStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ExaminationResultBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_examinationResultStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ExaminationResultViewModel? ReadElement(ExaminationResultSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _examinationResultStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ExaminationResultViewModel>? ReadList(ExaminationResultSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _examinationResultStorage.GetFullList() : _examinationResultStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ExaminationResultBindingModel model)
{
CheckModel(model);
if (_examinationResultStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ExaminationResultBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ExaminationForm))
{
throw new ArgumentNullException("Нет формы испытания", nameof(model.ExaminationForm));
}
_logger.LogInformation("ExaminationResult. ExaminationForm: {ExaminationForm}. Id: {Id}", model.ExaminationForm, model.Id);
}
}
}

View File

@ -0,0 +1,115 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class ReportLogic : IReportLogic
{
ILogger _logger;
IDisciplineStorage _disciplineStorage;
IStatementStorage _statementStorage;
IExaminationResultStorage _examinationResultStorage;
public ReportLogic(ILogger<ReportLogic> logger, IDisciplineStorage disciplineStorage,
IStatementStorage statementStorage, IExaminationResultStorage examinationResultStorage)
{
_logger = logger;
_disciplineStorage = disciplineStorage;
_statementStorage = statementStorage;
_examinationResultStorage = examinationResultStorage;
}
public List<ReportStudentsViewModel> GetStudens(ReportBindingModel model)
{
if (model == null) return new();
var results = _examinationResultStorage.GetFilteredList(new ExaminationResultSearchModel
{
From = model.From,
To = model.To,
});
var statements = _statementStorage.GetFilteredList(new StatementSearchModel
{
From = model.From,
To = model.To,
});
List<ReportStudentsViewModel> list = new();
foreach (var result in results)
{
foreach(var student in result.Students.Values)
{
foreach(var statement in statements)
{
if (!student.Statements.ContainsKey(statement.Id)) continue;
list.Add(new ReportStudentsViewModel
{
StudentName = student.Name,
ExaminationForm = result.ExaminationForm,
mark = result.Mark,
ExaminationResultDate = result.Date,
HoursCount = statement.HoursCount,
StatementDate = statement.Date
});
}
}
}
return list;
}
public List<ReportStudentDisciplineViewModel> GetStudentDiscipline(ReportBindingModel model)
{
if (model == null || model.Students == null) return new();
var disciplines = _disciplineStorage.GetFullList();
List<ReportStudentDisciplineViewModel> result = new();
foreach(var student in model.Students)
{
var record = new ReportStudentDisciplineViewModel
{
StudentName = student.Name,
};
foreach(var discipline in disciplines)
{
foreach (var statement in discipline.DisciplineStatements)
{
if(student.Statements.ContainsKey(statement.Key))
{
record.Disciplines.Add(discipline.Name);
break;
}
}
}
result.Add(record);
}
return result;
}
public void SaveStudentsToExcel()
{
throw new NotImplementedException("Реализация в следующем этапе");
}
public void SaveStudentsToPdf()
{
throw new NotImplementedException("Реализация в следующем этапе");
}
public void SaveStudentsToWord()
{
throw new NotImplementedException("Реализация в следующем этапе");
}
}
}

View File

@ -0,0 +1,112 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class ReportTypeLogic : IReportTypeLogic
{
private readonly ILogger _logger;
private readonly IReportTypeStorage _reportTypeStorage;
public ReportTypeLogic(ILogger<ReportTypeLogic> logger, IReportTypeStorage reportTypeStorage)
{
_logger = logger;
_reportTypeStorage = reportTypeStorage;
}
public bool Create(ReportTypeBindingModel model)
{
CheckModel(model);
if (_reportTypeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ReportTypeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_reportTypeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ReportTypeViewModel? ReadElement(ReportTypeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ReportTypeName: {Name}. Id:{Id}", model.Name, model.Id);
var element = _reportTypeStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ReportTypeViewModel>? ReadList(ReportTypeSearchModel? model)
{
_logger.LogInformation("ReadList. ReportTypeName: {Name}. Id:{Id}", model?.Name, model?.Id);
var list = model == null ? _reportTypeStorage.GetFullList() : _reportTypeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ReportTypeBindingModel model)
{
CheckModel(model);
if (_reportTypeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ReportTypeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия типа отчета", nameof(model.Name));
}
_logger.LogInformation("ReportType. ReportName:{Name}. Id: { Id}", model.Name, model.Id);
var element = _reportTypeStorage.GetElement(new ReportTypeSearchModel
{
Name = model.Name,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Тип отчета с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,101 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class StatementLogic : IStatementLogic
{
private readonly ILogger _logger;
private readonly IStatementStorage _statementStorage;
public StatementLogic(ILogger<StatementLogic> logger, IStatementStorage statementStorage)
{
_logger = logger;
_statementStorage = statementStorage;
}
public bool Create(StatementBindingModel model)
{
CheckModel(model);
if (_statementStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(StatementBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_statementStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public StatementViewModel? ReadElement(StatementSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _statementStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
f
public List<StatementViewModel>? ReadList(StatementSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _statementStorage.GetFullList() : _statementStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(StatementBindingModel model)
{
CheckModel(model);
if (_statementStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(StatementBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.HoursCount <= 0)
{
throw new ArgumentNullException("Количество часов в ведомости должно быть больше 0", nameof(model.HoursCount));
}
_logger.LogInformation("Statement. HoursCount:{HoursCount}. Id: { Id}", model.HoursCount, model.Id);
}
}
}

View File

@ -0,0 +1,101 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class StudentLogic : IStudentLogic
{
private readonly ILogger _logger;
private readonly IStudentStorage _studentStorage;
public StudentLogic(ILogger<StudentLogic> logger, IStudentStorage studentStorage)
{
_logger = logger;
_studentStorage = studentStorage;
}
public bool Create(StudentBindingModel model)
{
CheckModel(model);
if (_studentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(StudentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_studentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public StudentViewModel? ReadElement(StudentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. StudentName: {Name}. Id:{Id}", model.Name, model.Id);
var element = _studentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<StudentViewModel>? ReadList(StudentSearchModel? model)
{
_logger.LogInformation("ReadList. StudentName: {Name}. Id:{Id}", model?.Name, model?.Id);
var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(StudentBindingModel model)
{
CheckModel(model);
if (_studentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(StudentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет имени студента", nameof(model.Name));
}
_logger.LogInformation("Student. Name:{Name}. Id: { Id}", model.Name, model.Id);
}
}
}

View File

@ -0,0 +1,130 @@
using UniversityContracts.BindingModels;
using UniversityContracts.BuisnessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StoragesContracts;
using UniversityContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace UniversityBuisnessLogic.BuisnessLogic
{
public class UserLogic : IUserLogic
{
private readonly ILogger _logger;
private readonly IUserStorage _userStorage;
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage)
{
_logger = logger;
_userStorage = userStorage;
}
public bool Create(UserBindingModel model)
{
CheckModel(model);
if (_userStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(UserBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_userStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public UserViewModel? ReadElement(UserSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _userStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<UserViewModel>? ReadList(UserSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(UserBindingModel model)
{
CheckModel(model);
if (_userStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(UserBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Surname))
{
throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет фамилии пароля", nameof(model.Name));
}
else if (model.Password.Length < 6)
{
throw new ArgumentNullException("В пароле должно быть не менее 6 символов", nameof(model.Name));
}
_logger.LogInformation("User. Name:{Name}. Surname:{Surname}. Login: {Login} " +
"Password: {Password}. Id: {Id}", model.Name, model.Surname, model.Login, model.Password, model.Id);
var element = _userStorage.GetElement(new UserSearchModel
{
Login = model.Login,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Пользователь с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
</ItemGroup>
</Project>