diff --git a/StudentEnrollment/StudentEnrollmentBusinessLogic/StudentLogic.cs b/StudentEnrollment/StudentEnrollmentBusinessLogic/StudentLogic.cs index c87078d..77df5ec 100644 --- a/StudentEnrollment/StudentEnrollmentBusinessLogic/StudentLogic.cs +++ b/StudentEnrollment/StudentEnrollmentBusinessLogic/StudentLogic.cs @@ -34,7 +34,7 @@ namespace StudentEnrollmentBusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadList. TIN: {TIN}. Id:{Id}", model?.TIN, model.Id); + _logger.LogInformation("ReadList. TIN: {TIN}. Id:{Id}", model?.TIN, model?.Id); var element = _studentStorage.GetElement(model); if (element == null) { diff --git a/StudentEnrollment/StudentEnrollmentContracts/BindingModels/CourseBindingModel.cs b/StudentEnrollment/StudentEnrollmentContracts/BindingModels/CourseBindingModel.cs index 786c4ac..a3ab1fe 100644 --- a/StudentEnrollment/StudentEnrollmentContracts/BindingModels/CourseBindingModel.cs +++ b/StudentEnrollment/StudentEnrollmentContracts/BindingModels/CourseBindingModel.cs @@ -6,6 +6,6 @@ namespace StudentEnrollmentContracts.BindingModels { public long Id { get; set; } public string CourseName { get; set; } = string.Empty; - public string FacultyName { get; set; } = string.Empty; + public long FacultyId { get; set; } } } diff --git a/StudentEnrollment/StudentEnrollmentContracts/BindingModels/StudentBindingModel.cs b/StudentEnrollment/StudentEnrollmentContracts/BindingModels/StudentBindingModel.cs index 3db81a7..abfbbbb 100644 --- a/StudentEnrollment/StudentEnrollmentContracts/BindingModels/StudentBindingModel.cs +++ b/StudentEnrollment/StudentEnrollmentContracts/BindingModels/StudentBindingModel.cs @@ -11,7 +11,7 @@ namespace StudentEnrollmentContracts.BindingModels public string Email { get; set; } = string.Empty; public string TIN { get; set; } = string.Empty; public long ExamPointsId { get; set; } - public Dictionary StudentCourse + public Dictionary StudentCourse { get; set; diff --git a/StudentEnrollment/StudentEnrollmentContracts/ViewModels/CourseViewModel.cs b/StudentEnrollment/StudentEnrollmentContracts/ViewModels/CourseViewModel.cs index b9100d7..9203669 100644 --- a/StudentEnrollment/StudentEnrollmentContracts/ViewModels/CourseViewModel.cs +++ b/StudentEnrollment/StudentEnrollmentContracts/ViewModels/CourseViewModel.cs @@ -10,5 +10,6 @@ namespace StudentEnrollmentContracts.ViewModels public string CourseName { get; set; } = string.Empty; [DisplayName("Название факультета")] public string FacultyName { get; set; } = string.Empty; + public long FacultyId { get; set; } } } diff --git a/StudentEnrollment/StudentEnrollmentContracts/ViewModels/StudentViewModel.cs b/StudentEnrollment/StudentEnrollmentContracts/ViewModels/StudentViewModel.cs index 8442317..f7be59d 100644 --- a/StudentEnrollment/StudentEnrollmentContracts/ViewModels/StudentViewModel.cs +++ b/StudentEnrollment/StudentEnrollmentContracts/ViewModels/StudentViewModel.cs @@ -19,7 +19,7 @@ namespace StudentEnrollmentContracts.ViewModels public long ExamPointsId { get; set; } [DisplayName("Суммарное количество баллов")] public int ExamPoints { get; set; } - public Dictionary StudentCourse + public Dictionary StudentCourse { get; set; diff --git a/StudentEnrollment/StudentEnrollmentDataModels/Models/ICourseModel.cs b/StudentEnrollment/StudentEnrollmentDataModels/Models/ICourseModel.cs index a812f5a..8114ee9 100644 --- a/StudentEnrollment/StudentEnrollmentDataModels/Models/ICourseModel.cs +++ b/StudentEnrollment/StudentEnrollmentDataModels/Models/ICourseModel.cs @@ -3,6 +3,6 @@ public interface ICourseModel : IId { string CourseName { get; } - string FacultyName { get; } + long FacultyId { get; } } } diff --git a/StudentEnrollment/StudentEnrollmentDataModels/Models/IStudentModel.cs b/StudentEnrollment/StudentEnrollmentDataModels/Models/IStudentModel.cs index 4470402..f74c9ff 100644 --- a/StudentEnrollment/StudentEnrollmentDataModels/Models/IStudentModel.cs +++ b/StudentEnrollment/StudentEnrollmentDataModels/Models/IStudentModel.cs @@ -8,6 +8,6 @@ string Email { get; } string TIN { get; } long ExamPointsId { get; } - Dictionary StudentCourse { get; } + Dictionary StudentCourse { get; } } } diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/CourseStorage.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/CourseStorage.cs new file mode 100644 index 0000000..c72392b --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/CourseStorage.cs @@ -0,0 +1,9 @@ +using StudentEnrollmentContracts.StorageContracts; + +namespace StudentEnrollmentDatabaseImplement.Implements +{ + public class CourseStorage : ICourseStorage + { + // TODO: Implement this + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/ExamPoints.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/ExamPoints.cs new file mode 100644 index 0000000..c27c6bc --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/ExamPoints.cs @@ -0,0 +1,9 @@ +using StudentEnrollmentContracts.StorageContracts; + +namespace StudentEnrollmentDatabaseImplement.Implements +{ + public class ExamPoints : IExamPointsStorage + { + // TODO: Implement this + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/FacultyStorage.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/FacultyStorage.cs new file mode 100644 index 0000000..cb74514 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/FacultyStorage.cs @@ -0,0 +1,12 @@ +using StudentEnrollmentContracts.BindingModels; +using StudentEnrollmentContracts.SearchModels; +using StudentEnrollmentContracts.StorageContracts; +using StudentEnrollmentContracts.ViewModels; + +namespace StudentEnrollmentDatabaseImplement.Implements +{ + public class FacultyStorage : IFacultyStorage + { + // TODO: Implement this + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/StudentStorage.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/StudentStorage.cs new file mode 100644 index 0000000..04ae528 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Implements/StudentStorage.cs @@ -0,0 +1,9 @@ +using StudentEnrollmentContracts.StorageContracts; + +namespace StudentEnrollmentDatabaseImplement.Implements +{ + public class StudentStorage : IStudentStorage + { + // TODO: Implement this + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Course.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Course.cs new file mode 100644 index 0000000..a662616 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Course.cs @@ -0,0 +1,49 @@ +using StudentEnrollmentContracts.BindingModels; +using StudentEnrollmentContracts.ViewModels; +using StudentEnrollmentDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace StudentEnrollmentDatabaseImplement.Models +{ + public class Course : ICourseModel + { + public long Id { get; private set; } + [Required] + public string CourseName { get; private set; } = string.Empty; + [Required] + public long FacultyId { get; private set; } + + [ForeignKey("CourseId")] + public virtual List StudentCourses { get; set; } = new(); + + public static Course? Create(CourseBindingModel model) + { + if (model == null) + { + return null; + } + return new Course() + { + Id = model.Id, + CourseName = model.CourseName, + FacultyId = model.FacultyId, + }; + } + public void Update(CourseBindingModel model) + { + if (model == null) + { + return; + } + CourseName = model.CourseName; + FacultyId = model.FacultyId; + } + public CourseViewModel GetViewModel => new() + { + Id = Id, + CourseName = CourseName, + FacultyId = FacultyId, + }; + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/ExamPoints.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/ExamPoints.cs new file mode 100644 index 0000000..46c15d1 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/ExamPoints.cs @@ -0,0 +1,43 @@ +using StudentEnrollmentContracts.BindingModels; +using StudentEnrollmentDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace StudentEnrollmentDatabaseImplement.Models +{ + public class ExamPoints : IExamPointsModel + { + public long Id { get; private set; } + [Required] + public int FirstExamPoints { get; private set; } + [Required] + public int SecondExamPoints { get; private set; } + [Required] + public int ThirdExamPoints { get; private set; } + public int AddPoints { get; private set; } + public int Summary { get; private set; } + public static ExamPoints? Create(ExamPointsBindingModel model) + { + if (model == null) { + return null; + } + return new ExamPoints() + { + Id = model.Id, + FirstExamPoints = model.FirstExamPoints, + SecondExamPoints = model.SecondExamPoints, + ThirdExamPoints = model.ThirdExamPoints, + AddPoints = model.AddPoints, + Summary = model.Summary, + }; + } + public void Update(ExamPointsBindingModel model) + { + if (model == null) + { + return; + } + AddPoints = model.AddPoints; + Summary = model.Summary; + } + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Faculty.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Faculty.cs new file mode 100644 index 0000000..3a67287 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Faculty.cs @@ -0,0 +1,37 @@ +using StudentEnrollmentContracts.BindingModels; +using StudentEnrollmentContracts.ViewModels; +using StudentEnrollmentDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace StudentEnrollmentDatabaseImplement.Models +{ + public class Faculty : IFacultyModel + { + public long Id { get; private set; } + [Required] + public string FacultyName { get; private set;} = string.Empty; + public static Faculty? Create(FacultyBindingModel model) + { + if (model == null) + return null; + return new Faculty() + { + Id = model.Id, + FacultyName = model.FacultyName, + }; + } + + public void Update(FacultyBindingModel model) + { + if (model == null) + return; + FacultyName = model.FacultyName; + } + + public FacultyViewModel GetViewModel => new() + { + Id = Id, + FacultyName = FacultyName, + }; + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs new file mode 100644 index 0000000..b8bcc88 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs @@ -0,0 +1,60 @@ +using StudentEnrollmentContracts.BindingModels; +using StudentEnrollmentDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace StudentEnrollmentDatabaseImplement.Models +{ + public class Student : IStudentModel + { + public long Id { get; private set; } + [Required] + public string FirstName { get; private set; } = string.Empty; + [Required] + public string LastName { get; private set; } = string.Empty; + public string MiddleName { get; private set; } = string.Empty; + [Required] + public string Email { get; private set; } = string.Empty; + [Required] + public string TIN { get; private set; } = string.Empty; + [Required] + public long ExamPointsId { get; private set; } + private Dictionary? _StudentCourse = null; + public Dictionary StudentCourse + { + get + { + if (_StudentCourse == null) + { + _StudentCourse = Courses.ToDictionary(SC => SC.CourseId, + SC => SC.Course as ICourseModel); + } + return _StudentCourse; + } + } + [ForeignKey("StudentId")] + public virtual List Courses { get; set; } = new(); + + public static Student? Create(StudentEnrollmentDatabase context,StudentBindingModel model) + { + if (model == null) + { + return null; + } + return new Student() + { + Id = model.Id, + FirstName = model.FirstName, + LastName = model.LastName, + MiddleName = model.MiddleName, + Email = model.Email, + TIN = model.TIN, + Courses = model.StudentCourse.Select(x => new StudentCourse + { + Course = context.Courses.First(y => y.Id == x.Key) + } + ).ToList(), + }; + } + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/StudentCourse.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/StudentCourse.cs new file mode 100644 index 0000000..28d90d7 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/StudentCourse.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace StudentEnrollmentDatabaseImplement.Models +{ + public class StudentCourse + { + public long Id { get; set; } + [Required] + public long StudentId { get; set; } + [Required] + public long CourseId { get; set; } + public virtual Student Student { get; set; } = new(); + public virtual Course Course { get; set; } = new(); + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabase.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabase.cs new file mode 100644 index 0000000..23f2b81 --- /dev/null +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabase.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using StudentEnrollmentDatabaseImplement.Models; + +namespace StudentEnrollmentDatabaseImplement +{ + public class StudentEnrollmentDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql(@"Host=localhost;Database=StudentEnrollmentDatabase;Username=postgres;Password=postgres"); + } + base.OnConfiguring(optionsBuilder); + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + AppContext.SetSwitch("Npgsql.DisableDataTimeInfinityConversions", true); + } + public virtual DbSet Faculties { get; set; } + public virtual DbSet Courses { get; set; } + public virtual DbSet Students { get; set; } + public virtual DbSet StudentCourses { get; set; } + public virtual DbSet ExamPointes { get; set; } + + } +} diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabaseImplement.csproj b/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabaseImplement.csproj index cfadb03..7f7ba89 100644 --- a/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabaseImplement.csproj +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/StudentEnrollmentDatabaseImplement.csproj @@ -6,4 +6,13 @@ enable + + + + + + + + +