From 60f030dbd8a9694c933a20c0d9e65b7f92a31616 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Sat, 4 May 2024 20:00:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=82=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 17 ++- .../BindingModels/ImplementerBindingModel.cs | 22 ++++ .../IImplementerLogic.cs | 24 ++++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../SearchModels/ImplementerSearchModel.cs | 17 +++ .../SearchModels/OrderSearchModel.cs | 5 +- .../ViewModels/ImplementerViewModel.cs | 27 +++++ .../Models/IImplementerModel.cs | 16 +++ .../Controllers/ImplementerController.cs | 103 ++++++++++++++++++ 9 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ImplementerViewModel.cs create mode 100644 LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IImplementerModel.cs create mode 100644 LawFirm/AbstractLawFirmRestApi/Controllers/ImplementerController.cs diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs index cf6376c..1c48723 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs @@ -37,7 +37,22 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.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 CreateOrder(OrderBindingModel model) { CheckModel(model); diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ImplementerBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..96b437b --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IImplementerLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..bec8834 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs index ab78985..7998d50 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace AbstractLawFirmContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ImplementerSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..f84633f --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs index d78a23c..ef1ce1e 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using AbstractLawFirmDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace AbstractLawFirmContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ImplementerViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..fea571d --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Трудовой стаж")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IImplementerModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..7bf3768 --- /dev/null +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/LawFirm/AbstractLawFirmRestApi/Controllers/ImplementerController.cs b/LawFirm/AbstractLawFirmRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..b0291fa --- /dev/null +++ b/LawFirm/AbstractLawFirmRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Enums; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; + +namespace AbstractLawFirmRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id} ", model.Id); + throw; + } + } + } +}