From b21f5b85ad6d01e1091f9cdc881c3085e15a671e Mon Sep 17 00:00:00 2001 From: "a.puchkina" Date: Sat, 27 Apr 2024 19:02:25 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=83=D1=87=D0=B8=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/IConsultationModel.cs | 4 +- .../LawFimDataModels/Models/IHearingModel.cs | 2 +- .../LawFimDataModels/Models/ILawyerModel.cs | 12 +- .../BusinessLogics/ConsultationLogic.cs | 140 ++++++++++++++++ .../BusinessLogics/ExecutorLogic.cs | 2 +- .../BusinessLogics/GuarantorLogic.cs | 121 ++++++++++++++ .../BusinessLogics/HearingLogic.cs | 139 ++++++++++++++++ .../BusinessLogics/LawyerLogic.cs | 153 ++++++++++++++++++ .../BindingModels/ConsultationBindingModel.cs | 2 +- .../BindingModels/GuarantorBindingModel.cs | 2 +- .../BusinessLogicContracts/IGuarantorLogic.cs | 17 +- .../BusinessLogicContracts/IHearingLogic.cs | 9 +- .../BusinessLogicContracts/ILawyerLogic.cs | 8 +- .../SearchModels/GuarantorSearchModel.cs | 8 +- .../SearchModels/HearingSearchModel.cs | 8 +- .../SearchModels/LawyerSearchModel.cs | 8 +- .../StoragesContracts/IHearingStorage.cs | 2 +- .../StoragesContracts/ILawyerStorage.cs | 2 +- .../ViewModels/ConsultationViewModel.cs | 4 +- .../Implements/ConsultationStorage.cs | 111 +++++++++++++ 20 files changed, 694 insertions(+), 60 deletions(-) create mode 100644 LawFim/LawFirmBusinessLogic/BusinessLogics/ConsultationLogic.cs create mode 100644 LawFim/LawFirmBusinessLogic/BusinessLogics/GuarantorLogic.cs create mode 100644 LawFim/LawFirmBusinessLogic/BusinessLogics/HearingLogic.cs create mode 100644 LawFim/LawFirmBusinessLogic/BusinessLogics/LawyerLogic.cs create mode 100644 LawFim/LawFirmDatabaseImplement/Implements/ConsultationStorage.cs diff --git a/LawFim/LawFimDataModels/Models/IConsultationModel.cs b/LawFim/LawFimDataModels/Models/IConsultationModel.cs index 77cd66a..ddb5a28 100644 --- a/LawFim/LawFimDataModels/Models/IConsultationModel.cs +++ b/LawFim/LawFimDataModels/Models/IConsultationModel.cs @@ -4,8 +4,8 @@ { Dictionary ConsultationLawyers { get; } double Cost { get; } - DateTime CosultationDate { get; } + DateTime ConsultationDate { get; } public int CaseId { get; } - public int GuarantorId { get; } // не уверена + public int GuarantorId { get; } } } diff --git a/LawFim/LawFimDataModels/Models/IHearingModel.cs b/LawFim/LawFimDataModels/Models/IHearingModel.cs index 767dab4..9fd85a0 100644 --- a/LawFim/LawFimDataModels/Models/IHearingModel.cs +++ b/LawFim/LawFimDataModels/Models/IHearingModel.cs @@ -5,6 +5,6 @@ Dictionary HearingLawyers { get; } DateTime HearingDate { get; } string Judge { get; } - public int GuarantorId { get; } // не уверена + public int GuarantorId { get; } } } diff --git a/LawFim/LawFimDataModels/Models/ILawyerModel.cs b/LawFim/LawFimDataModels/Models/ILawyerModel.cs index d274f7e..98bbfdd 100644 --- a/LawFim/LawFimDataModels/Models/ILawyerModel.cs +++ b/LawFim/LawFimDataModels/Models/ILawyerModel.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawFimDataModels.Models +namespace LawFimDataModels.Models { - public interface ILawyerModel: IId + public interface ILawyerModel: IId { string FIO { get; } string Phone { get; } string Email { get; } - public int GuarantorId { get; } // не уверена + public int GuarantorId { get; } } } diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/ConsultationLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/ConsultationLogic.cs new file mode 100644 index 0000000..68d80aa --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/ConsultationLogic.cs @@ -0,0 +1,140 @@ +using LawFimDataModels.Models; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class ConsultationLogic : IConsultationLogic + { + private readonly ILogger _logger; + private readonly IConsultationStorage _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 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 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)); + } + + var element = _consultationStorage.GetElement(model); + + if (element == null) + { + return false; + } + + 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, + }); + + 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 + + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("На данное время уже назначена консультация"); + } + } + } +} diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/ExecutorLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/ExecutorLogic.cs index ae74748..1aa0d82 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/ExecutorLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/ExecutorLogic.cs @@ -119,7 +119,7 @@ namespace LawFirmBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Клиент с такими данными уже есть"); + throw new InvalidOperationException("Исполнитель с такими данными уже есть"); } } } diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/GuarantorLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/GuarantorLogic.cs new file mode 100644 index 0000000..0c31de1 --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/GuarantorLogic.cs @@ -0,0 +1,121 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class GuarantorLogic : IGuarantorLogic + { + private readonly ILogger _logger; + private readonly IGuarantorStorage _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 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 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; + } + + 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("Поручитель с такими данными уже есть"); + } + } + } +} diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/HearingLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/HearingLogic.cs new file mode 100644 index 0000000..1b2ec1c --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/HearingLogic.cs @@ -0,0 +1,139 @@ +using LawFimDataModels.Models; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class HearingLogic : IHearingLogic + { + private readonly ILogger _logger; + private readonly IHearingStorage _hearingStorage; + + public HearingLogic(ILogger logger, IHearingStorage hearingStorage) + { + _logger = logger; + _hearingStorage = hearingStorage; + } + + public bool Create(HearingBindingModel model) + { + CheckModel(model); + if (_hearingStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(HearingBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_hearingStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public HearingViewModel? ReadElement(HearingSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. HearingDate:{HearingDate}. Id:{Id}", model.HearingDate, model.Id); + var element = _hearingStorage.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(HearingSearchModel? model) + { + _logger.LogInformation("ReadList. HearingDate:{HearingDate}.Id:{Id}", model?.HearingDate, model?.Id); + var list = model == null ? _hearingStorage.GetFullList() : _hearingStorage.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(HearingBindingModel model) + { + CheckModel(model); + if (_hearingStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel lawyer) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _hearingStorage.GetElement(model); + + if (element == null) + { + return false; + } + + element.HearingLawyers[lawyer.Id] = lawyer; + + _hearingStorage.Update(new() + { + Id = element.Id, + HearingDate = element.HearingDate, + Judge = element.Judge, + HearingLawyers = element.HearingLawyers, + GuarantorId = element.GuarantorId, + }); + + return true; + } + private void CheckModel(HearingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty((model.HearingDate).ToString())) + { + throw new ArgumentNullException("Не поставлено время", nameof(model.HearingDate)); + } + + _logger.LogInformation("Hearing. HearingDate:{HearingDate}. Id: {Id} ", model.HearingDate, model.Id); + var element = _hearingStorage.GetElement(new HearingSearchModel + { + HearingDate = model.HearingDate + + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("На данное время уже назначено слушание"); + } + } + } +} diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/LawyerLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/LawyerLogic.cs new file mode 100644 index 0000000..2756c68 --- /dev/null +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/LawyerLogic.cs @@ -0,0 +1,153 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class LawyerLogic : ILawyerLogic + { + private readonly ILogger _logger; + private readonly ILawyerStorage _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 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? 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 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)); + } + + _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("Юрист с такими данными уже есть"); + } + } + } +} diff --git a/LawFim/LawFirmContracts/BindingModels/ConsultationBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/ConsultationBindingModel.cs index 23cabab..1d05ba1 100644 --- a/LawFim/LawFirmContracts/BindingModels/ConsultationBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/ConsultationBindingModel.cs @@ -5,7 +5,7 @@ namespace LawFirmContracts.BindingModels public class ConsultationBindingModel : IConsultationModel { public int Id { get; set; } - public string Cost { get; set; } + public double Cost { get; set; } public DateTime ConsultationDate { get; set; } public int CaseId { get; set; } public int GuarantorId { get; set; } diff --git a/LawFim/LawFirmContracts/BindingModels/GuarantorBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/GuarantorBindingModel.cs index 2c0d995..9a9260c 100644 --- a/LawFim/LawFirmContracts/BindingModels/GuarantorBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/GuarantorBindingModel.cs @@ -2,7 +2,7 @@ namespace LawFirmContracts.BindingModels { - public class GuaratorBindingModel : IGuarantorModel + public class GuarantorBindingModel : IGuarantorModel { public int Id { get; set; } public string FIO { get; set; } = string.Empty; diff --git a/LawFim/LawFirmContracts/BusinessLogicContracts/IGuarantorLogic.cs b/LawFim/LawFirmContracts/BusinessLogicContracts/IGuarantorLogic.cs index 0961a2c..79c6389 100644 --- a/LawFim/LawFirmContracts/BusinessLogicContracts/IGuarantorLogic.cs +++ b/LawFim/LawFirmContracts/BusinessLogicContracts/IGuarantorLogic.cs @@ -1,20 +1,15 @@ -using LawFirmContracts.SearchModels; +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; using LawFirmContracts.ViewModels; -using LawFirmContracts.BindingModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LawFirmContracts.BusinessLogicContracts { - public interface IGuarantorLogic + public interface IGuarantorLogic { List? ReadList(GuarantorSearchModel? model); GuarantorViewModel? ReadElement(GuarantorSearchModel model); - bool Create(GuaratorBindingModel model); - bool Update(GuaratorBindingModel model); - bool Delete(GuaratorBindingModel model); + bool Create(GuarantorBindingModel model); + bool Update(GuarantorBindingModel model); + bool Delete(GuarantorBindingModel model); } } diff --git a/LawFim/LawFirmContracts/BusinessLogicContracts/IHearingLogic.cs b/LawFim/LawFirmContracts/BusinessLogicContracts/IHearingLogic.cs index 30926ed..a396f05 100644 --- a/LawFim/LawFirmContracts/BusinessLogicContracts/IHearingLogic.cs +++ b/LawFim/LawFirmContracts/BusinessLogicContracts/IHearingLogic.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using LawFimDataModels.Models; +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; namespace LawFirmContracts.BusinessLogicContracts { diff --git a/LawFim/LawFirmContracts/BusinessLogicContracts/ILawyerLogic.cs b/LawFim/LawFirmContracts/BusinessLogicContracts/ILawyerLogic.cs index 0926563..3b18164 100644 --- a/LawFim/LawFirmContracts/BusinessLogicContracts/ILawyerLogic.cs +++ b/LawFim/LawFirmContracts/BusinessLogicContracts/ILawyerLogic.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; namespace LawFirmContracts.BusinessLogicContracts { diff --git a/LawFim/LawFirmContracts/SearchModels/GuarantorSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/GuarantorSearchModel.cs index 15ab360..5fc6efc 100644 --- a/LawFim/LawFirmContracts/SearchModels/GuarantorSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/GuarantorSearchModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawFirmContracts.SearchModels +namespace LawFirmContracts.SearchModels { public class GuarantorSearchModel { diff --git a/LawFim/LawFirmContracts/SearchModels/HearingSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/HearingSearchModel.cs index 959c762..046d1f3 100644 --- a/LawFim/LawFirmContracts/SearchModels/HearingSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/HearingSearchModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawFirmContracts.SearchModels +namespace LawFirmContracts.SearchModels { public class HearingSearchModel { diff --git a/LawFim/LawFirmContracts/SearchModels/LawyerSearchModel.cs b/LawFim/LawFirmContracts/SearchModels/LawyerSearchModel.cs index 1d3660c..b69fb65 100644 --- a/LawFim/LawFirmContracts/SearchModels/LawyerSearchModel.cs +++ b/LawFim/LawFirmContracts/SearchModels/LawyerSearchModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LawFirmContracts.SearchModels +namespace LawFirmContracts.SearchModels { public class LawyerSearchModel { diff --git a/LawFim/LawFirmContracts/StoragesContracts/IHearingStorage.cs b/LawFim/LawFirmContracts/StoragesContracts/IHearingStorage.cs index bcb855a..6a38e0e 100644 --- a/LawFim/LawFirmContracts/StoragesContracts/IHearingStorage.cs +++ b/LawFim/LawFirmContracts/StoragesContracts/IHearingStorage.cs @@ -4,7 +4,7 @@ using LawFirmContracts.ViewModels; namespace LawFirmContracts.StoragesContracts { - public class IHearingStorage + public interface IHearingStorage { List GetFullList(); List GetFilteredList(HearingSearchModel model); diff --git a/LawFim/LawFirmContracts/StoragesContracts/ILawyerStorage.cs b/LawFim/LawFirmContracts/StoragesContracts/ILawyerStorage.cs index 03021c3..4a62c32 100644 --- a/LawFim/LawFirmContracts/StoragesContracts/ILawyerStorage.cs +++ b/LawFim/LawFirmContracts/StoragesContracts/ILawyerStorage.cs @@ -4,7 +4,7 @@ using LawFirmContracts.ViewModels; namespace LawFirmContracts.StoragesContracts { - public class ILawyerStorage + public interface ILawyerStorage { List GetFullList(); List GetFilteredList(LawyerSearchModel model); diff --git a/LawFim/LawFirmContracts/ViewModels/ConsultationViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ConsultationViewModel.cs index 27aff80..85d3a90 100644 --- a/LawFim/LawFirmContracts/ViewModels/ConsultationViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/ConsultationViewModel.cs @@ -9,7 +9,9 @@ namespace LawFirmContracts.ViewModels public int Id { get; set; } [DisplayName("Цена консультации")] public double Cost { get; set; } - [DisplayName("Дело")] + [DisplayName("Дата консультации")] + public DateTime ConsultationDate { get; set; } + [DisplayName("Дело")] public string CaseName { get; set; } = string.Empty; public int CaseId { get; set; } [DisplayName("Имя поручителя")] diff --git a/LawFim/LawFirmDatabaseImplement/Implements/ConsultationStorage.cs b/LawFim/LawFirmDatabaseImplement/Implements/ConsultationStorage.cs new file mode 100644 index 0000000..94b67f0 --- /dev/null +++ b/LawFim/LawFirmDatabaseImplement/Implements/ConsultationStorage.cs @@ -0,0 +1,111 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace LawFirmDatabaseImplement.Implements +{ + public class ConsultationStorage : IConsultationStorage + { + public List GetFullList() + { + using var context = new LawFirmDatabase(); + return context.Consultations + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ConsultationSearchModel model) + { + if (!model.Id.HasValue && !model.Cost.HasValue && !model.ConsultationDate.HasValue + && !model.CaseId.HasValue && !model.GuarantorId.HasValue) + { + return new(); + } + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Consultations + .Include(x => x.Lawyers).ThenInclude(x => x.Lawyer) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new LawFirmDatabase(); + return context.Consultations + .Include(x => x.Lawyers).ThenInclude(x => x.Lawyer) + .Where(x => x.ConsultationDate >= model.DateFrom && x.ConsultationDate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public ConsultationViewModel? GetElement(ConsultationSearchModel model) + { + if (!model.Id.HasValue && !model.ConsultationDate.HasValue && !model.CaseId.HasValue) + { + return new(); + } + using var context = new LawFirmDatabase(); + return context.Consultations.Include(x => x.Lawyers).ThenInclude(x => x.Lawyer) + .FirstOrDefault(x => (model.CaseId.HasValue && x.Case == model.CaseId) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ConsultationViewModel? Insert(ConsultationBindingModel model) + { + using var context = new LawFirmDatabase(); + var newConsultation = Consultation.Create(context, model); + if (newConsultation == null) + { + return null; + } + context.Consultations.Add(newConsultation); + context.SaveChanges(); + return newConsultation.GetViewModel; + } + public ConsultationViewModel? Update(ConsultationBindingModel model) + { + using var context = new LawFirmDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var consultation = context.Consultations.FirstOrDefault(rec => + rec.Id == model.Id); + if (consultation == null) + { + return null; + } + consultation.Update(model); + context.SaveChanges(); + consultation.UpdateLawyers(context, model); + transaction.Commit(); + return consultation.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ConsultationViewModel? Delete(ConsultationBindingModel model) + { + using var context = new LawFirmDatabase(); + var element = context.Consultations + .Include(x => x.Lawyers) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Consultations.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +}