diff --git a/BeautySalonView/ClientWebApp/Controllers/EvaluationController.cs b/BeautySalonView/ClientWebApp/Controllers/EvaluationController.cs index 5d359aa..28e20da 100644 --- a/BeautySalonView/ClientWebApp/Controllers/EvaluationController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/EvaluationController.cs @@ -6,92 +6,112 @@ using Microsoft.AspNetCore.Mvc; namespace WorkerWebApp.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] + public class EvaluationController : Controller { private readonly ILogger _logger; - private readonly IEvaluationLogic _logic; + private readonly IProcedureLogic _procedureLogic; - public EvaluationController(IEvaluationLogic logic, ILogger logger) + private readonly IEvaluationLogic _evaluationLogic; + + public EvaluationController(ILogger logger, IEvaluationLogic evaluationLogic, IProcedureLogic procedureLogic) { _logger = logger; - _logic = logic; + _evaluationLogic = evaluationLogic; + _procedureLogic = procedureLogic; } [HttpGet] - public EvaluationViewModel? GetEvaluation(int id) + public IActionResult Evaluation() { - try + if (APIWorker.Worker == null) { - return _logic.ReadElement(new EvaluationSearchModel - { - Id = id - }); + return Redirect("~/Home/Enter"); } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения оценки"); - throw; - } - } + return View(_evaluationLogic.ReadList(null)); + } [HttpGet] - public List? GetAllEvaluations() + public IActionResult CreateEvaluation() { - try + if (APIWorker.Worker == null) { - return _logic.ReadList(null); + return Redirect("~/Home/Enter"); } - catch (Exception ex) + + ViewBag.Procedure = _procedureLogic.ReadList(new ProcedureSearchModel { - _logger.LogError(ex, "Ошибка получения списка оценок"); - throw; - } + WorkerId = APIWorker.Worker.Id, + }); + + return View(); } [HttpPost] - public void CreateEvaluation(EvaluationBindingModel model) + public void CreateEvaluation(double pointsProcedures, double pointsCosmetics, int procedure) { - try + if (APIWorker.Worker == null) { - _logic.Create(model); + throw new Exception("Необходимо авторизоваться!"); } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания оценки"); - throw; - } - } + if (procedure <= 0) + { + throw new Exception("Введены не все данные!"); + } + + _evaluationLogic.Create(new EvaluationBindingModel + { + PointsProcedure = pointsProcedures, + PointsCosmetics = pointsCosmetics, + ProcedureId = procedure + }); + + Response.Redirect("/Evaluation/Evaluations"); + } + [HttpGet] + public IActionResult UpdateEvaluation(int id) + { + if (APIWorker.Worker == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Procedures = _procedureLogic.ReadList(new ProcedureSearchModel + { + WorkerId = APIWorker.Worker.Id, + }); + + return View(_evaluationLogic.ReadElement(new EvaluationSearchModel + { + Id = id + })); + } [HttpPost] - public void UpdateEvaluation(EvaluationBindingModel model) + public void UpdateEvaluation(int id, double pointsProcedures, double pointsCosmetics, int procedure) { - try + if (APIWorker.Worker == null) { - _logic.Update(model); + throw new Exception("Необходимо авторизоваться!"); } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления оценки"); - throw; - } - } - [HttpDelete] - public void DeleteEvaluation(EvaluationBindingModel model) - { - try + if (procedure <= 0) { - _logic.Delete(model); + throw new Exception("Введены не все данные!"); } - catch (Exception ex) + + + _evaluationLogic.Update(new EvaluationBindingModel { - _logger.LogError(ex, "Ошибка удаления оценки"); - throw; - } + Id = id, + PointsProcedure = pointsProcedures, + PointsCosmetics = pointsCosmetics, + ProcedureId = procedure + }); + + Response.Redirect("/Evaluation/Evaluations"); } } } diff --git a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs index 5b08b91..db41dfb 100644 --- a/BeautySalonView/ClientWebApp/Controllers/OrderController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/OrderController.cs @@ -1,100 +1,239 @@ -using BeautySalonContracts.BindingModels; +using BeautySalonBusinesLogic.BusinessLogic; +using BeautySalonContracts.BindingModels; using BeautySalonContracts.BusinessLogicContracts; using BeautySalonContracts.SearchModels; using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using BeautySalonDataModels.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace WorkerWebApp.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] - public class OrderController : Controller - { - private readonly ILogger _logger; + [Route("api/[controller]/[action]")] + [ApiController] + public class OrderController : Controller + { + private readonly ILogger _logger; - private readonly IOrderLogic _logic; + private readonly IOrderLogic _orderLogic; - public OrderController(IOrderLogic logic, ILogger logger) - { - _logger = logger; - _logic = logic; - } + private readonly IServiceLogic _serviceLogic; - [HttpGet] - public OrderViewModel? GetOrder(int id) - { - try - { - return _logic.ReadElement(new OrderSearchModel - { - Id = id - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения заказа"); - throw; - } - } + /// + /// Бизнес-логика для сущности "Процедура" + /// + private readonly IProcedureLogic _procedureLogic; - /// - /// Получение заказов по id пользователя (полный список, кот. будет выводиться) - /// - /// - /// - [HttpGet] - public List? GetOrders(int? workerId) - { - try - { - return _logic.ReadList(new OrderSearchModel { WorkerId = workerId }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", workerId); - throw; - } - } + public OrderController(ILogger logger, IOrderLogic orderLogic, IProcedureLogic procedureLogic, IServiceLogic serviceLogic) + { + _logger = logger; + _orderLogic = orderLogic; + _procedureLogic = procedureLogic; + _serviceLogic = serviceLogic; + } - [HttpPost] - public void CreateOrder(OrderBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания заказа"); - throw; - } - } - [HttpPost] - public void UpdateOrder(OrderBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления заказа"); - throw; - } - } - [HttpDelete] - public void DeleteOrder(OrderBindingModel model) - { - try - { - _logic.Delete(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления заказа"); - throw; - } - } - } + [HttpGet] + public IActionResult Orders() + { + if (APIWorker.Worker == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_orderLogic.ReadList(new OrderSearchModel + { + WorkerId = APIWorker.Worker.Id, + })); + } + /// + /// Получение заказов по id пользователя (полный список, кот. будет выводиться) + /// + /// + /// + [HttpGet] + public IActionResult CreateOrder() + { + if (APIWorker.Worker == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Services = _serviceLogic.ReadList(null); + + return View(); + } + + [HttpPost] + public void CreateOrder(double amount, DateTime datacreate, DateTime dateimplement, List services) + { + if (APIWorker.Worker == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary orderServices = new Dictionary(); + foreach (var serviceId in services) + { + 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 + }); + + Response.Redirect("/Order/Orders"); + } + [HttpGet] + public IActionResult UpdateOrder(int id) + { + if (APIWorker.Worker == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Services = _serviceLogic.ReadList(null); + + return View(_orderLogic.ReadElement(new OrderSearchModel + { + Id = id + })); + } + [HttpPost] + public void UpdateOrder(int id, double amount, DateTime datacreate, DateTime dateimplement, List services) + { + if (APIWorker.Worker == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null) + { + 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 + { + Id = id, + OrderAmount = amount, + DateCreate = datacreate, + DateImplement = dateimplement, + WorkerId = APIWorker.Worker.Id, + OrderProcedures = order!.OrderProcedures, + OrderServices = orderServices + }); + + Response.Redirect("/Order/Orders"); + } + [HttpPost] + public void DeleteOrder(int id) + { + if (APIWorker.Worker == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + _orderLogic.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); + } + } } diff --git a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs index d17d182..e6b874f 100644 --- a/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/ProcedureController.cs @@ -6,9 +6,7 @@ using Microsoft.AspNetCore.Mvc; using WorkerWebApp; namespace WorkerWebApp.Controllers -{ - [Route("api/[controller]/[action]")] - [ApiController] +{ public class ProcedureController : Controller { private readonly ILogger logger; @@ -82,10 +80,12 @@ namespace WorkerWebApp.Controllers ProcedureName = name, ProcedurePrice = price, ProcedureDuration = duration + + }); - return RedirectToAction("Procedures"); - } + return RedirectToAction("Procedures", "Procedure"); + } [HttpGet] public IActionResult UpdateProcedures(int id) @@ -124,8 +124,8 @@ namespace WorkerWebApp.Controllers ProcedureDuration = duration }); - return RedirectToAction("Procedures"); - } + return RedirectToAction("Procedures", "Procedure"); + } [HttpPost] public IActionResult DeleteProcedure(int id) @@ -140,7 +140,7 @@ namespace WorkerWebApp.Controllers Id = id }); - return RedirectToAction("Procedures"); - } + return RedirectToAction("Procedures", "Procedure"); + } } } \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Views/Evaluation/Create.cshtml b/BeautySalonView/ClientWebApp/Views/Evaluation/Create.cshtml new file mode 100644 index 0000000..b352485 --- /dev/null +++ b/BeautySalonView/ClientWebApp/Views/Evaluation/Create.cshtml @@ -0,0 +1,34 @@ +@{ + ViewData["Title"] = "Создание оценки"; +} + +
+

