diff --git a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs index b3b8c23..f94c9f5 100644 --- a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs @@ -4,6 +4,9 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.ViewModels; using WorkerWebApp.Controllers; using Microsoft.AspNetCore.Mvc; +using BeautySalonDatabaseImplement.Models; +using Microsoft.Extensions.Logging; +using System; namespace WorkerWebApp.Controllers { @@ -11,104 +14,136 @@ namespace WorkerWebApp.Controllers [ApiController] public class ProcedureController : Controller { - private readonly ILogger _logger; + private readonly ILogger logger; - private readonly IProcedureLogic _logic; + private readonly ICosmeticLogic cosmetic; + private readonly IProcedureLogic procedure; - public ProcedureController(IProcedureLogic logic, ILogger logger) + public ProcedureController(ILogger logger, ICosmeticLogic cosmetic, IProcedureLogic procedure) { - _logger = logger; - _logic = logic; + this.logger = logger; + this.cosmetic = cosmetic; + this.procedure = procedure; } - [HttpGet] - public ProcedureViewModel? GetProcedure(int id) + public ProcedureViewModel GetProcedure(int id) { try { - return _logic.ReadElement(new ProcedureSearchModel + return procedure.ReadElement(new ProcedureSearchModel { Id = id }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения процедуры"); + logger.LogError(ex, "Ошибка получения процедуры"); throw; } } [HttpGet] - public List? GetAllProcedures() + public IActionResult Procedures() { - try + if (APIWorker.Worker == null) { - return _logic.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка процедур"); - throw; + return Redirect("~/Home/Enter"); } + + return View(cosmetic.ReadList(null)); } [HttpGet] - public List? GetProcedures(int workerId) + public IActionResult CreateProcedures() { - try + if (APIWorker.Worker == null) { - return _logic.ReadList(new ProcedureSearchModel { WorkerId = workerId }); + return Redirect("~/Home/Enter"); } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка процедур сотрудника id={Id}", workerId); - throw; - } - } + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel()); - [HttpPost] - public void CreateProcedure(ProcedureBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания процедуры"); - throw; - } + return View(); } [HttpPost] - public void UpdateProcedure(ProcedureBindingModel model) + public IActionResult CreateProcedures(string name, double price, double duration) { - try + if (APIWorker.Worker == null) { - _logic.Update(model); + throw new Exception("Необходимо авторизоваться!"); } - catch (Exception ex) + + if (string.IsNullOrEmpty(name) || price <= 0) { - _logger.LogError(ex, "Ошибка обновления процедуры"); - throw; + throw new Exception("Введены не все данные!"); } + + procedure.Create(new ProcedureBindingModel + { + ProcedureName = name, + ProcedurePrice = price, + ProcedureDuration = duration + }); + + return RedirectToAction("Procedures"); } - [HttpDelete] - public void DeleteProcedure(ProcedureBindingModel model) + [HttpGet] + public IActionResult UpdateProcedures(int id) { - try + if (APIWorker.Worker == null) { - _logic.Delete(model); + return Redirect("~/Home/Enter"); } - catch (Exception ex) + + ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel()); + + return View(procedure.ReadElement(new ProcedureSearchModel { - _logger.LogError(ex, "Ошибка удаления процедуры"); - throw; - } + Id = id + })); } + [HttpPost] + public IActionResult UpdateProcedures(int id, string name, double price, double duration) + { + if (APIWorker.Worker == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || price <= 0) + { + throw new Exception("Введены не все данные!"); + } + + procedure.Update(new ProcedureBindingModel + { + Id = id, + ProcedureName = name, + ProcedurePrice = price, + ProcedureDuration = duration + }); + + return RedirectToAction("Procedures"); + } + + [HttpPost] + public IActionResult DeleteProcedure(int id) + { + if (APIWorker.Worker == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + procedure.Delete(new ProcedureBindingModel + { + Id = id + }); + + return RedirectToAction("Procedures"); + } } -} +} \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Views/Home/Procedure.cshtml b/BeautySalonView/ClientWebApp/Views/Home/Procedure.cshtml index 29d8192..ac85a2f 100644 --- a/BeautySalonView/ClientWebApp/Views/Home/Procedure.cshtml +++ b/BeautySalonView/ClientWebApp/Views/Home/Procedure.cshtml @@ -8,13 +8,13 @@
@@ -23,7 +23,7 @@ / @ViewBag.NumberOfPages
- + Перейти @@ -32,8 +32,9 @@ - - + + + @@ -42,10 +43,11 @@ + }
Наименование процедурыЦена процедурыНазвание процедурыСтоимостьДлительность
@item.ProcedureName @item.ProcedurePrice@item.ProcedureDuration
- + \ No newline at end of file