From 19606c2a5cd641fd4961105a0cd412f35729a688 Mon Sep 17 00:00:00 2001 From: "kagbie3nn@mail.ru" Date: Fri, 31 May 2024 11:45:10 +0400 Subject: [PATCH] poi --- .../ZooDataBaseImplement/Models/Preserve.cs | 6 +- .../Controllers/PreserveController.cs | 94 ++++++++++ .../Controllers/ReportControllerEmployee.cs | 48 +++++ .../Controllers/HomeController.cs | 170 ++++++++++++++++-- .../Views/Home/Index.cshtml | 74 ++------ .../Views/Home/IndexPreserve.cshtml | 63 +++++++ .../Views/Home/ListPreserves.cshtml | 35 ++++ .../Views/Home/Reports.cshtml | 12 ++ .../Views/Shared/_Layout.cshtml | 6 - .../ZooShowEmployeeApp.csproj | 2 +- 10 files changed, 423 insertions(+), 87 deletions(-) create mode 100644 git/JurasicZoo/ZooRestApi/Controllers/PreserveController.cs create mode 100644 git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs create mode 100644 git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexPreserve.cshtml create mode 100644 git/JurasicZoo/ZooShowEmployeeApp/Views/Home/ListPreserves.cshtml create mode 100644 git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Reports.cshtml diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/Preserve.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/Preserve.cs index 3a50cad..b1c8bf5 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/Preserve.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/Preserve.cs @@ -35,7 +35,8 @@ namespace ZooDataBaseImplement.Models Id = model.Id, PreserveName = model.PreserveName, PreservePrice = model.PreservePrice, - }; + EmployeeId = model.EmployeeId, + }; } public void Update(PreserveBindingModel model) { @@ -51,7 +52,8 @@ namespace ZooDataBaseImplement.Models Id = Id, PreserveName = PreserveName, PreservePrice = PreservePrice, - }; + EmployeeId = EmployeeId, + }; } } diff --git a/git/JurasicZoo/ZooRestApi/Controllers/PreserveController.cs b/git/JurasicZoo/ZooRestApi/Controllers/PreserveController.cs new file mode 100644 index 0000000..870a0a6 --- /dev/null +++ b/git/JurasicZoo/ZooRestApi/Controllers/PreserveController.cs @@ -0,0 +1,94 @@ +using Microsoft.AspNetCore.Mvc; +using ZooContracts.BindingModels; +using ZooContracts.BuisnessLogicsContracts; +using ZooContracts.SearchModels; +using ZooContracts.ViewModels; +using ZooDataBaseImplement.Models; + +namespace ZooRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class PreserveController : Controller + { + private readonly ILogger _logger; + private readonly IPreserveLogic _preserve; + public PreserveController(ILogger logger, IPreserveLogic preserve) + { + _logger = logger; + _preserve = preserve; + } + [HttpGet] + public List GetPreserves(int EmployeeId) + { + try + { + return _preserve.ReadList(new PreserveSearchModel { EmployeeId = EmployeeId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка животных"); + throw; + } + } + [HttpGet] + public Tuple? GetPreserve(int PreserveId) + { + try + { + var elem = _preserve.ReadElement(new PreserveSearchModel { Id = PreserveId }); + if (elem == null) + { + return null; + } + return Tuple.Create(elem); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения животного по id={Id}", PreserveId); + throw; + } + } + [HttpPost] + public bool CreatePreserve(PreserveBindingModel model) + { + try + { + return _preserve.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать животного"); + throw; + } + } + + [HttpPost] + public bool UpdatePreserve(PreserveBindingModel model) + { + try + { + return _preserve.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить животное"); + throw; + } + } + + [HttpPost] + public bool DeletePreserve(PreserveBindingModel model) + { + try + { + return _preserve.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления животного"); + throw; + } + } + } + } diff --git a/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs b/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs new file mode 100644 index 0000000..4d07d32 --- /dev/null +++ b/git/JurasicZoo/ZooRestApi/Controllers/ReportControllerEmployee.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Mvc; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; + +namespace ZooRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportControllerEmployee : Controller + { + private readonly ILogger _logger; + private readonly IReportEmployeeLogic _report; + public ReportControllerEmployee(ILogger logger, IReportEmployeeLogic report) + { + logger = logger; + _report = report; + } + [Microsoft.AspNetCore.Mvc.HttpGet] + public IActionResult Index(ReportControllerEmployee report) + { + return View(); + } + [HttpPost] + public void CreateServiceListWordFile(ReportRouteBindingModel model) + { + try + { + _report.SaveRoutesToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] + public void CreateServiceListExcelFile(ReportRouteBindingModel model) + { + try + { + _report.SaveRoutesToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } + } +} \ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs index 528a54e..e3c4cce 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs @@ -25,6 +25,11 @@ namespace ZooShowEmployeeApp.Controllers View(APIEmployee.GetRequest>($"api/main/getroutes?EmployeeId={APIEmployee.Employee.Id}")); } + + public IActionResult Reports() + { + return View(); + } [HttpGet] public IActionResult Privacy() { @@ -116,32 +121,167 @@ namespace ZooShowEmployeeApp.Controllers } - [HttpGet] - public IActionResult CreatePreserve() + public IActionResult IndexPreserve() + { + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIEmployee.GetRequest>($"api/Preserve/getPreserves?clientid={APIEmployee.Employee.Id}")); + } + public IActionResult CreatePreserve() + { + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + [HttpPost] + public void CreatePreserve(string name, double price) + { + if (APIEmployee.Employee == null) + { + throw new Exception("Вы как суда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || price <= 0 ) + { + throw new Exception("Ошибка в введённых данных"); + } + APIEmployee.PostRequest("api/Preserve/createPreserve", new PreserveBindingModel + { + PreserveName = name, + PreservePrice = price, + EmployeeId = APIEmployee.Employee.Id + }); + Response.Redirect("Index"); + } + public IActionResult UpdatePreserve() + { + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Preserves = APIEmployee.GetRequest>($"api/Preserve/getPreserves?clientid={APIEmployee.Employee.Id}"); + return View(); + } + [HttpPost] + public void UpdatePreserve(int pet, string name, double price) + { + if (APIEmployee.Employee == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || price <= 0) + { + throw new Exception("Ошибка введённых данных"); + } + APIEmployee.PostRequest("api/Preserve/updatePreserve", new PreserveViewModel + { + Id = pet, + PreserveName = name, + PreservePrice = price, + + }); + Response.Redirect("Index"); + } + [HttpGet] + public Tuple? GetPreserve(int PreserveId) + { + if (APIEmployee.Employee == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIEmployee.GetRequest>($"api/Preserve/getPreserve?PreserveId={PreserveId}"); + if (result == null) + { + return default; + } + return result; + } + [HttpPost] + public void IndexPreserve(int id) + { + if (APIEmployee.Employee == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIEmployee.PostRequest("api/Preserve/deletePreserve", new PreserveBindingModel + { + Id = id + }); + Response.Redirect("Index"); + } + + + + + + + + + + + + + [HttpGet] + public IActionResult ListPreserves() { - ViewBag.Preserves = - APIEmployee.GetRequest>("api/main/getpreservelist"); + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Preserves = APIEmployee.GetRequest>($"api/preserve/GetPreserves?Employeeid={APIEmployee.Employee.Id}"); return View(); } + [HttpPost] - public void CreatePreserve(int preserve, int count) + public void ListPreserves(List preserve, string type) { if (APIEmployee.Employee == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (count <= 0) - { - throw new Exception("Количество и сумма должны быть больше 0"); - } - APIEmployee.PostRequest("api/main/createpreserve", new - PreserveBindingModel - { - EmployeeId = APIEmployee.Employee.Id - }); - Response.Redirect("Index"); + if (preserve.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + if (type == "docx") + { + APIEmployee.PostRequest("api/report/createservicelistwordfile", new ReportPreserveBindingModel + { + Preserve = preserve, + FileName = "C:\\gg\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIEmployee.PostRequest("api/report/createservicelistexcelfile", new ReportPreserveBindingModel + { + Preserve = preserve, + FileName = "C:\\gg\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } } + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\gg\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\gg\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } } } diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml index 84c6135..060828f 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml @@ -1,66 +1,14 @@ -@using ZooContracts.ViewModels -@model List -@{ +@{ ViewData["Title"] = "Home Page"; } +
-

Маршруты

-
-Создать Маршруты -
- @{ - if (Model == null) - { -

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

- return; - } - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - } - -
- Номер - - Заповедники - - Дата начала - - Дата окончания - - Статус -
- @Html.DisplayFor(modelItem => - item.Id) - - @Html.DisplayFor(modelItem => - item.RouteName) - - @Html.DisplayFor(modelItem => - item.DateStart) - - @Html.DisplayFor(modelItem => - item.DateFinish) - - @Html.DisplayFor(modelItem => - item.Status) -
- } -
+

Приложение "Зоопарк "Юрский период". Исполнитель"

+ + \ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexPreserve.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexPreserve.cshtml new file mode 100644 index 0000000..a2b266f --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexPreserve.cshtml @@ -0,0 +1,63 @@ +@using ZooContracts.ViewModels; + +@model List + +@{ + ViewData["Title"] = "Preserves"; +} + +
+

Заповедник

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

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

+ return; + } +

+ Создать Заповедник + Обновить Заповедник +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + Название + + Стоимость +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.PreserveName) + + @Html.DisplayFor(modelItem => item.PreservePrice) + +
+ + +
+
+ } +
\ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/ListPreserves.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/ListPreserves.cshtml new file mode 100644 index 0000000..f4f043d --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/ListPreserves.cshtml @@ -0,0 +1,35 @@ +@using ZooContracts.ViewModels; +@{ + ViewData["Title"] = "ServiceListReport"; +} + +
+

Создать cписки маршрутов

+
+
+
+
маршрут:
+
+ +
+
+
+ +
+ + +
+
+ + +
+
+
+ +
+
diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Reports.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Reports.cshtml new file mode 100644 index 0000000..6df2a91 --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Reports.cshtml @@ -0,0 +1,12 @@ +@{ + ViewData["Title"] = ""; +} + + + diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml index 41ee25c..f81240f 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml @@ -20,12 +20,6 @@