Создание оценки

+
+ +
+

Баллы за процедуру:

+ +

Баллы за косметику:

+ + + +
+
Процедура:
+
+ +
+
+ + +
+
+
+
+
+ diff --git a/BeautySalonView/ClientWebApp/Views/Evaluation/Evaluations.cshtml b/BeautySalonView/ClientWebApp/Views/Evaluation/Evaluations.cshtml new file mode 100644 index 0000000..eb37243 --- /dev/null +++ b/BeautySalonView/ClientWebApp/Views/Evaluation/Evaluations.cshtml @@ -0,0 +1,69 @@ +@using BeautySalonContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Оценки"; +} + +
+

Оценки

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

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

+ return; + } + +

+ Создать оценку +

+ + + + + + + + + + + + + + + @foreach (var evaluation in Model) + { + + + + + + + + + } + +
НомерОценка за процедуруОценка за косметикуНомер процедуры
@evaluation.Id@evaluation.PointsProcedure@evaluation.PointsCosmetics@evaluation.ProcedureId +

+
+

+
+ } +
+ +@section scripts { + +} + diff --git a/BeautySalonView/ClientWebApp/Views/Evaluation/Update.cshtml b/BeautySalonView/ClientWebApp/Views/Evaluation/Update.cshtml new file mode 100644 index 0000000..bc3f60b --- /dev/null +++ b/BeautySalonView/ClientWebApp/Views/Evaluation/Update.cshtml @@ -0,0 +1,41 @@ +@using BeautySalonContracts.ViewModels + +@model EvaluationViewModel + +@{ + ViewData["Title"] = "Редактирование оценки"; +} + +
+

