From ab1c2c3a8841648ce8410f7c1b0ad08edffd295d Mon Sep 17 00:00:00 2001 From: K Date: Fri, 31 May 2024 16:58:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B0=D0=B0=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/LaborCostsLogic.cs | 14 +- .../BindingModels/LaborCostsBindingModel.cs | 3 +- .../SearchModels/LaborCostsSearchModel.cs | 4 +- .../Models/ILaborCostsModel.cs | 2 +- .../Implements/LaborCostsStorage.cs | 18 +- .../Models/Cosmetic.cs | 6 - .../Controllers/OrderController.cs | 215 ++++++------------ .../Controllers/CosmeticController.cs | 199 ++++------------ .../Controllers/LaborCostController.cs | 171 ++++++++++---- .../StorekeeperWebApp.csproj | 7 +- .../Views/LaborCost/CreateLaborCosts.cshtml | 38 ++++ .../Views/LaborCost/LaborCosts.cshtml | 68 ++++++ .../Views/LaborCost/UpdateLaborCosts.cshtml | 29 +++ .../Views/LaborCosts/Create.cshtml | 15 -- .../Views/LaborCosts/Update.cshtml | 16 -- .../Views/Shared/UpdateLaborCosts.cshtml | 29 +++ .../Views/Shared/_Layout.cshtml | 4 +- BeautySalonView/StaffMemberWebApp/libman.json | 5 + 18 files changed, 448 insertions(+), 395 deletions(-) create mode 100644 BeautySalonView/StaffMemberWebApp/Views/LaborCost/CreateLaborCosts.cshtml create mode 100644 BeautySalonView/StaffMemberWebApp/Views/LaborCost/LaborCosts.cshtml create mode 100644 BeautySalonView/StaffMemberWebApp/Views/LaborCost/UpdateLaborCosts.cshtml delete mode 100644 BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Create.cshtml delete mode 100644 BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Update.cshtml create mode 100644 BeautySalonView/StaffMemberWebApp/Views/Shared/UpdateLaborCosts.cshtml create mode 100644 BeautySalonView/StaffMemberWebApp/libman.json diff --git a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/LaborCostsLogic.cs b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/LaborCostsLogic.cs index 3912b17..0da0463 100644 --- a/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/LaborCostsLogic.cs +++ b/BeautySalonView/BeautySalonBusinesLogic/BusinessLogic/LaborCostsLogic.cs @@ -3,6 +3,7 @@ using BeautySalonContracts.BusinessLogicContracts; using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; +using DocumentFormat.OpenXml.Bibliography; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -102,8 +103,19 @@ namespace BeautySalonBusinesLogic.BusinessLogic { throw new ArgumentNullException("Не указана сложность трудозатраты", nameof(model.Difficulty)); } - _logger.LogInformation("LaborCosts. NumberHours: {NumberHours}. Difficulty: {Difficulty}. Id: {Id}", + var element = _laborCostsStorage.GetElement(new LaborCostsSearchModel + { + NumberHours = model.NumberHours, + Difficulty = model.Difficulty, + StorekeeperId = model.StorekeeperId + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такая трудозатрата уже уже есть"); + } + _logger.LogInformation("LaborCosts. NumberHours: {NumberHours}. Difficulty: {Difficulty}. Id: {Id}", model.NumberHours, model.Difficulty, model.Id); + } } } diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/LaborCostsBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/LaborCostsBindingModel.cs index c847549..a17e23e 100644 --- a/BeautySalonView/BeautySalonContracts/BindingModels/LaborCostsBindingModel.cs +++ b/BeautySalonView/BeautySalonContracts/BindingModels/LaborCostsBindingModel.cs @@ -13,6 +13,5 @@ namespace BeautySalonContracts.BindingModels public int NumberHours { get; set; } public string Difficulty { get; set; } = string.Empty; public int StorekeeperId { get; set; } - - } + } } diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/LaborCostsSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/LaborCostsSearchModel.cs index 4b7e1a0..18b171b 100644 --- a/BeautySalonView/BeautySalonContracts/SearchModels/LaborCostsSearchModel.cs +++ b/BeautySalonView/BeautySalonContracts/SearchModels/LaborCostsSearchModel.cs @@ -9,6 +9,8 @@ namespace BeautySalonContracts.SearchModels public class LaborCostsSearchModel { public int? Id { get; set; } - public int? StorekeeperId { get; set; } + public int? NumberHours { get; set; } + public string? Difficulty { get; set; } + public int? StorekeeperId { get; set; } } } diff --git a/BeautySalonView/BeautySalonDataModels/Models/ILaborCostsModel.cs b/BeautySalonView/BeautySalonDataModels/Models/ILaborCostsModel.cs index 2372605..558f3f2 100644 --- a/BeautySalonView/BeautySalonDataModels/Models/ILaborCostsModel.cs +++ b/BeautySalonView/BeautySalonDataModels/Models/ILaborCostsModel.cs @@ -11,5 +11,5 @@ namespace BeautySalonDataModels.Models int NumberHours { get; } string Difficulty { get; } int StorekeeperId { get; } - } + } } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs index 3cd7414..49a0996 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs @@ -35,12 +35,20 @@ namespace BeautySalonDatabaseImplement.Implements { if (!model.Id.HasValue) { - return null; + using var context = new BeautySalonDatabase(); + return context.LaborCosts + .FirstOrDefault(x => x.NumberHours == model.NumberHours + && x.Difficulty == model.Difficulty + && x.StorekeeperId == model.StorekeeperId) + ?.GetViewModel; + } + else + { + using var context = new BeautySalonDatabase(); + return context.LaborCosts + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; } - using var context = new BeautySalonDatabase(); - return context.LaborCosts - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; } public List GetFilteredList(LaborCostsSearchModel model) diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs index a7e8417..8881a56 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs @@ -68,9 +68,6 @@ namespace BeautySalonDatabaseImplement.Models CosmeticPrice = model.CosmeticPrice, StorekeeperId = model.StorekeeperId, LaborCostId = model.LaborCostId, - LaborCost = context.LaborCosts - .First(x => x.Id == model.LaborCostId) - }; return cosmetic; } @@ -80,9 +77,6 @@ namespace BeautySalonDatabaseImplement.Models Brand = model.Brand; CosmeticPrice = model.CosmeticPrice; LaborCostId = model.LaborCostId; - LaborCost = context.LaborCosts - .First(x => x.Id == model.LaborCostId); - } public CosmeticViewModel GetViewModel => new() diff --git a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs index db41dfb..0f0d25b 100644 --- a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs @@ -1,36 +1,46 @@ -using BeautySalonBusinesLogic.BusinessLogic; -using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BindingModels; using BeautySalonContracts.BusinessLogicContracts; using BeautySalonContracts.SearchModels; using BeautySalonContracts.ViewModels; using BeautySalonDatabaseImplement.Models; using BeautySalonDataModels.Models; -using Microsoft.AspNetCore.Http; +using DocumentFormat.OpenXml.Spreadsheet; using Microsoft.AspNetCore.Mvc; - -namespace WorkerWebApp.Controllers +using WorkerWebApp; +/* +namespace BeautySalonRestApi.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] public class OrderController : Controller { - private readonly ILogger _logger; + private readonly ILogger logger; - private readonly IOrderLogic _orderLogic; + private readonly IOrderLogic order; + private readonly ILaborCostsLogic laborCost; + private readonly IProcedureLogic procedure; - private readonly IServiceLogic _serviceLogic; - - /// - /// Бизнес-логика для сущности "Процедура" - /// - private readonly IProcedureLogic _procedureLogic; - - public OrderController(ILogger logger, IOrderLogic orderLogic, IProcedureLogic procedureLogic, IServiceLogic serviceLogic) + public OrderController(ILogger logger, IOrderLogic order, IProcedureLogic procedure, ILaborCostsLogic laborCost) { - _logger = logger; - _orderLogic = orderLogic; - _procedureLogic = procedureLogic; - _serviceLogic = serviceLogic; + this.logger = logger; + this.order = order; + this.procedure = procedure; + this.laborCost = laborCost; + } + + [HttpGet] + public OrderViewModel? GetOrder(int id) + { + try + { + return order.ReadElement(new OrderSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка получения косметики"); + throw; + } } [HttpGet] @@ -41,199 +51,114 @@ namespace WorkerWebApp.Controllers return Redirect("~/Home/Enter"); } - return View(_orderLogic.ReadList(new OrderSearchModel - { - WorkerId = APIWorker.Worker.Id, - })); + return View(order.ReadList(null)); } - /// - /// Получение заказов по id пользователя (полный список, кот. будет выводиться) - /// - /// - /// + [HttpGet] - public IActionResult CreateOrder() + public IActionResult CreateOrders() { if (APIWorker.Worker == null) { return Redirect("~/Home/Enter"); } - ViewBag.Services = _serviceLogic.ReadList(null); + ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel + { + WorkerId = APIWorker.Worker.Id, + }); return View(); } [HttpPost] - public void CreateOrder(double amount, DateTime datacreate, DateTime dateimplement, List services) + public void CreateOrders(string name, string brand, double price, int laborCost) { if (APIWorker.Worker == null) { throw new Exception("Необходимо авторизоваться!"); } - if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null) + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0) { throw new Exception("Введены не все данные!"); } - Dictionary orderServices = new Dictionary(); - foreach (var serviceId in services) + order.Create(new OrderBindingModel { - orderServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!); - } - - _orderLogic.Create(new OrderBindingModel - { - OrderAmount = amount, - DateCreate = datacreate, - DateImplement = dateimplement, - WorkerId = APIWorker.Worker.Id, - OrderServices = orderServices + OrderName = name, + Brand = brand, + OrderPrice = price, + LaborCostId = laborCost, + WorkerId = APIWorker.Worker.Id }); Response.Redirect("/Order/Orders"); } + + [HttpGet] - public IActionResult UpdateOrder(int id) + public IActionResult UpdateOrders(int id) { if (APIWorker.Worker == null) { return Redirect("~/Home/Enter"); } - ViewBag.Services = _serviceLogic.ReadList(null); + ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel + { + WorkerId = APIWorker.Worker.Id, + }); - return View(_orderLogic.ReadElement(new OrderSearchModel + return View(order.ReadElement(new OrderSearchModel { Id = id })); } + [HttpPost] - public void UpdateOrder(int id, double amount, DateTime datacreate, DateTime dateimplement, List services) + public void UpdateOrders(int id, string name, string brand, double price, int laborCost) { if (APIWorker.Worker == null) { throw new Exception("Необходимо авторизоваться!"); } - if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null) + if (string.IsNullOrEmpty(name) || laborCost <= 0) { throw new Exception("Введены не все данные!"); } - Dictionary orderServices = new Dictionary(); - foreach (var serviceId in services) - { - orderServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!); - } - - var order = _orderLogic.ReadElement(new OrderSearchModel { Id = id }); - _orderLogic.Update(new OrderBindingModel + order.Update(new OrderBindingModel { Id = id, - OrderAmount = amount, - DateCreate = datacreate, - DateImplement = dateimplement, - WorkerId = APIWorker.Worker.Id, - OrderProcedures = order!.OrderProcedures, - OrderServices = orderServices + OrderName = name, + Brand = brand, + OrderPrice = price, + LaborCostId = laborCost }); Response.Redirect("/Order/Orders"); } + + /// + /// Удалить косметику + /// + /// [HttpPost] - public void DeleteOrder(int id) + public void DeleteOrders(int id) { if (APIWorker.Worker == null) { throw new Exception("Необходимо авторизоваться!"); } - _orderLogic.Delete(new OrderBindingModel + order.Delete(new OrderBindingModel { Id = id }); Response.Redirect("/Order/Orders"); } - [HttpGet] - public IActionResult CreateOrderProcedure() - { - if (APIWorker.Worker == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - ViewBag.Orders = _orderLogic.ReadList(new OrderSearchModel - { - WorkerId = APIWorker.Worker.Id - }); - ViewBag.Procedures = _procedureLogic.ReadList(new ProcedureSearchModel - { - WorkerId = APIWorker.Worker.Id - }); - - return View(); - } - - [HttpPost] - public void CreatePatientProcedure(int orderId, List procedures) - { - if (APIWorker.Worker == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - if (orderId <= 0 || procedures == null) - { - throw new Exception("Введены не все данные!"); - } - - Dictionary orderProcedures = new Dictionary(); - foreach (var procedureId in procedures) - { - orderProcedures.Add(procedureId, _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId })!); - } - - var order = _orderLogic.ReadElement(new OrderSearchModel { Id = orderId }); - _orderLogic.Update(new OrderBindingModel - { - Id = order!.Id, - OrderAmount = order!.OrderAmount, - DateCreate = order!.DateCreate, - DateImplement = order!.DateImplement, - WorkerId = APIWorker.Worker.Id, - OrderServices = order!.OrderServices, - OrderProcedures = orderProcedures - }); - - Response.Redirect("/Order/Orders"); - } - - [HttpGet] - public JsonResult GetOrderProcedures(int orderId) - { - if (APIWorker.Worker == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - var allProcedures = _procedureLogic.ReadList(new ProcedureSearchModel - { - WorkerId = APIWorker.Worker.Id - }); - - var order = _orderLogic.ReadElement(new OrderSearchModel { Id = orderId }); - var orderProceduresIds = order?.OrderProcedures?.Select(x => x.Key).ToList() ?? new List(); - - var result = new - { - allProcedures = allProcedures.Select(r => new { id = r.Id }), - orderProceduresIds = orderProceduresIds - }; - - return Json(result); - } } } +*/ \ No newline at end of file diff --git a/BeautySalonView/StaffMemberWebApp/Controllers/CosmeticController.cs b/BeautySalonView/StaffMemberWebApp/Controllers/CosmeticController.cs index 52a8ec0..d2c2893 100644 --- a/BeautySalonView/StaffMemberWebApp/Controllers/CosmeticController.cs +++ b/BeautySalonView/StaffMemberWebApp/Controllers/CosmeticController.cs @@ -2,207 +2,94 @@ using BeautySalonContracts.BusinessLogicContracts; using BeautySalonContracts.SearchModels; using BeautySalonContracts.ViewModels; -using BeautySalonDatabaseImplement.Models; -using BeautySalonDataModels.Models; -using DocumentFormat.OpenXml.Spreadsheet; using Microsoft.AspNetCore.Mvc; -using StorekeeperWebApp; namespace BeautySalonRestApi.Controllers { - public class CosmeticController : Controller + public class LaborCostsController : Controller { - private readonly ILogger logger; + private readonly ILogger _logger; - private readonly ICosmeticLogic cosmetic; - private readonly ILaborCostsLogic laborCost; - private readonly IProcedureLogic procedure; + private readonly ILaborCostsLogic _logic; - public CosmeticController(ILogger logger, ICosmeticLogic cosmetic, IProcedureLogic procedure, ILaborCostsLogic laborCost) + public LaborCostsController(ILaborCostsLogic logic, ILogger logger) { - this.logger = logger; - this.cosmetic = cosmetic; - this.procedure = procedure; - this.laborCost = laborCost; + _logger = logger; + _logic = logic; } + [HttpGet] - public CosmeticViewModel? GetCosmetic(int id) + public LaborCostsViewModel? GetLaborCosts(int id) { try { - return cosmetic.ReadElement(new CosmeticSearchModel + return _logic.ReadElement(new LaborCostsSearchModel { Id = id }); } catch (Exception ex) { - logger.LogError(ex, "Ошибка получения косметики"); + _logger.LogError(ex, "Ошибка получения трудозатраты"); throw; } } [HttpGet] - public IActionResult Cosmetics() + public List? GetAllLaborCosts() { - if (APIStorekeeper.Storekeeper == null) + try { - return Redirect("~/Home/Enter"); + return _logic.ReadList(null); } - - return View(cosmetic.ReadList(null)); - } - - /*[HttpGet] - public IActionResult CreateCosmetics() - { - if (APIStorekeeper.Storekeeper == null) + catch (Exception ex) { - return Redirect("~/Home/Enter"); + _logger.LogError(ex, "Ошибка получения списка трудозатрат"); + throw; } - - ViewBag.Procedures = procedure.ReadList(null); - - return View(); - } - [HttpPost] - public void CreateCosmetics(CosmeticBindingModel model, int[] procedureIds) - { - if (APIStorekeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - var procedures = procedure.ReadList(null); - if (model.Id == 0) - { - model.StorekeeperId = APIStorekeeper.Storekeeper.Id; - for (int i = 0; i < procedureIds.Length; i++) - { - var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!; - model.CosmeticProcedures.Add(i, procedure); - } - if (cosmetic.Create(model)) - Response.Redirect("/Cosmetic/Cosmetics"); - } - else - { - for (int i = 0; i < procedureIds.Length; i++) - { - var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!; - model.CosmeticProcedures.Add(i, procedure); - } - model.StorekeeperId = APIStorekeeper.Storekeeper.Id; - if (cosmetic.Create(model)) - Response.Redirect("/Cosmetic/Cosmetics"); - } - }*/ - - [HttpGet] - public IActionResult CreateCosmetics() - { - if (APIStorekeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel - { - StorekeeperId = APIStorekeeper.Storekeeper.Id, - }); - - return View(); - } - - [HttpPost] - public void CreateCosmetics(string name, string brand, double price, int laborCost) - { - if (APIStorekeeper.Storekeeper == null) - { - throw new Exception("Необходимо авторизоваться!"); - } - - if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0) - { - throw new Exception("Введены не все данные!"); - } - - cosmetic.Create(new CosmeticBindingModel - { - CosmeticName = name, - Brand = brand, - CosmeticPrice = price, - LaborCostId = laborCost, - StorekeeperId = APIStorekeeper.Storekeeper.Id - }); - - Response.Redirect("/Cosmetic/Cosmetics"); - } - - - [HttpGet] - public IActionResult UpdateCosmetics(int id) - { - if (APIStorekeeper.Storekeeper == null) - { - return Redirect("~/Home/Enter"); - } - - ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel - { - StorekeeperId = APIStorekeeper.Storekeeper.Id, - }); - - return View(cosmetic.ReadElement(new CosmeticSearchModel - { - Id = id - })); } [HttpPost] - public void UpdateCosmetics(int id, string name, string brand, double price, int laborCost) + public void CreateLaborCosts(LaborCostsBindingModel model) { - if (APIStorekeeper.Storekeeper == null) + try { - throw new Exception("Необходимо авторизоваться!"); + _logic.Create(model); } - - if (string.IsNullOrEmpty(name) || laborCost <= 0) + catch (Exception ex) { - throw new Exception("Введены не все данные!"); + _logger.LogError(ex, "Ошибка создания трудозатраты"); + throw; } - - cosmetic.Update(new CosmeticBindingModel - { - Id = id, - CosmeticName = name, - Brand = brand, - CosmeticPrice = price, - LaborCostId = laborCost - }); - - Response.Redirect("/Cosmetic/Cosmetics"); } - /// - /// Удалить косметику - /// - /// - [HttpPost] - public void DeleteCosmetics(int id) + [HttpPost] + public void UpdateLaborCosts(LaborCostsBindingModel model) { - if (APIStorekeeper.Storekeeper == null) + try { - throw new Exception("Необходимо авторизоваться!"); + _logic.Update(model); } - - cosmetic.Delete(new CosmeticBindingModel + catch (Exception ex) { - Id = id - }); + _logger.LogError(ex, "Ошибка обновления трудозатраты"); + throw; + } + } - Response.Redirect("/Cosmetic/Cosmetics"); + [HttpDelete] + public void DeleteLaborCosts(LaborCostsBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления трудозатраты"); + throw; + } } } } diff --git a/BeautySalonView/StaffMemberWebApp/Controllers/LaborCostController.cs b/BeautySalonView/StaffMemberWebApp/Controllers/LaborCostController.cs index d2c2893..a752a1b 100644 --- a/BeautySalonView/StaffMemberWebApp/Controllers/LaborCostController.cs +++ b/BeautySalonView/StaffMemberWebApp/Controllers/LaborCostController.cs @@ -2,94 +2,179 @@ using BeautySalonContracts.BusinessLogicContracts; using BeautySalonContracts.SearchModels; using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using BeautySalonDataModels.Models; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Mvc; +using StorekeeperWebApp; namespace BeautySalonRestApi.Controllers { - public class LaborCostsController : Controller + public class LaborCostController : Controller { - private readonly ILogger _logger; + private readonly ILogger logger; - private readonly ILaborCostsLogic _logic; + private readonly ILaborCostsLogic laborCost; + private readonly ICosmeticLogic cosmetic; - public LaborCostsController(ILaborCostsLogic logic, ILogger logger) + public LaborCostController(ILogger logger, ILaborCostsLogic laborCost, ICosmeticLogic cosmetic) { - _logger = logger; - _logic = logic; + this.logger = logger; + this.laborCost = laborCost; + this.cosmetic = cosmetic; } - [HttpGet] - public LaborCostsViewModel? GetLaborCosts(int id) + public LaborCostsViewModel? GetLaborCost(int id) { try { - return _logic.ReadElement(new LaborCostsSearchModel + return laborCost.ReadElement(new LaborCostsSearchModel { Id = id }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения трудозатраты"); + logger.LogError(ex, "Ошибка получения трудозатраты"); throw; } } [HttpGet] - public List? GetAllLaborCosts() + public IActionResult LaborCosts() { - try + if (APIStorekeeper.Storekeeper == null) { - return _logic.ReadList(null); + return Redirect("~/Home/Enter"); } - catch (Exception ex) + + return View(laborCost.ReadList(null)); + } + + [HttpGet] + public IActionResult CreateLaborCosts() + { + if (APIStorekeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel + { + StorekeeperId = APIStorekeeper.Storekeeper.Id, + }); + + return View(); + } + + [HttpPost] + public void CreateLaborCosts(int hours, string difficulty, int cosmeticId) + { + if (APIStorekeeper.Storekeeper == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (hours <= 0 || string.IsNullOrEmpty(difficulty) || cosmeticId <= 0) + { + throw new Exception("Введены не все данные!"); + } + + laborCost.Create(new LaborCostsBindingModel + { + NumberHours = hours, + Difficulty = difficulty, + StorekeeperId = APIStorekeeper.Storekeeper.Id + }); + + var labor = laborCost.ReadElement(new LaborCostsSearchModel { + NumberHours = hours, + Difficulty = difficulty, + StorekeeperId = APIStorekeeper.Storekeeper.Id + }); + + var cosm = cosmetic.ReadElement(new CosmeticSearchModel{ Id = cosmeticId }); + if (cosm != null && labor != null) { - _logger.LogError(ex, "Ошибка получения списка трудозатрат"); - throw; + cosm.LaborCostId = labor.Id; // Присваиваем айди трудозатраты к объекту косметики + cosmetic.Update(new CosmeticBindingModel + { + Id = cosm.Id, + CosmeticName = cosm.CosmeticName, + Brand = cosm.Brand, + CosmeticPrice = cosm.CosmeticPrice, + LaborCostId = cosm.LaborCostId + }); } + + Response.Redirect("/LaborCost/LaborCosts"); + } + + + [HttpGet] + public IActionResult UpdateLaborCosts(int id) + { + if (APIStorekeeper.Storekeeper == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel + { + StorekeeperId = APIStorekeeper.Storekeeper.Id, + }); + + return View(laborCost.ReadElement(new LaborCostsSearchModel + { + Id = id + })); } [HttpPost] - public void CreateLaborCosts(LaborCostsBindingModel model) + public void UpdateLaborCosts(int hours, string difficulty) { - try + if (APIStorekeeper.Storekeeper == null) { - _logic.Create(model); + throw new Exception("Необходимо авторизоваться!"); } - catch (Exception ex) + + if (string.IsNullOrEmpty(difficulty) || hours <= 0) { - _logger.LogError(ex, "Ошибка создания трудозатраты"); - throw; + throw new Exception("Введены не все данные!"); } + + laborCost.Update(new LaborCostsBindingModel + { + NumberHours = hours, + Difficulty = difficulty, + StorekeeperId = APIStorekeeper.Storekeeper.Id + }); + + Response.Redirect("/LaborCost/LaborCosts"); } - [HttpPost] - public void UpdateLaborCosts(LaborCostsBindingModel model) + /// + /// Удалить косметику + /// + /// + [HttpPost] + public void DeleteLaborCosts(int id) { - try + if (APIStorekeeper.Storekeeper == null) { - _logic.Update(model); + throw new Exception("Необходимо авторизоваться!"); } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления трудозатраты"); - throw; - } - } - [HttpDelete] - public void DeleteLaborCosts(LaborCostsBindingModel model) - { - try + laborCost.Delete(new LaborCostsBindingModel { - _logic.Delete(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления трудозатраты"); - throw; - } + Id = id + }); + + Response.Redirect("/LaborCost/LaborCosts"); } } } diff --git a/BeautySalonView/StaffMemberWebApp/StorekeeperWebApp.csproj b/BeautySalonView/StaffMemberWebApp/StorekeeperWebApp.csproj index fc00769..8202a2a 100644 --- a/BeautySalonView/StaffMemberWebApp/StorekeeperWebApp.csproj +++ b/BeautySalonView/StaffMemberWebApp/StorekeeperWebApp.csproj @@ -6,6 +6,10 @@ enable + + + + @@ -26,12 +30,11 @@ - - + diff --git a/BeautySalonView/StaffMemberWebApp/Views/LaborCost/CreateLaborCosts.cshtml b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/CreateLaborCosts.cshtml new file mode 100644 index 0000000..6727c32 --- /dev/null +++ b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/CreateLaborCosts.cshtml @@ -0,0 +1,38 @@ +@{ + ViewData["Title"] = "Создание трудозатраты"; +} + +
+

