From f80e7e1f8c295f7507fcc05e6371a0ab675ed3a0 Mon Sep 17 00:00:00 2001 From: frog24 Date: Sun, 28 Apr 2024 21:33:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=82=D0=B5=D0=BD=D1=86=D0=B8?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=87=D0=B8=D0=BB=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20(=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D1=88=D0=B5=20=D0=BF=D1=80=D0=B2=D0=B5=D1=80=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D1=87=D1=82=D0=BE=20=D1=8F=20=D0=B2=D0=BE=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/DoctorVisitLogic.cs | 130 ++++++++++++++++++ .../BusinessLogics/DrugPurchaseLogic.cs | 2 +- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Vetclinic/VetclinicBusinessLogic/BusinessLogics/DoctorVisitLogic.cs diff --git a/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DoctorVisitLogic.cs b/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DoctorVisitLogic.cs new file mode 100644 index 0000000..6a70dcb --- /dev/null +++ b/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DoctorVisitLogic.cs @@ -0,0 +1,130 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetclinicContracts.BindingModels; +using VetclinicContracts.BusinessLogicsContracts; +using VetclinicContracts.SearchModels; +using VetclinicContracts.StoragesContracts; +using VetclinicContracts.ViewModels; +using VetclinicDataModels.Enums; + +namespace VetclinicBusinessLogic.BusinessLogics +{ + public class DoctorVisitLogic: IDoctorVisitLogic + { + private readonly ILogger _logger; + private readonly IDoctorVisitStorage _doctorVisitStorage; + public DoctorVisitLogic(ILogger logger, IDoctorVisitStorage doctorVisitStorage) + { + _logger = logger; + _doctorVisitStorage = doctorVisitStorage; + } + public List? ReadList(DoctorVisitSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _doctorVisitStorage.GetFullList() : _doctorVisitStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DoctorVisitViewModel? ReadElement(DoctorVisitSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + + var element = _doctorVisitStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + public bool CreateDoctorVisit(DoctorVisitBindingModel model) + { + CheckModel(model); + if (model.Status != DoctorVisitStatus.Неизвестен) + { + _logger.LogWarning("Wrong DoctorVisit status. Insert operation failed"); + return false; + } + model.Status = DoctorVisitStatus.Забронировано; + if (_doctorVisitStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool ChangeStatus(DoctorVisitBindingModel model, DoctorVisitStatus status) + { + CheckModel(model, false); + var element = _doctorVisitStorage.GetElement(new DoctorVisitSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + DoctorVisitStatus oldStatus = model.Status; + model.Status = status; + /* РАЗ УЖ НЕТ ДАТЫ ОКОНЧАНИЯ ТО ЭТО НЕ НАДО? + if (model.Status == DoctorVisitStatus.Закончен) + { + model.DateImplement = DateTime.Now; + } + */ + if (_doctorVisitStorage.Update(model) == null) + { + model.Status = oldStatus; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool BeginDoctorVisit(DoctorVisitBindingModel model) + { + return ChangeStatus(model, DoctorVisitStatus.Выполняется); + } + public bool FinishDoctorVisit(DoctorVisitBindingModel model) + { + return ChangeStatus(model, DoctorVisitStatus.Закончен); + } + private void CheckModel(DoctorVisitBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.DateVisit != null) + { + throw new ArithmeticException("Дата завершения не может быть раньше даты начала"); + } + _logger.LogInformation("DoctorVisit. Id:{Id}. DateVisit:{DateVisit}. ServiceId:{ServiceId}. AnimalId:{AnimalId}", + model.Id, model.DateVisit, model.ServiceId, model.AnimalId); + } + } +} diff --git a/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DrugPurchaseLogic.cs b/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DrugPurchaseLogic.cs index 8a9a7aa..f764264 100644 --- a/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DrugPurchaseLogic.cs +++ b/Vetclinic/VetclinicBusinessLogic/BusinessLogics/DrugPurchaseLogic.cs @@ -133,7 +133,7 @@ namespace VetclinicBusinessLogic.BusinessLogics { throw new ArithmeticException("Дата завершения не может быть раньше даты начала"); } - _logger.LogInformation("DrugPurchase. Id:{Id}. Sum:{Sum}. AnimalId:{AnimalId}", model.Id, model.Sum, model.AnimalId); + _logger.LogInformation("DrugPurchase. Id:{Id}. Cost:{Cost}. DrugId:{DrugId}. AnimalId:{DrugId}", model.Id, model.Cost, model.DrugId, model.AnimalId); } } }