From 22f02bc6bb94a73b554fee93f4b2ea9dfc47ad8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Fri, 3 May 2024 02:48:53 +0400 Subject: [PATCH] =?UTF-8?q?=E2=94=90(=E3=82=B7)=E2=94=8C=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/LawyerBindingModel.cs | 2 +- .../LawCompanyContracts/ViewModels/LawyerViewModel.cs | 2 +- LawCompany/LawCompanyDataModels/Models/ILawyerModel.cs | 2 +- .../Implements/GuarantorStorage.cs | 2 +- .../Implements/LawyerStorage.cs | 2 +- .../LawCompanyDatabaseImplement/LawCompanyDatabase.cs | 2 +- .../LawCompanyDatabaseImplement/Models/Guarantor.cs | 3 +-- .../LawCompanyDatabaseImplement/Models/Lawyer.cs | 10 ++++------ LawCompany/LawCompanyRestApi/Program.cs | 4 ++-- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs index 5345171..bdde6fc 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs @@ -8,6 +8,6 @@ namespace LawCompanyContracts.BindingModels public string FIO { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; - public int GuarantorId { get; set; } + public int? GuarantorId { get; set; } } } diff --git a/LawCompany/LawCompanyContracts/ViewModels/LawyerViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/LawyerViewModel.cs index c4acb81..464674f 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/LawyerViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/LawyerViewModel.cs @@ -13,6 +13,6 @@ namespace LawCompanyContracts.ViewModels public string Phone { get; set; } = string.Empty; [DisplayName("E-mail юриста")] public string Email { get; set; } = string.Empty; - public int GuarantorId { get; set; } + public int? GuarantorId { get; set; } } } \ No newline at end of file diff --git a/LawCompany/LawCompanyDataModels/Models/ILawyerModel.cs b/LawCompany/LawCompanyDataModels/Models/ILawyerModel.cs index 2adbd99..c0ce300 100644 --- a/LawCompany/LawCompanyDataModels/Models/ILawyerModel.cs +++ b/LawCompany/LawCompanyDataModels/Models/ILawyerModel.cs @@ -7,6 +7,6 @@ namespace LawCompanyDataModels.Models string FIO { get; } string Phone { get; } string Email { get; } - public int GuarantorId { get; } + public int? GuarantorId { get; } } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs index 40def90..b5d93e2 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs @@ -59,7 +59,7 @@ namespace LawCompanyDatabaseImplement.Implements public GuarantorViewModel? Insert(GuarantorBindingModel model) { using var context = new LawCompanyDatabase(); - var newGuarantor = Guarantor.Create(model); + var newGuarantor = Guarantor.Create(context, model); if (newGuarantor == null) { return null; diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs index ed501b0..aad4e05 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs @@ -61,7 +61,7 @@ namespace LawCompanyDatabaseImplement.Implements public LawyerViewModel? Insert(LawyerBindingModel model) { using var context = new LawCompanyDatabase(); - var newLawyer = Lawyer.Create(model); + var newLawyer = Lawyer.Create(context, model); if (newLawyer == null) { return null; diff --git a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs index 2bb5359..a9fd10e 100644 --- a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs +++ b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs @@ -15,7 +15,7 @@ namespace LawCompanyDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-H8060U3\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-6GNIALH9\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs index 7d66157..b41f4c7 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs @@ -22,8 +22,7 @@ namespace LawCompanyDatabaseImplement.Models public virtual List Lawyers { get; set; } = new(); [ForeignKey("GuarantorId")] public virtual List Consultations { get; set; } = new(); - - public static Guarantor? Create(GuarantorBindingModel? model) + public static Guarantor? Create(LawCompanyDatabase context, GuarantorBindingModel? model) { if (model == null) { diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs index 8b93ea6..d79d066 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Lawyer.cs @@ -1,12 +1,9 @@ using LawCompanyContracts.BindingModels; using LawCompanyContracts.ViewModels; using LawCompanyDataModels.Models; -using LawCompanyDataModels.Models; -using LawCompanyContracts.BindingModels; -using LawCompanyContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; - +using System.ComponentModel.Design; namespace LawCompanyDatabaseImplement.Models { @@ -23,9 +20,9 @@ namespace LawCompanyDatabaseImplement.Models public virtual List HearingLawyers { get; set; } = new(); [ForeignKey("LawyerId")] public virtual List ConsultationLawyers { get; set; } = new(); - public int GuarantorId { get; set; } + public int? GuarantorId { get; set; } - public static Lawyer? Create(LawyerBindingModel? model) + public static Lawyer? Create(LawCompanyDatabase context, LawyerBindingModel? model) { if (model == null) { @@ -60,6 +57,7 @@ namespace LawCompanyDatabaseImplement.Models FIO = model.FIO; Email = model.Email; Phone = model.Phone; + if (!model.GuarantorId.HasValue) GuarantorId = model.GuarantorId; } public LawyerViewModel GetViewModel => new() { diff --git a/LawCompany/LawCompanyRestApi/Program.cs b/LawCompany/LawCompanyRestApi/Program.cs index a99d617..346e70e 100644 --- a/LawCompany/LawCompanyRestApi/Program.cs +++ b/LawCompany/LawCompanyRestApi/Program.cs @@ -20,7 +20,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -//builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -32,7 +32,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -//builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers();