From 4b0110e728a84883976c0d1900592d816cd355ef Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:20:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20database?= =?UTF-8?q?Implement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- University/University.sln | 6 ++ .../Models/IStudentModel.cs | 2 +- .../Implements/AttestationStorage.cs | 13 ++++ .../Implements/PlanOfStudyStorage.cs | 13 ++++ .../Implements/StudentStorage.cs | 13 ++++ .../Models/Attestation.cs | 20 ++++++ .../Models/PlanOfStudy.cs | 20 ++++++ .../Models/Student.cs | 65 +++++++++++++++++++ .../UniversityDatabase.cs | 24 +++++++ .../UniversityDatabaseImplement.csproj | 23 +++++++ 10 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 University/UniversityDatabaseImplement/Implements/AttestationStorage.cs create mode 100644 University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs create mode 100644 University/UniversityDatabaseImplement/Implements/StudentStorage.cs create mode 100644 University/UniversityDatabaseImplement/Models/Attestation.cs create mode 100644 University/UniversityDatabaseImplement/Models/PlanOfStudy.cs create mode 100644 University/UniversityDatabaseImplement/Models/Student.cs create mode 100644 University/UniversityDatabaseImplement/UniversityDatabase.cs create mode 100644 University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj diff --git a/University/University.sln b/University/University.sln index 7a02fdc..f214fca 100644 --- a/University/University.sln +++ b/University/University.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDataModels", "Uni EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityContracts", "UniversityContracts\UniversityContracts.csproj", "{9510FE77-96E8-4ED9-B8D7-18FE309B98C9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDatabaseImplement", "UniversityDatabaseImplement\UniversityDatabaseImplement.csproj", "{A8D828DA-DC23-4D25-9B71-4169F5A55FC1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {9510FE77-96E8-4ED9-B8D7-18FE309B98C9}.Release|Any CPU.Build.0 = Release|Any CPU + {A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8D828DA-DC23-4D25-9B71-4169F5A55FC1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/University/UniversityDataModels/Models/IStudentModel.cs b/University/UniversityDataModels/Models/IStudentModel.cs index 588e744..24b3be0 100644 --- a/University/UniversityDataModels/Models/IStudentModel.cs +++ b/University/UniversityDataModels/Models/IStudentModel.cs @@ -3,7 +3,7 @@ public interface IStudentModel : IId { string Name { get; } - public string PhoneNumber { get; } + string PhoneNumber { get; } int PlanOfStudyId { get; } } } diff --git a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs new file mode 100644 index 0000000..8685292 --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.StorageContracts; + +namespace UniversityDatabaseImplement.Implements +{ + public class AttestationStorage : IAttestationStorage + { + } +} diff --git a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs new file mode 100644 index 0000000..cad2218 --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.StorageContracts; + +namespace UniversityDatabaseImplement.Implements +{ + public class PlanOfStudyStorage : IPlanOfStudyStorage + { + } +} diff --git a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs new file mode 100644 index 0000000..6ab1cfe --- /dev/null +++ b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.StorageContracts; + +namespace UniversityDatabaseImplement.Implements +{ + public class StudentStorage : IStudentStorage + { + } +} diff --git a/University/UniversityDatabaseImplement/Models/Attestation.cs b/University/UniversityDatabaseImplement/Models/Attestation.cs new file mode 100644 index 0000000..14e2eec --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Attestation.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Attestation : IAttestationModel + { + public int Id { get; set; } + public int StudentId { get; set; } + [Required] + public string FormOfEvaluation { get; private set; } = string.Empty; + [Required] + public string Score { get; private set; } = string.Empty; + } +} diff --git a/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs new file mode 100644 index 0000000..9670bab --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/PlanOfStudy.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class PlanOfStudy : IPlanOfStudyModel + { + public int Id { get; set; } + public int WorkerId { get; set; } + [Required] + public string Profile { get; private set; } = string.Empty; + [Required] + public string FormOfStudy { get; private set; } = string.Empty; + } +} diff --git a/University/UniversityDatabaseImplement/Models/Student.cs b/University/UniversityDatabaseImplement/Models/Student.cs new file mode 100644 index 0000000..ad7b13d --- /dev/null +++ b/University/UniversityDatabaseImplement/Models/Student.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModel; +using UniversityContracts.ViewModels; +using UniversityDataModels.Models; + +namespace UniversityDatabaseImplement.Models +{ + public class Student : IStudentModel + { + public int Id { get; private set; } + public int PlanOfStudyId { get; private set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string PhoneNumber { get; private set; } = string.Empty; + + public static Student? Create(StudentBindingModel model) + { + if (model == null) + { + return null; + } + return new Student() + { + Id = model.Id, + PlanOfStudyId = model.PlanOfStudyId, + Name = model.Name, + PhoneNumber = model.PhoneNumber + }; + } + public static Student Create(StudentViewModel model) + { + return new Student + { + Id = model.Id, + PlanOfStudyId = model.PlanOfStudyId, + Name = model.Name, + PhoneNumber = model.PhoneNumber + }; + } + public void Update(StudentBindingModel model) + { + if (model == null) + { + return; + } + PhoneNumber = model.PhoneNumber; + Name = model.Name; + PlanOfStudyId = model.PlanOfStudyId; + } + public StudentViewModel GetViewModel => new() + { + Id = Id, + PlanOfStudyId = PlanOfStudyId, + Name = Name, + PhoneNumber = PhoneNumber + }; + } +} diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs new file mode 100644 index 0000000..278cf7d --- /dev/null +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel; +using UniversityDatabaseImplement.Models; + +namespace UniversityDatabaseImplement +{ + public class UniversityDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder + optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=PlumbingRepairDatabaseFull;Username=postgres;Password=postgres"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Students { set; get; } + public virtual DbSet PlansOfStudy { set; get; } + public virtual DbSet Attestations { set; get; } + // public virtual DbSet Workers { set; get; } + // public virtual DbSet Storekeepers { set; get; } + } +} diff --git a/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj new file mode 100644 index 0000000..06b233b --- /dev/null +++ b/University/UniversityDatabaseImplement/UniversityDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + +