From 7611610ba238c7b2d7633252d5f04ea95686c1bd Mon Sep 17 00:00:00 2001 From: K Date: Tue, 30 Apr 2024 19:39:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B2=20=D1=80=D0=B5=D1=81=D1=82=D0=B0=D0=BF=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CosmeticController.cs | 124 +++++++++------- .../Controllers/LaborCostController.cs | 140 +++++++++++------- .../Controllers/ServiceController.cs | 138 ++++++++++------- .../Controllers/StaffMemberController.cs | 88 ++++------- 4 files changed, 281 insertions(+), 209 deletions(-) diff --git a/BeautySalonView/BeatySalonRestApi/Controllers/CosmeticController.cs b/BeautySalonView/BeatySalonRestApi/Controllers/CosmeticController.cs index b87a0d5..9e70287 100644 --- a/BeautySalonView/BeatySalonRestApi/Controllers/CosmeticController.cs +++ b/BeautySalonView/BeatySalonRestApi/Controllers/CosmeticController.cs @@ -1,82 +1,106 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; using Microsoft.AspNetCore.Mvc; -namespace BeatySalonRestApi.Controllers +namespace BeautySalonRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class CosmeticController : Controller { - // GET: CosmeticController - public ActionResult Index() + private readonly ILogger logger; + + private readonly ICosmeticLogic cosmetic; + + public CosmeticController(ILogger logger, ICosmeticLogic cosmetic) { - return View(); + this.logger = logger; + this.cosmetic = cosmetic; } - // GET: CosmeticController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: CosmeticController/Create - public ActionResult Create() - { - return View(); - } - - // POST: CosmeticController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + [HttpGet] + public CosmeticViewModel? Get(int id) { try { - return RedirectToAction(nameof(Index)); + return cosmetic.ReadElement(new CosmeticSearchModel { Id = id }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения косметики с id = {Id}", id); + throw; } } - // GET: CosmeticController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: CosmeticController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + [HttpGet] + public List? GetAll() { try { - return RedirectToAction(nameof(Index)); + return cosmetic.ReadList(null); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка косметики"); + throw; } } - // GET: CosmeticController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: CosmeticController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + [HttpGet] + public List? GetMany(int userId, int page) { try { - return RedirectToAction(nameof(Index)); + return cosmetic.ReadList(new CosmeticSearchModel { LaborCostId = userId }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка косметики клиента id = {Id}", userId); + throw; + } + } + + [HttpPost] + public void Create(CosmeticBindingModel model) + { + try + { + cosmetic.Create(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка создания косметики"); + throw; + } + } + + [HttpPost] + public void Update(CosmeticBindingModel model) + { + try + { + cosmetic.Update(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка обновления косметики"); + throw; + } + } + + [HttpPost] + public void Delete(CosmeticBindingModel model) + { + try + { + cosmetic.Delete(new() { Id = model.Id }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка удаления косметики"); + throw; } } } diff --git a/BeautySalonView/BeatySalonRestApi/Controllers/LaborCostController.cs b/BeautySalonView/BeatySalonRestApi/Controllers/LaborCostController.cs index 8b3d536..a6ac077 100644 --- a/BeautySalonView/BeatySalonRestApi/Controllers/LaborCostController.cs +++ b/BeautySalonView/BeatySalonRestApi/Controllers/LaborCostController.cs @@ -1,82 +1,120 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; using Microsoft.AspNetCore.Mvc; -namespace BeatySalonRestApi.Controllers +namespace BeautySalonRestApi.Controllers { - public class LaborCostController : Controller + [Route("api/[controller]/[action]")] + [ApiController] + public class LaborCostsController : Controller { - // GET: LaborCost - public ActionResult Index() + private readonly ILogger logger; + + private readonly ILaborCostsLogic laborCosts; + + public LaborCostsController(ILogger logger, ILaborCostsLogic laborCosts) { - return View(); + this.logger = logger; + this.laborCosts = laborCosts; } - // GET: LaborCost/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: LaborCost/Create - public ActionResult Create() - { - return View(); - } - - // POST: LaborCost/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + [HttpGet] + public LaborCostsViewModel? Get(int id) { try { - return RedirectToAction(nameof(Index)); + return laborCosts.ReadElement(new LaborCostsSearchModel { Id = id }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения трудозатраты с id = {Id}", id); + throw; } } - // GET: LaborCost/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: LaborCost/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + [HttpGet] + public List? GetAll() { try { - return RedirectToAction(nameof(Index)); + return laborCosts.ReadList(null); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка трудозатрат"); + throw; } } - // GET: LaborCost/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: LaborCost/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + [HttpGet] + public List? GetAllByUser(int userId) { try { - return RedirectToAction(nameof(Index)); + return laborCosts.ReadList(new LaborCostsSearchModel { StaffMemberId = userId }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка трудозатрат пользователя"); + throw; + } + } + + [HttpGet] + public List? GetMany(int userId, int page) + { + try + { + return laborCosts.ReadList(new LaborCostsSearchModel { StaffMemberId = userId }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка получения списка трудозатрат клиента id = {Id}", userId); + throw; + } + } + + [HttpPost] + public void Create(LaborCostsBindingModel model) + { + try + { + laborCosts.Create(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка создания трудозатраты"); + throw; + } + } + + [HttpPost] + public void Update(LaborCostsBindingModel model) + { + try + { + laborCosts.Update(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка обновления трудозатраты"); + throw; + } + } + + [HttpPost] + public void Delete(LaborCostsBindingModel model) + { + try + { + laborCosts.Delete(new() { Id = model.Id }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка удаления трудозатраты"); + throw; } } } diff --git a/BeautySalonView/BeatySalonRestApi/Controllers/ServiceController.cs b/BeautySalonView/BeatySalonRestApi/Controllers/ServiceController.cs index cfcf557..5814c94 100644 --- a/BeautySalonView/BeatySalonRestApi/Controllers/ServiceController.cs +++ b/BeautySalonView/BeatySalonRestApi/Controllers/ServiceController.cs @@ -1,82 +1,120 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; using Microsoft.AspNetCore.Mvc; -namespace BeatySalonRestApi.Controllers +namespace BeautySalonRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class ServiceController : Controller { - // GET: ServiceController - public ActionResult Index() + private readonly ILogger logger; + + private readonly IServiceLogic service; + + public ServiceController(ILogger logger, IServiceLogic service) { - return View(); + this.logger = logger; + this.service = service; } - // GET: ServiceController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: ServiceController/Create - public ActionResult Create() - { - return View(); - } - - // POST: ServiceController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + [HttpGet] + public ServiceViewModel? Get(int id) { try { - return RedirectToAction(nameof(Index)); + return service.ReadElement(new ServiceSearchModel { Id = id }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения услуги с id = {Id}", id); + throw; } } - // GET: ServiceController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: ServiceController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + [HttpGet] + public List? GetAll() { try { - return RedirectToAction(nameof(Index)); + return service.ReadList(null); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка услуг"); + throw; } } - // GET: ServiceController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: ServiceController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) + [HttpGet] + public List? GetAllByUser(int userId) { try { - return RedirectToAction(nameof(Index)); + return service.ReadList(new ServiceSearchModel { StaffMemberId = userId }); } - catch + catch (Exception ex) { - return View(); + logger.LogError(ex, "Ошибка получения списка услуг пользователя"); + throw; + } + } + + [HttpGet] + public List? GetMany(int userId, int page) + { + try + { + return service.ReadList(new ServiceSearchModel { StaffMemberId = userId }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка получения списка услуг клиента id = {Id}", userId); + throw; + } + } + + [HttpPost] + public void Create(ServiceBindingModel model) + { + try + { + service.Create(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка создания услуги"); + throw; + } + } + + [HttpPost] + public void Update(ServiceBindingModel model) + { + try + { + service.Update(model); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка обновления услуги"); + throw; + } + } + + [HttpPost] + public void Delete(ServiceBindingModel model) + { + try + { + service.Delete(new() { Id = model.Id }); + } + catch (Exception ex) + { + logger.LogError(ex, "Ошибка удаления услуги"); + throw; } } } diff --git a/BeautySalonView/BeatySalonRestApi/Controllers/StaffMemberController.cs b/BeautySalonView/BeatySalonRestApi/Controllers/StaffMemberController.cs index dffadb9..2a64c98 100644 --- a/BeautySalonView/BeatySalonRestApi/Controllers/StaffMemberController.cs +++ b/BeautySalonView/BeatySalonRestApi/Controllers/StaffMemberController.cs @@ -1,83 +1,55 @@ -using Microsoft.AspNetCore.Http; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; using Microsoft.AspNetCore.Mvc; -namespace BeatySalonRestApi.Controllers +namespace BeautySalonRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class StaffMemberController : Controller { - // GET: StaffMemberController - public ActionResult Index() + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IStaffMemberLogic _logic; + public StaffMemberController(IOrderLogic order, IStaffMemberLogic logic, ILogger logger) { - return View(); + _logger = logger; + _order = order; + _logic = logic; } - // GET: StaffMemberController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: StaffMemberController/Create - public ActionResult Create() - { - return View(); - } - - // POST: StaffMemberController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) + [HttpGet] + public StaffMemberViewModel? Login(string login, string password) { try { - return RedirectToAction(nameof(Index)); + return _logic.ReadElement(new StaffMemberSearchModel + { + StaffMemberLogin = login, + StaffMemberPassword = password + }); } - catch + catch (Exception ex) { - return View(); + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; } } - // GET: StaffMemberController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: StaffMemberController/Edit/5 [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) + public void Register(StaffMemberBindingModel model) { try { - return RedirectToAction(nameof(Index)); + _logic.Create(model); } - catch + catch (Exception ex) { - return View(); - } - } - - // GET: StaffMemberController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: StaffMemberController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); + _logger.LogError(ex, "Ошибка регистрации"); + throw; } } } -} +} \ No newline at end of file