From 0e7a46e2e1bd6797a2526186acbb0fb85c4afe8f 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: Wed, 1 May 2024 23:48:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 2 - .../BusinessLogics/ConsultationLogic.cs | 236 ++++++++-------- .../BusinessLogics/ExecutorLogic.cs | 8 +- .../BusinessLogics/GuarantorLogic.cs | 206 +++++++------- .../BusinessLogics/LawyerLogic.cs | 267 +++++++++--------- .../BindingModels/ConsultationBindingModel.cs | 18 +- .../BindingModels/GuarantorBindingModel.cs | 14 +- .../BindingModels/LawyerBindingModel.cs | 16 +- .../IConsultationLogic.cs | 22 +- .../BusinessLogicContracts/IGuarantorLogic.cs | 21 +- .../BusinessLogicContracts/IHearingLogic.cs | 27 +- .../BusinessLogicContracts/ILawyerLogic.cs | 25 +- .../SearchModels/ConsultationSearchModel.cs | 18 +- .../SearchModels/GuarantorSearchModel.cs | 22 +- .../SearchModels/HearingSearchModel.cs | 22 +- .../SearchModels/LawyerSearchModel.cs | 24 +- .../SearchModels/VisitSearchModel.cs | 8 +- .../StoragesContracts/ICaseStorage.cs | 18 +- .../StoragesContracts/IConsultationStorage.cs | 18 +- .../StoragesContracts/IGuarantorStorage.cs | 18 +- .../StoragesContracts/IHearingStorage.cs | 18 +- .../StoragesContracts/ILawyerStorage.cs | 22 +- .../ViewModels/ConsultationViewModel.cs | 30 +- .../ViewModels/IGuarantorViewModel.cs | 20 +- .../ViewModels/ILawyerViewModel.cs | 24 +- .../Implements/GuarantorStorage.cs | 171 ++++++----- .../Implements/LawyerStorage.cs | 198 ++++++------- .../Models/Guarantor.cs | 2 +- 28 files changed, 725 insertions(+), 770 deletions(-) diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs index 8569c90..5c28cad 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs @@ -142,8 +142,6 @@ namespace LawCompanyBusinessLogic.BusinessLogics FIO = model.FIO, Phone = model.Phone, Email = model.Email, - ExecutorId = model.ExecutorId, - }); if (element != null && element.Id != model.Id) { diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs index 6024678..3049397 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ConsultationLogic.cs @@ -1,140 +1,140 @@ -using LawCompanyContracts.BindingModels; +using LawCompanyDataModels.Models; +using LawCompanyContracts.BindingModels; using LawCompanyContracts.BusinessLogicContracts; using LawCompanyContracts.SearchModels; using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; -using LawCompanyDataModels.Models; using Microsoft.Extensions.Logging; namespace LawCompanyBusinessLogic.BusinessLogics { - public class ConsultationLogic : IConsultationLogic - { - private readonly ILogger _logger; - private readonly IConsultationStorage _consultationStorage; + public class ConsultationLogic : IConsultationLogic + { + private readonly ILogger _logger; + private readonly IConsultationStorage _consultationStorage; - public ConsultationLogic(ILogger logger, IConsultationStorage consultationStorage) - { - _logger = logger; - _consultationStorage = consultationStorage; - } + public ConsultationLogic(ILogger logger, IConsultationStorage consultationStorage) + { + _logger = logger; + _consultationStorage = consultationStorage; + } - public bool Create(ConsultationBindingModel model) - { - CheckModel(model); - if (_consultationStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public bool Create(ConsultationBindingModel model) + { + CheckModel(model); + if (_consultationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool Delete(ConsultationBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_consultationStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } + public bool Delete(ConsultationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_consultationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } - public ConsultationViewModel? ReadElement(ConsultationSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ConsultationDate:{ConsultationDate}. Id:{Id}", model.ConsultationDate, model.Id); - var element = _consultationStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } + public ConsultationViewModel? ReadElement(ConsultationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ConsultationDate:{ConsultationDate}. Id:{Id}", model.ConsultationDate, model.Id); + var element = _consultationStorage.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? ReadList(ConsultationSearchModel? model) - { - _logger.LogInformation("ReadList. ConsultationDate:{ConsultationDate}.Id:{Id}", model?.ConsultationDate, model?.Id); - var list = model == null ? _consultationStorage.GetFullList() : _consultationStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadList(ConsultationSearchModel? model) + { + _logger.LogInformation("ReadList. ConsultationDate:{ConsultationDate}.Id:{Id}", model?.ConsultationDate, model?.Id); + var list = model == null ? _consultationStorage.GetFullList() : _consultationStorage.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(ConsultationBindingModel model) - { - CheckModel(model); - if (_consultationStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } + public bool Update(ConsultationBindingModel model) + { + CheckModel(model); + if (_consultationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } - var element = _consultationStorage.GetElement(model); + var element = _consultationStorage.GetElement(model); - if (element == null) - { - return false; - } + if (element == null) + { + return false; + } - element.ConsultationLawyers[lawyer.Id] = lawyer; + element.ConsultationLawyers[lawyer.Id] = lawyer; - _consultationStorage.Update(new() - { - Id = element.Id, - Cost = element.Cost, - ConsultationDate = element.ConsultationDate, - CaseId = element.CaseId, - ConsultationLawyers = element.ConsultationLawyers, - GuarantorId = element.GuarantorId, - }); + _consultationStorage.Update(new() + { + Id = element.Id, + Cost = element.Cost, + ConsultationDate = element.ConsultationDate, + CaseId = element.CaseId, + ConsultationLawyers = element.ConsultationLawyers, + GuarantorId = element.GuarantorId, + }); - return true; - } - private void CheckModel(ConsultationBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty((model.ConsultationDate).ToString())) - { - throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate)); - } + return true; + } + private void CheckModel(ConsultationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty((model.ConsultationDate).ToString())) + { + throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate)); + } - _logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id); - var element = _consultationStorage.GetElement(new ConsultationSearchModel - { - ConsultationDate = model.ConsultationDate + _logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id); + var element = _consultationStorage.GetElement(new ConsultationSearchModel + { + ConsultationDate = model.ConsultationDate - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("На данное время уже назначена консультация"); - } - } - } + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("На данное время уже назначена консультация"); + } + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs index 0dc5de3..4300395 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs @@ -17,7 +17,7 @@ namespace LawCompanyBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IExecutorStorage _executorStorage; - public ExecutorLogic(ILogger logger, IExecutorStorage executorStorage) + public ExecutorLogic(ILogger logger, IExecutorStorage executorStorage) { _logger = logger; _executorStorage = executorStorage; @@ -119,8 +119,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Исполнитель с такими данными уже есть"); - } - } + throw new InvalidOperationException("Исполнитель с такими данными уже есть"); + } + } } } diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/GuarantorLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/GuarantorLogic.cs index 3d179f1..1d9ef79 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/GuarantorLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/GuarantorLogic.cs @@ -7,115 +7,115 @@ using Microsoft.Extensions.Logging; namespace LawCompanyBusinessLogic.BusinessLogics { - public class GuarantorLogic : IGuarantorLogic - { - private readonly ILogger _logger; - private readonly IGuarantorStorage _guarantorStorage; + public class GuarantorLogic : IGuarantorLogic + { + private readonly ILogger _logger; + private readonly IGuarantorStorage _guarantorStorage; - public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage) - { - _logger = logger; - _guarantorStorage = guarantorStorage; - } + public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage) + { + _logger = logger; + _guarantorStorage = guarantorStorage; + } - public bool Create(GuarantorBindingModel model) - { - CheckModel(model); - if (_guarantorStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public bool Create(GuarantorBindingModel model) + { + CheckModel(model); + if (_guarantorStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool Update(GuarantorBindingModel model) - { - CheckModel(model); - if (_guarantorStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } + public bool Update(GuarantorBindingModel model) + { + CheckModel(model); + if (_guarantorStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } - public bool Delete(GuarantorBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_guarantorStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } + public bool Delete(GuarantorBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_guarantorStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } - public List? ReadList(GuarantorSearchModel? model) - { - _logger.LogInformation("ReadList. GuarantorName:{GuarantorName}.Id:{Id}", model?.FIO, model?.Id); - var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadList(GuarantorSearchModel? model) + { + _logger.LogInformation("ReadList. GuarantorName:{GuarantorName}.Id:{Id}", model?.FIO, model?.Id); + var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public GuarantorViewModel? ReadElement(GuarantorSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. GuarantorName:{GuarantorName}. Id:{Id}", model.FIO, model.Id); - var element = _guarantorStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } + public GuarantorViewModel? ReadElement(GuarantorSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. GuarantorName:{GuarantorName}. Id:{Id}", model.FIO, model.Id); + var element = _guarantorStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } - private void CheckModel(GuarantorBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.FIO)) - { - throw new ArgumentNullException("Нет имени поручителя", nameof(model.FIO)); - } - if (string.IsNullOrEmpty(model.Email)) - { - throw new ArgumentNullException("Нет e-mail поручителя", nameof(model.Email)); - } - if (string.IsNullOrEmpty(model.Password)) - { - throw new ArgumentNullException("Нет пароля поручителя", nameof(model.Password)); - } + private void CheckModel(GuarantorBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("Нет имени поручителя", nameof(model.FIO)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет e-mail поручителя", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля поручителя", nameof(model.Password)); + } - _logger.LogInformation("Guarantor. GuarantorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id); - var element = _guarantorStorage.GetElement(new GuarantorSearchModel - { - FIO = model.FIO, - Email = model.Email, - Password = model.Password, - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Поручитель с такими данными уже есть"); - } - } - } + _logger.LogInformation("Guarantor. GuarantorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id); + var element = _guarantorStorage.GetElement(new GuarantorSearchModel + { + FIO = model.FIO, + Email = model.Email, + Password = model.Password, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Поручитель с такими данными уже есть"); + } + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/LawyerLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/LawyerLogic.cs index 04399c2..45a71af 100644 --- a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/LawyerLogic.cs +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/LawyerLogic.cs @@ -7,148 +7,147 @@ using Microsoft.Extensions.Logging; namespace LawCompanyBusinessLogic.BusinessLogics { - public class LawyerLogic : ILawyerLogic - { - private readonly ILogger _logger; - private readonly ILawyerStorage _lawyerStorage; + public class LawyerLogic : ILawyerLogic + { + private readonly ILogger _logger; + private readonly ILawyerStorage _lawyerStorage; - public LawyerLogic(ILogger logger, ILawyerStorage lawyerStorage) - { - _logger = logger; - _lawyerStorage = lawyerStorage; - } + public LawyerLogic(ILogger logger, ILawyerStorage lawyerStorage) + { + _logger = logger; + _lawyerStorage = lawyerStorage; + } - public bool Create(LawyerBindingModel model) - { - CheckModel(model); - if (_lawyerStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public bool Create(LawyerBindingModel model) + { + CheckModel(model); + if (_lawyerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool Delete(LawyerBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_lawyerStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } + public bool Delete(LawyerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_lawyerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } - public List? ReadHearingElementList(HearingSearchModel? model) - { - if (model == null) - { - return null; - } - var list = _lawyerStorage.GetLawyerHearingList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadHearingElementList(HearingSearchModel? model) + { + if (model == null) + { + return null; + } + var list = _lawyerStorage.GetLawyerHearingList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public List? ReadConsultationElementList(ConsultationSearchModel? model) - { - if (model == null) - { - return null; - } - var list = _lawyerStorage.GetLawyerConsultationList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadConsultationElementList(ConsultationSearchModel? model) + { + if (model == null) + { + return null; + } + var list = _lawyerStorage.GetLawyerConsultationList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public LawyerViewModel? ReadElement(LawyerSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. LawyerName:{FIO}. Id:{Id}", model.FIO, model.Id); - var element = _lawyerStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } + public LawyerViewModel? ReadElement(LawyerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. LawyerName:{FIO}. Id:{Id}", model.FIO, model.Id); + var element = _lawyerStorage.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? ReadList(LawyerSearchModel? model) - { - _logger.LogInformation("ReadList. LawyerName:{LawyerName}.Id:{Id}", model?.FIO, model?.Id); - var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadList(LawyerSearchModel? model) + { + _logger.LogInformation("ReadList. LawyerName:{LawyerName}.Id:{Id}", model?.FIO, model?.Id); + var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.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(LawyerBindingModel model) - { - CheckModel(model); - if (_lawyerStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - private void CheckModel(LawyerBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.FIO)) - { - throw new ArgumentNullException("Нет имени юриста", nameof(model.FIO)); - } - if (string.IsNullOrEmpty(model.Phone)) - { - throw new ArgumentNullException("Нет телефона юриста", nameof(model.Phone)); - } - if (string.IsNullOrEmpty(model.Email)) - { - throw new ArgumentNullException("Нет e-mail юриста", nameof(model.Email)); - } + public bool Update(LawyerBindingModel model) + { + CheckModel(model); + if (_lawyerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(LawyerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("Нет имени юриста", nameof(model.FIO)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет телефона юриста", nameof(model.Phone)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет e-mail юриста", nameof(model.Email)); + } - _logger.LogInformation("Lawyer. LawyerName:{FIO}. Phone: {Phone}. E-mail:{Email}. Id: {Id} ", model.FIO, model.Phone, model.Email, model.Id); - var element = _lawyerStorage.GetElement(new LawyerSearchModel - { - FIO = model.FIO, - Phone = model.Phone, - Email = model.Email, - GuarantorId = model.GuarantorId, + _logger.LogInformation("Lawyer. LawyerName:{FIO}. Phone: {Phone}. E-mail:{Email}. Id: {Id} ", model.FIO, model.Phone, model.Email, model.Id); + var element = _lawyerStorage.GetElement(new LawyerSearchModel + { + FIO = model.FIO, + Phone = model.Phone, + Email = model.Email, - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Юрист с такими данными уже есть"); - } - } - } + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Юрист с такими данными уже есть"); + } + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs index 00e95f0..c594fa1 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/ConsultationBindingModel.cs @@ -2,13 +2,13 @@ namespace LawCompanyContracts.BindingModels { - public class ConsultationBindingModel : IConsultationModel - { - public int Id { get; set; } - public double Cost { get; set; } - public DateTime ConsultationDate { get; set; } - public int CaseId { get; set; } - public int GuarantorId { get; set; } - public Dictionary ConsultationLawyers { get; set; } = new(); - } + public class ConsultationBindingModel : IConsultationModel + { + public int Id { get; set; } + public double Cost { get; set; } + public DateTime ConsultationDate { get; set; } + public int CaseId { get; set; } + public int GuarantorId { get; set; } + public Dictionary ConsultationLawyers { get; set; } = new(); + } } diff --git a/LawCompany/LawCompanyContracts/BindingModels/GuarantorBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/GuarantorBindingModel.cs index 72d6eb7..1428553 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/GuarantorBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/GuarantorBindingModel.cs @@ -2,13 +2,13 @@ namespace LawCompanyContracts.BindingModels { - public class GuarantorBindingModel : IGuarantorModel - { - public int Id { get; set; } - public string FIO { get; set; } = string.Empty; + public class GuarantorBindingModel : IGuarantorModel + { + public int Id { get; set; } + public string FIO { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - } + public string Password { get; set; } = string.Empty; + } } diff --git a/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs b/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs index 19090b9..bdde6fc 100644 --- a/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs +++ b/LawCompany/LawCompanyContracts/BindingModels/LawyerBindingModel.cs @@ -2,12 +2,12 @@ namespace LawCompanyContracts.BindingModels { - public class LawyerBindingModel : ILawyerModel - { - public int Id { get; set; } - 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 class LawyerBindingModel : ILawyerModel + { + public int Id { get; set; } + 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; } + } } diff --git a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IConsultationLogic.cs b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IConsultationLogic.cs index 8f3a703..a0a891f 100644 --- a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IConsultationLogic.cs +++ b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IConsultationLogic.cs @@ -1,17 +1,17 @@ -using LawCompanyContracts.BindingModels; -using LawCompanyDataModels.Models; +using LawCompanyDataModels.Models; +using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.BusinessLogicContracts { - public interface IConsultationLogic - { - List? ReadList(ConsultationSearchModel? model); - ConsultationViewModel? ReadElement(ConsultationSearchModel model); - bool Create(ConsultationBindingModel model); - bool Update(ConsultationBindingModel model); - bool Delete(ConsultationBindingModel model); - bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer); - } + public interface IConsultationLogic + { + List? ReadList(ConsultationSearchModel? model); + ConsultationViewModel? ReadElement(ConsultationSearchModel model); + bool Create(ConsultationBindingModel model); + bool Update(ConsultationBindingModel model); + bool Delete(ConsultationBindingModel model); + bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IGuarantorLogic.cs b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IGuarantorLogic.cs index 03cbf7f..610d122 100644 --- a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IGuarantorLogic.cs +++ b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IGuarantorLogic.cs @@ -1,20 +1,15 @@ using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawCompanyContracts.BusinessLogicContracts { - public interface IGuarantorLogic - { - List? ReadList(GuarantorSearchModel? model); - GuarantorViewModel? ReadElement(GuarantorSearchModel model); - bool Create(GuarantorBindingModel model); - bool Update(GuarantorBindingModel model); - bool Delete(GuarantorBindingModel model); - } + public interface IGuarantorLogic + { + List? ReadList(GuarantorSearchModel? model); + GuarantorViewModel? ReadElement(GuarantorSearchModel model); + bool Create(GuarantorBindingModel model); + bool Update(GuarantorBindingModel model); + bool Delete(GuarantorBindingModel model); + } } diff --git a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IHearingLogic.cs b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IHearingLogic.cs index fbca5b8..b198572 100644 --- a/LawCompany/LawCompanyContracts/BusinessLogicContracts/IHearingLogic.cs +++ b/LawCompany/LawCompanyContracts/BusinessLogicContracts/IHearingLogic.cs @@ -1,22 +1,17 @@ -using LawCompanyContracts.BindingModels; -using LawCompanyDataModels.Models; +using LawCompanyDataModels.Models; +using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawCompanyContracts.BusinessLogicContracts { - public interface IHearingLogic - { - List? ReadList(HearingSearchModel? model); - HearingViewModel? ReadElement(HearingSearchModel model); - bool Create(HearingBindingModel model); - bool Update(HearingBindingModel model); - bool Delete(HearingBindingModel model); - bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel client); - } + public interface IHearingLogic + { + List? ReadList(HearingSearchModel? model); + HearingViewModel? ReadElement(HearingSearchModel model); + bool Create(HearingBindingModel model); + bool Update(HearingBindingModel model); + bool Delete(HearingBindingModel model); + bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel client); + } } diff --git a/LawCompany/LawCompanyContracts/BusinessLogicContracts/ILawyerLogic.cs b/LawCompany/LawCompanyContracts/BusinessLogicContracts/ILawyerLogic.cs index 4422455..75a2c56 100644 --- a/LawCompany/LawCompanyContracts/BusinessLogicContracts/ILawyerLogic.cs +++ b/LawCompany/LawCompanyContracts/BusinessLogicContracts/ILawyerLogic.cs @@ -1,22 +1,17 @@ using LawCompanyContracts.BindingModels; using LawCompanyContracts.SearchModels; using LawCompanyContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawCompanyContracts.BusinessLogicContracts { - public interface ILawyerLogic - { - List? ReadHearingElementList(HearingSearchModel? model); - List? ReadConsultationElementList(ConsultationSearchModel? model); - List? ReadList(LawyerSearchModel? model); - LawyerViewModel? ReadElement(LawyerSearchModel model); - bool Create(LawyerBindingModel model); - bool Update(LawyerBindingModel model); - bool Delete(LawyerBindingModel model); - } + public interface ILawyerLogic + { + List? ReadHearingElementList(HearingSearchModel? model); + List? ReadConsultationElementList(ConsultationSearchModel? model); + List? ReadList(LawyerSearchModel? model); + LawyerViewModel? ReadElement(LawyerSearchModel model); + bool Create(LawyerBindingModel model); + bool Update(LawyerBindingModel model); + bool Delete(LawyerBindingModel model); + } } diff --git a/LawCompany/LawCompanyContracts/SearchModels/ConsultationSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/ConsultationSearchModel.cs index c40303f..99d76f4 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/ConsultationSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/ConsultationSearchModel.cs @@ -1,11 +1,13 @@ namespace LawCompanyContracts.SearchModels { - public class ConsultationSearchModel - { - public int? Id { get; set; } - public double? Cost { get; set; } - public DateTime? ConsultationDate { get; set; } - public int? CaseId { get; set; } - public int? GuarantorId { get; set; } - } + public class ConsultationSearchModel + { + public int? Id { get; set; } + public double? Cost { get; set; } + public DateTime? ConsultationDate { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public int? CaseId { get; set; } + public int? GuarantorId { get; set; } + } } diff --git a/LawCompany/LawCompanyContracts/SearchModels/GuarantorSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/GuarantorSearchModel.cs index 954a3fd..17c6721 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/GuarantorSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/GuarantorSearchModel.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.SearchModels +namespace LawCompanyContracts.SearchModels { - public class GuarantorSearchModel - { - public int? Id { get; set; } - public string? FIO { get; set; } - public string? Email { get; set; } - public string? Password { get; set; } - } + public class GuarantorSearchModel + { + public int? Id { get; set; } + public string? FIO { get; set; } + public string? Email { get; set; } + public string? Password { get; set; } + } } diff --git a/LawCompany/LawCompanyContracts/SearchModels/HearingSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/HearingSearchModel.cs index 8a2e72c..3815ead 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/HearingSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/HearingSearchModel.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.SearchModels +namespace LawCompanyContracts.SearchModels { - public class HearingSearchModel - { - public int? Id { get; set; } - public DateTime? HearingDate { get; set; } - public int? GuarantorId { get; set; } - } + public class HearingSearchModel + { + public int? Id { get; set; } + public DateTime? HearingDate { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public int? GuarantorId { get; set; } + } } diff --git a/LawCompany/LawCompanyContracts/SearchModels/LawyerSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/LawyerSearchModel.cs index 5df671f..e405c2d 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/LawyerSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/LawyerSearchModel.cs @@ -1,17 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.SearchModels +namespace LawCompanyContracts.SearchModels { - public class LawyerSearchModel - { - public int? Id { get; set; } - public string? FIO { get; set; } - public string? Phone { get; set; } - public string? Email { get; set; } - public int? GuarantorId { get; set; } - } + public class LawyerSearchModel + { + public int? Id { get; set; } + public string? FIO { get; set; } + public string? Phone { get; set; } + public string? Email { get; set; } + public int? GuarantorId { get; set; } + } } diff --git a/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs b/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs index 065327d..75f444d 100644 --- a/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs +++ b/LawCompany/LawCompanyContracts/SearchModels/VisitSearchModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawCompanyContracts.SearchModels +namespace LawCompanyContracts.SearchModels { public class VisitSearchModel { diff --git a/LawCompany/LawCompanyContracts/StoragesContracts/ICaseStorage.cs b/LawCompany/LawCompanyContracts/StoragesContracts/ICaseStorage.cs index a5a67ed..d16b346 100644 --- a/LawCompany/LawCompanyContracts/StoragesContracts/ICaseStorage.cs +++ b/LawCompany/LawCompanyContracts/StoragesContracts/ICaseStorage.cs @@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.StoragesContracts { - public interface ICaseStorage - { - List GetFullList(); - List GetFilteredList(CaseSearchModel model); - CaseViewModel? GetElement(CaseSearchModel model); - CaseViewModel? Insert(CaseBindingModel model); - CaseViewModel? Update(CaseBindingModel model); - CaseViewModel? Delete(CaseBindingModel model); - } + public interface ICaseStorage + { + List GetFullList(); + List GetFilteredList(CaseSearchModel model); + CaseViewModel? GetElement(CaseSearchModel model); + CaseViewModel? Insert(CaseBindingModel model); + CaseViewModel? Update(CaseBindingModel model); + CaseViewModel? Delete(CaseBindingModel model); + } } diff --git a/LawCompany/LawCompanyContracts/StoragesContracts/IConsultationStorage.cs b/LawCompany/LawCompanyContracts/StoragesContracts/IConsultationStorage.cs index 9dc897f..fc0a90c 100644 --- a/LawCompany/LawCompanyContracts/StoragesContracts/IConsultationStorage.cs +++ b/LawCompany/LawCompanyContracts/StoragesContracts/IConsultationStorage.cs @@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.StoragesContracts { - public interface IConsultationStorage - { - List GetFullList(); - List GetFilteredList(ConsultationSearchModel model); - ConsultationViewModel? GetElement(ConsultationSearchModel model); - ConsultationViewModel? Insert(ConsultationBindingModel model); - ConsultationViewModel? Update(ConsultationBindingModel model); - ConsultationViewModel? Delete(ConsultationBindingModel model); - } + public interface IConsultationStorage + { + List GetFullList(); + List GetFilteredList(ConsultationSearchModel model); + ConsultationViewModel? GetElement(ConsultationSearchModel model); + ConsultationViewModel? Insert(ConsultationBindingModel model); + ConsultationViewModel? Update(ConsultationBindingModel model); + ConsultationViewModel? Delete(ConsultationBindingModel model); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/StoragesContracts/IGuarantorStorage.cs b/LawCompany/LawCompanyContracts/StoragesContracts/IGuarantorStorage.cs index 0d14238..17ba69b 100644 --- a/LawCompany/LawCompanyContracts/StoragesContracts/IGuarantorStorage.cs +++ b/LawCompany/LawCompanyContracts/StoragesContracts/IGuarantorStorage.cs @@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.StoragesContracts { - public interface IGuarantorStorage - { - List GetFullList(); - List GetFilteredList(GuarantorSearchModel model); - GuarantorViewModel? GetElement(GuarantorSearchModel model); - GuarantorViewModel? Insert(GuarantorBindingModel model); - GuarantorViewModel? Update(GuarantorBindingModel model); - GuarantorViewModel? Delete(GuarantorBindingModel model); - } + public interface IGuarantorStorage + { + List GetFullList(); + List GetFilteredList(GuarantorSearchModel model); + GuarantorViewModel? GetElement(GuarantorSearchModel model); + GuarantorViewModel? Insert(GuarantorBindingModel model); + GuarantorViewModel? Update(GuarantorBindingModel model); + GuarantorViewModel? Delete(GuarantorBindingModel model); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/StoragesContracts/IHearingStorage.cs b/LawCompany/LawCompanyContracts/StoragesContracts/IHearingStorage.cs index bdacf50..ef0f696 100644 --- a/LawCompany/LawCompanyContracts/StoragesContracts/IHearingStorage.cs +++ b/LawCompany/LawCompanyContracts/StoragesContracts/IHearingStorage.cs @@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.StoragesContracts { - public class IHearingStorage - { - List GetFullList(); - List GetFilteredList(HearingSearchModel model); - HearingViewModel? GetElement(HearingSearchModel model); - HearingViewModel? Insert(HearingBindingModel model); - HearingViewModel? Update(HearingBindingModel model); - HearingViewModel? Delete(HearingBindingModel model); - } + public interface IHearingStorage + { + List GetFullList(); + List GetFilteredList(HearingSearchModel model); + HearingViewModel? GetElement(HearingSearchModel model); + HearingViewModel? Insert(HearingBindingModel model); + HearingViewModel? Update(HearingBindingModel model); + HearingViewModel? Delete(HearingBindingModel model); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/StoragesContracts/ILawyerStorage.cs b/LawCompany/LawCompanyContracts/StoragesContracts/ILawyerStorage.cs index 5432eb3..673020d 100644 --- a/LawCompany/LawCompanyContracts/StoragesContracts/ILawyerStorage.cs +++ b/LawCompany/LawCompanyContracts/StoragesContracts/ILawyerStorage.cs @@ -4,15 +4,15 @@ using LawCompanyContracts.ViewModels; namespace LawCompanyContracts.StoragesContracts { - public class ILawyerStorage - { - List GetFullList(); - List GetFilteredList(LawyerSearchModel model); - List GetLawyerConsultationList(ConsultationSearchModel model); - List GetLawyerHearingList(HearingSearchModel model); - LawyerViewModel? GetElement(LawyerSearchModel model); - LawyerViewModel? Insert(LawyerBindingModel model); - LawyerViewModel? Update(LawyerBindingModel model); - LawyerViewModel? Delete(LawyerBindingModel model); - } + public interface ILawyerStorage + { + List GetFullList(); + List GetFilteredList(LawyerSearchModel model); + List GetLawyerConsultationList(ConsultationSearchModel model); + List GetLawyerHearingList(HearingSearchModel model); + LawyerViewModel? GetElement(LawyerSearchModel model); + LawyerViewModel? Insert(LawyerBindingModel model); + LawyerViewModel? Update(LawyerBindingModel model); + LawyerViewModel? Delete(LawyerBindingModel model); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs index d4ac4c2..518d224 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ConsultationViewModel.cs @@ -3,20 +3,18 @@ using System.ComponentModel; namespace LawCompanyContracts.ViewModels { - public class ConsultationViewModel : IConsultationModel - { - [DisplayName("Номер консультации")] - public int Id { get; set; } - [DisplayName("Цена консультации")] - public double Cost { get; set; } - [DisplayName("Дата консультации")] - public DateTime ConsultationDate { get; set; } - [DisplayName("Дело")] - public string CaseName { get; set; } = string.Empty; - public int CaseId { get; set; } - [DisplayName("Имя поручителя")] - public string GuarantorName { get; set; } = string.Empty; - public int GuarantorId { get; set; } - public Dictionary ConsultationLawyers { get; set; } = new(); - } + public class ConsultationViewModel : IConsultationModel + { + [DisplayName("Номер консультации")] + public int Id { get; set; } + [DisplayName("Цена консультации")] + public double Cost { get; set; } + [DisplayName("Дата консультации")] + public DateTime ConsultationDate { get; set; } + [DisplayName("Дело")] + public string CaseName { get; set; } = string.Empty; + public int CaseId { get; set; } + public int GuarantorId { get; set; } + public Dictionary ConsultationLawyers { get; set; } = new(); + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/ViewModels/IGuarantorViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/IGuarantorViewModel.cs index 00f0d80..29aca75 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/IGuarantorViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/IGuarantorViewModel.cs @@ -3,14 +3,14 @@ using System.ComponentModel; namespace LawCompanyContracts.ViewModels { - public class GuarantorViewModel : IGuarantorModel - { - public int Id { get; set; } - [DisplayName("Имя поручителя")] - public string FIO { get; set; } = string.Empty; - [DisplayName("E-mail поручителя")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль поручителя")] - public string Password { get; set; } = string.Empty; - } + public class GuarantorViewModel : IGuarantorModel + { + public int Id { get; set; } + [DisplayName("Имя поручителя")] + public string FIO { get; set; } = string.Empty; + [DisplayName("E-mail поручителя")] + public string Email { get; set; } = string.Empty; + [DisplayName("Пароль поручителя")] + public string Password { get; set; } = string.Empty; + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyContracts/ViewModels/ILawyerViewModel.cs b/LawCompany/LawCompanyContracts/ViewModels/ILawyerViewModel.cs index 37baf6b..464674f 100644 --- a/LawCompany/LawCompanyContracts/ViewModels/ILawyerViewModel.cs +++ b/LawCompany/LawCompanyContracts/ViewModels/ILawyerViewModel.cs @@ -3,16 +3,16 @@ using System.ComponentModel; namespace LawCompanyContracts.ViewModels { - public class LawyerViewModel : ILawyerModel - { - [DisplayName("Номер юриста")] - public int Id { get; set; } - [DisplayName("Имя юриста")] - public string FIO { get; set; } = string.Empty; - [DisplayName("Телефон юриста")] - public string Phone { get; set; } = string.Empty; - [DisplayName("E-mail юриста")] - public string Email { get; set; } = string.Empty; - public int? GuarantorId { get; set; } - } + public class LawyerViewModel : ILawyerModel + { + [DisplayName("Номер юриста")] + public int Id { get; set; } + [DisplayName("Имя юриста")] + public string FIO { get; set; } = string.Empty; + [DisplayName("Телефон юриста")] + public string Phone { get; set; } = string.Empty; + [DisplayName("E-mail юриста")] + public string Email { get; set; } = string.Empty; + public int? GuarantorId { get; set; } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs index 6200376..d500a7e 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs @@ -3,101 +3,96 @@ using LawCompanyContracts.SearchModels; using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; using LawCompanyDatabaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawCompanyDatabaseImplement.Implements { - public class GuarantorStorage : IGuarantorStorage - { - public List GetFullList() - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Select(x => x.GetViewModel) - .ToList(); - } + public class GuarantorStorage : IGuarantorStorage + { + public List GetFullList() + { + using var context = new LawCompanyDatabase(); + return context.Guarantors + .Select(x => x.GetViewModel) + .ToList(); + } - public List GetFilteredList(GuarantorSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Password)) - { - return new(); - } - if (!string.IsNullOrEmpty(model.Email)) - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Where(x => x.Email.Equals(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - } + public List GetFilteredList(GuarantorSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) + && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + if (!string.IsNullOrEmpty(model.Email)) + { + using var context = new LawCompanyDatabase(); + return context.Guarantors + .Where(x => x.Email.Equals(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new LawCompanyDatabase(); + return context.Guarantors + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } - public GuarantorViewModel? GetElement(GuarantorSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Password)) - { - return null; - } - using var context = new LawCompanyDatabase(); + public GuarantorViewModel? GetElement(GuarantorSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) + && string.IsNullOrEmpty(model.Password)) + { + return null; + } + using var context = new LawCompanyDatabase(); - return context.Guarantors - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) - && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } + return context.Guarantors + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) + && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } - public GuarantorViewModel? Insert(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var newGuarantor = Guarantor.Create(model); - if (newGuarantor == null) - { - return null; - } - context.Guarantors.Add(newGuarantor); - context.SaveChanges(); - return newGuarantor.GetViewModel; - } + public GuarantorViewModel? Insert(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var newGuarantor = Guarantor.Create(context, model); + if (newGuarantor == null) + { + return null; + } + context.Guarantors.Add(newGuarantor); + context.SaveChanges(); + return newGuarantor.GetViewModel; + } - public GuarantorViewModel? Update(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); - if (executor == null) - { - return null; - } - executor.Update(model); - context.SaveChanges(); - return executor.GetViewModel; - } + public GuarantorViewModel? Update(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); + if (executor == null) + { + return null; + } + executor.Update(model); + context.SaveChanges(); + return executor.GetViewModel; + } - public GuarantorViewModel? Delete(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Guarantors.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } + public GuarantorViewModel? Delete(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Guarantors.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs index 6a21383..9ab1588 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/LawyerStorage.cs @@ -6,105 +6,105 @@ using LawCompanyDatabaseImplement.Models; namespace LawCompanyDatabaseImplement.Implements { - public class LawyerStorage : ILawyerStorage - { - public List GetFullList() - { - using var context = new LawCompanyDatabase(); - return context.Lawyers - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(LawyerSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue && string.IsNullOrEmpty(model.FIO)) - { - return new(); - } - if (!string.IsNullOrEmpty(model.Email)) - { - using var context = new LawCompanyDatabase(); - return context.Lawyers - .Where(x => x.Email.Equals(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.GuarantorId.HasValue) - { - using var context = new LawCompanyDatabase(); - return context.Lawyers - .Where(x => x.GuarantorId.Equals(model.GuarantorId)) - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - using var context = new LawCompanyDatabase(); - return context.Lawyers - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - } - public LawyerViewModel? GetElement(LawyerSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue - && string.IsNullOrEmpty(model.FIO)) - { - return null; - } - using var context = new LawCompanyDatabase(); - return context.Lawyers - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.GuarantorId.HasValue && x.GuarantorId == model.GuarantorId)) - ?.GetViewModel; - } - public LawyerViewModel? Insert(LawyerBindingModel model) - { - using var context = new LawCompanyDatabase(); - var newLawyer = Lawyer.Create(model); - if (newLawyer == null) - { - return null; - } - context.Lawyers.Add(newLawyer); - context.SaveChanges(); - return newLawyer.GetViewModel; - } - public LawyerViewModel? Update(LawyerBindingModel model) - { - using var context = new LawCompanyDatabase(); - var lawyer = context.Lawyers.FirstOrDefault(x => x.Id == model.Id); - if (lawyer == null) - { - return null; - } - lawyer.Update(model); - context.SaveChanges(); - return lawyer.GetViewModel; - } - public LawyerViewModel? Delete(LawyerBindingModel model) - { - using var context = new LawCompanyDatabase(); - var element = context.Lawyers.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Lawyers.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - public List GetLawyerHearingList(HearingSearchModel model) - { - using var context = new LawCompanyDatabase(); - return context.HearingLawyers.Where(x => x.HearingId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList(); + public class LawyerStorage : ILawyerStorage + { + public List GetFullList() + { + using var context = new LawCompanyDatabase(); + return context.Lawyers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(LawyerSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue && string.IsNullOrEmpty(model.FIO)) + { + return new(); + } + if (!string.IsNullOrEmpty(model.Email)) + { + using var context = new LawCompanyDatabase(); + return context.Lawyers + .Where(x => x.Email.Equals(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.GuarantorId.HasValue) + { + using var context = new LawCompanyDatabase(); + return context.Lawyers + .Where(x => x.GuarantorId.Equals(model.GuarantorId)) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new LawCompanyDatabase(); + return context.Lawyers + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public LawyerViewModel? GetElement(LawyerSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue + && string.IsNullOrEmpty(model.FIO)) + { + return null; + } + using var context = new LawCompanyDatabase(); + return context.Lawyers + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.GuarantorId.HasValue && x.GuarantorId == model.GuarantorId)) + ?.GetViewModel; + } + public LawyerViewModel? Insert(LawyerBindingModel model) + { + using var context = new LawCompanyDatabase(); + var newLawyer = Lawyer.Create(context, model); + if (newLawyer == null) + { + return null; + } + context.Lawyers.Add(newLawyer); + context.SaveChanges(); + return newLawyer.GetViewModel; + } + public LawyerViewModel? Update(LawyerBindingModel model) + { + using var context = new LawCompanyDatabase(); + var lawyer = context.Lawyers.FirstOrDefault(x => x.Id == model.Id); + if (lawyer == null) + { + return null; + } + lawyer.Update(model); + context.SaveChanges(); + return lawyer.GetViewModel; + } + public LawyerViewModel? Delete(LawyerBindingModel model) + { + using var context = new LawCompanyDatabase(); + var element = context.Lawyers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Lawyers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + public List GetLawyerHearingList(HearingSearchModel model) + { + using var context = new LawCompanyDatabase(); + return context.HearingLawyers.Where(x => x.HearingId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList(); - } - public List GetLawyerConsultationList(ConsultationSearchModel model) - { - using var context = new LawCompanyDatabase(); - return context.ConsultationLawyers.Where(x => x.ConsultationId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList(); + } + public List GetLawyerConsultationList(ConsultationSearchModel model) + { + using var context = new LawCompanyDatabase(); + return context.ConsultationLawyers.Where(x => x.ConsultationId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList(); - } - } + } + } } \ No newline at end of file diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs index feda3a9..a79d7ec 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Guarantor.cs @@ -3,7 +3,7 @@ using LawCompanyContracts.BindingModels; using LawCompanyContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using LawFirmDatabaseImplement.Models; +using LawCompanyDatabaseImplement.Models; namespace LawCompanyDatabaseImplement.Models {