From cdc415a487bc0f3dbdd7c9a66e9012b9a4582707 Mon Sep 17 00:00:00 2001 From: Leozillo73 <76777036+Leozillo73@users.noreply.github.com> Date: Fri, 31 May 2024 15:37:24 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=B3=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 43 +++++++ .../Views/Home/CreateRoute.cshtml | 13 +-- .../ZooClientApp/Views/Home/IndexRoute.cshtml | 6 + .../Controllers/ReportControllerEmployee.cs | 2 +- .../ZooRestApi/Controllers/RouteController.cs | 109 ++++++++++++++++++ 5 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 git/JurasicZoo/ZooRestApi/Controllers/RouteController.cs diff --git a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs index dc15024..30fca8e 100644 --- a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs @@ -2,7 +2,9 @@ using System.Diagnostics; using ZooClientApp.Models; using ZooContracts.BindingModels; +using ZooContracts.SearchModels; using ZooContracts.ViewModels; +using ZooDataModels.Models; namespace ZooClientApp.Controllers { @@ -144,6 +146,47 @@ namespace ZooClientApp.Controllers ); return count * (prod?.PreservePrice ?? 1); } + //Маршруты + public IActionResult IndexRoute() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + var helpme = APIClient.GetRequest>($"api/route/getroutes?clientid={APIClient.Client.Id}"); + return View(helpme); + } + public IActionResult CreateRoute() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Preserves = APIClient.GetRequest>($"api/preserve/getpreserves?clientid={APIClient.Client.Id}"); + return View(); + } + [HttpPost] + public void CreateRoute(string name, List preserves, DateTime dateTime) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + Dictionary a = new Dictionary(); + foreach (int pet in preserves) + { + a.Add(pet, new PreserveSearchModel { Id = pet } as IPreserveModel); + } + + APIClient.PostRequest("api/route/createroute", new RouteBindingModel + { + ClientId = APIClient.Client.Id, + RoutePreserves = a, + DateStart = dateTime, + RouteName = name + }); + Response.Redirect("IndexRoute"); + } [HttpGet] public IActionResult Mails() diff --git a/git/JurasicZoo/ZooClientApp/Views/Home/CreateRoute.cshtml b/git/JurasicZoo/ZooClientApp/Views/Home/CreateRoute.cshtml index a4ff1d8..732ddf0 100644 --- a/git/JurasicZoo/ZooClientApp/Views/Home/CreateRoute.cshtml +++ b/git/JurasicZoo/ZooClientApp/Views/Home/CreateRoute.cshtml @@ -24,7 +24,7 @@
-
Дата:
+
Дата начала:
@@ -36,14 +36,3 @@
-@section Scripts - { - -} \ No newline at end of file diff --git a/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml b/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml index 8e94b8c..8e899a4 100644 --- a/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml +++ b/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml @@ -30,6 +30,9 @@ Маршрут + + Статус + Дата начала @@ -45,6 +48,9 @@ @Html.DisplayFor(modelItem => item.RoutePrice) + + @Html.DisplayFor(modelItem => item.Status) + @Html.DisplayFor(modelItem => item.DateStart) diff --git a/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs b/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs index 4d07d32..e626bbd 100644 --- a/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs +++ b/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs @@ -12,7 +12,7 @@ namespace ZooRestApi.Controllers private readonly IReportEmployeeLogic _report; public ReportControllerEmployee(ILogger logger, IReportEmployeeLogic report) { - logger = logger; + _logger = logger; _report = report; } [Microsoft.AspNetCore.Mvc.HttpGet] diff --git a/git/JurasicZoo/ZooRestApi/Controllers/RouteController.cs b/git/JurasicZoo/ZooRestApi/Controllers/RouteController.cs new file mode 100644 index 0000000..820d7f8 --- /dev/null +++ b/git/JurasicZoo/ZooRestApi/Controllers/RouteController.cs @@ -0,0 +1,109 @@ +using Microsoft.AspNetCore.Mvc; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.SearchModels; +using ZooContracts.ViewModels; +using ZooDataBaseImplement.Models; + +namespace ZooRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class RouteController : Controller + { + private readonly ILogger _logger; + private readonly IRouteLogic _route; + public RouteController(ILogger logger, IRouteLogic route) + { + _logger = logger; + _route = route; + } + [HttpGet] + public Tuple>? GetRoutes(int visitId) + { + try + { + var elem = _route.ReadElement(new RouteSearchModel { Id = visitId }); + if (elem == null) + { + return null; + } + var res = Tuple.Create(elem, elem.RoutePreserves.Select(x => x.Value.PreserveName).ToList()); + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения визита по id={Id}", visitId); + throw; + } + } + [HttpGet] + public List? GetRoutes(int? clientId) + { + try + { + return _route.ReadList(new RouteSearchModel { ClientId = clientId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка маршрутов"); + throw; + } + } + + [HttpGet] + public List GetAllVisits() + { + try + { + return _route.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка маршрутов"); + throw; + } + } + + [HttpPost] + public bool CreateVisit(RouteBindingModel model) + { + try + { + return _route.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать маршрут"); + throw; + } + } + + [HttpPost] + public bool UpdateVisit(RouteBindingModel model) + { + try + { + return _route.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить маршрута"); + throw; + } + } + [HttpPost] + public bool DeleteVisit(RouteBindingModel model) + { + try + { + return _route.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления маршрутп"); + throw; + } + } + } +}