Создание трудозатраты

+
+ +
+
+
Количество часов:
+
+
+ +
+
Сложность:
+
+
+ +
+
Косметика:
+
+ +
+
+ + +
+
+
+
+
+ diff --git a/BeautySalonView/StaffMemberWebApp/Views/LaborCost/LaborCosts.cshtml b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/LaborCosts.cshtml new file mode 100644 index 0000000..6c2c742 --- /dev/null +++ b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/LaborCosts.cshtml @@ -0,0 +1,68 @@ +@using BeautySalonContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Трудозатраты"; +} + +
+

Трудозатраты

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать Трудозатрату +

+ + + + + + + + + + + + + + @foreach (var laborCosts in Model) + { + + + + + + + + } + +
НомерКоличество часовСложность
@laborCosts.Id@laborCosts.NumberHours@laborCosts.Difficulty +

+
+

+
+ } +
+ +@section scripts { + +} + + diff --git a/BeautySalonView/StaffMemberWebApp/Views/LaborCost/UpdateLaborCosts.cshtml b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/UpdateLaborCosts.cshtml new file mode 100644 index 0000000..dd896f3 --- /dev/null +++ b/BeautySalonView/StaffMemberWebApp/Views/LaborCost/UpdateLaborCosts.cshtml @@ -0,0 +1,29 @@ +@using BeautySalonContracts.ViewModels + +@model LaborCostsViewModel + +@{ + ViewData["Title"] = "Редактирование трудозатраты"; +} + +
+