Редактирование оценки

+
+ +
+ +

Баллы за процедуру:

+ +

Баллы за косметику:

+ + + +
+
Процедура:
+
+ +
+
+ + +
+
+
+
+
diff --git a/BeautySalonView/ClientWebApp/Views/Home/Rating.cshtml b/BeautySalonView/ClientWebApp/Views/Home/Evaluation.cshtml similarity index 100% rename from BeautySalonView/ClientWebApp/Views/Home/Rating.cshtml rename to BeautySalonView/ClientWebApp/Views/Home/Evaluation.cshtml diff --git a/BeautySalonView/ClientWebApp/Views/Order/Create.cshtml b/BeautySalonView/ClientWebApp/Views/Order/Create.cshtml deleted file mode 100644 index 7cddaad..0000000 --- a/BeautySalonView/ClientWebApp/Views/Order/Create.cshtml +++ /dev/null @@ -1,75 +0,0 @@ -@{ - ViewData["Title"] = "Заказ"; -} - -

Создать заказ

- -

Выбранные услуги:

-
- - - - - - - - - - - - - - - - - -
НазваниеСтоимостьКоличество
Не выбрано
-
- -

Добавить услугу:

-

Наименование:

- -

Количество:

- - - -

Выбранные процедуры:

-
- - - - - - - - - - - - - - - - - -
НазваниеСтоимостьКоличество
Не выбрано
-
- -

Привязать процедуру:

-

Наименование:

- -

Количество:

- - - -

Стоимость заказа:

- - - - diff --git a/BeautySalonView/ClientWebApp/Views/Order/CreateOrder.cshtml b/BeautySalonView/ClientWebApp/Views/Order/CreateOrder.cshtml new file mode 100644 index 0000000..d37346c --- /dev/null +++ b/BeautySalonView/ClientWebApp/Views/Order/CreateOrder.cshtml @@ -0,0 +1,46 @@ +@{ + ViewData["Title"] = "Создание заказа"; +} + +
+

Создание заказа

+
+ +
+ +

Стоимость заказа:

+ +
- -

Выбранные процедуры:

-
- - - - - - - - - - - - - - - - - -
НазваниеСтоимостьКоличество
Не выбрано
-
- -

Добавить процедуру:

-

Наименование:

- -

Количество:

- - - -

Стоимость заказа:

- - - - - - diff --git a/BeautySalonView/ClientWebApp/Views/Order/UpdateOrder.cshtml b/BeautySalonView/ClientWebApp/Views/Order/UpdateOrder.cshtml new file mode 100644 index 0000000..8d69034 --- /dev/null +++ b/BeautySalonView/ClientWebApp/Views/Order/UpdateOrder.cshtml @@ -0,0 +1,61 @@ +@using BeautySalonContracts.ViewModels + +@model OrderViewModel + +@{ + ViewData["Title"] = "Редактирование заказа"; +} + +
+

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

+
+ +
+

Стоимость заказа:

+ +
- - diff --git a/BeautySalonView/ClientWebApp/Views/Rating/Update.cshtml b/BeautySalonView/ClientWebApp/Views/Rating/Update.cshtml deleted file mode 100644 index 955aac5..0000000 --- a/BeautySalonView/ClientWebApp/Views/Rating/Update.cshtml +++ /dev/null @@ -1,38 +0,0 @@ -@{ - ViewData["Title"] = "Оценка"; -} - -

Обновить оценку

- -
- -

Баллы за процедуру:

- -

Баллы за косметику:

- -

Процедура:

- - -
- - \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml b/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml index a98ece1..4ada692 100644 --- a/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml +++ b/BeautySalonView/ClientWebApp/Views/Shared/_Layout.cshtml @@ -32,13 +32,13 @@ Авторизация