Редактирование трудозатраты

+
+ +
+
+
Количество часов:
+
+
+ +
+
Сложность:
+
+
+ + +
+
+
+
+
diff --git a/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Create.cshtml b/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Create.cshtml deleted file mode 100644 index 94c11ae..0000000 --- a/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Create.cshtml +++ /dev/null @@ -1,15 +0,0 @@ -@{ - ViewData["Title"] = "Трудозатраты"; -} - -

Создать трудозатрату

- -
-

Количество часов:

- -

Количество специалистов:

- - -
diff --git a/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Update.cshtml b/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Update.cshtml deleted file mode 100644 index 1881fb4..0000000 --- a/BeautySalonView/StaffMemberWebApp/Views/LaborCosts/Update.cshtml +++ /dev/null @@ -1,16 +0,0 @@ -@{ - ViewData["Title"] = "Трудозатраты"; -} - -

Обновить трудозатраты

- -
- -

Количество часов:

- -

Количество специалистов:

- - -
diff --git a/BeautySalonView/StaffMemberWebApp/Views/Shared/UpdateLaborCosts.cshtml b/BeautySalonView/StaffMemberWebApp/Views/Shared/UpdateLaborCosts.cshtml new file mode 100644 index 0000000..dd896f3 --- /dev/null +++ b/BeautySalonView/StaffMemberWebApp/Views/Shared/UpdateLaborCosts.cshtml @@ -0,0 +1,29 @@ +@using BeautySalonContracts.ViewModels + +@model LaborCostsViewModel + +@{ + ViewData["Title"] = "Редактирование трудозатраты"; +} + +
+

Редактирование трудозатраты

+
+ +
+
+
Количество часов:
+
+
+ +
+
Сложность:
+
+
+ + +
+
+
+
+
diff --git a/BeautySalonView/StaffMemberWebApp/Views/Shared/_Layout.cshtml b/BeautySalonView/StaffMemberWebApp/Views/Shared/_Layout.cshtml index 90219ce..40746ea 100644 --- a/BeautySalonView/StaffMemberWebApp/Views/Shared/_Layout.cshtml +++ b/BeautySalonView/StaffMemberWebApp/Views/Shared/_Layout.cshtml @@ -32,13 +32,13 @@ Авторизация