diff --git a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs index 8dff787..b445fb8 100644 --- a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs @@ -1,7 +1,10 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Globalization; using ZooClientApp.Models; using ZooContracts.BindingModels; +using ZooContracts.BuisnessLogicsContracts; +using ZooContracts.BusinessLogicsContracts; using ZooContracts.SearchModels; using ZooContracts.ViewModels; using ZooDataModels.Models; @@ -11,6 +14,9 @@ namespace ZooClientApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IPreserveLogic _preservelLogic; + private readonly IClientLogic _clientLogic; + private readonly IRouteLogic _dorctorVisitLogic; public HomeController(ILogger logger) { _logger = logger; @@ -112,49 +118,107 @@ namespace ZooClientApp.Controllers Response.Redirect("Enter"); return; } - [HttpGet] - public IActionResult Create() + //=================ЖИВОТНЫЕ================= + public IActionResult IndexPreserve() { - ViewBag.Routes = - APIClient.GetRequest>("api/main/getRoutes"); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/preserve/getpreserves?employeeid={1}")); + } + public IActionResult CreatePreserve() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } return View(); } [HttpPost] - public void Create(int Route, int count) + public void Createpreserve(string name, int price) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || price <= 0) + { + throw new Exception("Ошибка в введённых данных"); + } + APIClient.PostRequest("api/preserve/createpreserve", new PreserveBindingModel + { + PreserveName = name, + PreservePrice = price, + EmployeeId = 1 + }); + Response.Redirect("Index"); + } + public IActionResult UpdatePreserve() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Preserves = APIClient.GetRequest>($"api/preserve/getpreserves?employeeid={1}"); + return View(); + } + [HttpPost] + public void UpdatePreserve(int pet, string name, int price) { if (APIClient.Client == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (count <= 0) + if (string.IsNullOrEmpty(name) || price <= 0) { - throw new Exception("Количество и сумма должны быть больше 0"); + throw new Exception("Ошибка введённых данных"); } - APIClient.PostRequest("api/main/createroute", new - RouteBindingModel + APIClient.PostRequest("api/preserve/updatepreserve", new PreserveViewModel { - ClientId = APIClient.Client.Id - + Id = pet, + PreserveName = name, + PreservePrice = price, }); Response.Redirect("Index"); } - [HttpPost] - public double Calc(int count, int canned) + [HttpGet] + public Tuple? GetPreserve(int preserveId) { - var prod = - APIClient.GetRequest($"api/main/getcanned?cannedId={canned}" - ); - return count * (prod?.PreservePrice ?? 1); + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIClient.GetRequest>($"api/preserve/getpreserve?preserveId={preserveId}"); + if (result == null) + { + return default; + } + return result; } - //Маршруты + [HttpPost] + public void IndexPreserve(int id) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/preserve/deletepreserve", new PreserveBindingModel + { + Id = id + }); + Response.Redirect("Index"); + } + + //=================ПОСЕЩЕНИЯ================= public IActionResult IndexRoute() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } - - return View(APIClient.GetRequest>($"api/route/getroutes?Clientid={APIClient.Client.Id}")); + var helpme = APIClient.GetRequest>($"api/route/getroutes?clientid={APIClient.Client.Id}"); + return View(helpme); } public IActionResult CreateRoute() { @@ -162,7 +226,8 @@ namespace ZooClientApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Preserves = APIClient.GetRequest>($"api/preserve/getpreserves"); + ViewBag.Preserves = APIClient.GetRequest>($"api/preserve/getpreserves?employeeid={1}"); + //ViewBag.Services = APIClient.GetRequest>($"api/service/getservices?doctorid={null}"); return View(); } [HttpPost] @@ -173,30 +238,37 @@ namespace ZooClientApp.Controllers throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } Dictionary a = new Dictionary(); - foreach (int pet in preserves) + foreach (int preserve in preserves) { - a.Add(pet, new PreserveSearchModel { Id = pet } as IPreserveModel); + a.Add(preserve, new PreserveSearchModel { Id = preserve } as IPreserveModel); } - APIClient.PostRequest("api/route/createroute", new RouteBindingModel { ClientId = APIClient.Client.Id, RoutePreserves = a, - DateStart = dateTime, + RoutePrice = 100, RouteName = name }); Response.Redirect("IndexRoute"); } + //=================ПОКУПКИ================= + //=================ПРОЧЕЕ================= + + public IActionResult Reports() + { + return View(); + } [HttpGet] - public IActionResult Mails() + public IActionResult AnimalServices() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } + ViewBag.Animals = APIClient.GetRequest>($"api/preserve/getpreserves?employeeid={1}"); return View(); - //return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); } + } } \ 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 8e899a4..17fddd5 100644 --- a/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml +++ b/git/JurasicZoo/ZooClientApp/Views/Home/IndexRoute.cshtml @@ -46,7 +46,7 @@ @Html.DisplayFor(modelItem => item.Id) - @Html.DisplayFor(modelItem => item.RoutePrice) + @Html.DisplayFor(modelItem => item.RouteName) @Html.DisplayFor(modelItem => item.Status) diff --git a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs index f1a5669..670176f 100644 --- a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs +++ b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs @@ -25,7 +25,7 @@ namespace ZooContracts.ViewModels [DisplayName("Статус")] public RouteStatus Status { get; set; } = RouteStatus.Неоплачен; [DisplayName("Дата начала")] - public DateTime DateStart { get; set; } + public DateTime DateStart { get; set; } = DateTime.Now; [DisplayName("Дата окончания")] public DateTime DateFinish { get; set; } public Dictionary RoutePreserves diff --git a/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs b/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs index 93f44b7..2cb7cd6 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs @@ -28,10 +28,7 @@ namespace ZooDataBaseImplement.Implements public List GetFilteredList(RouteSearchModel model) { - if (string.IsNullOrEmpty(model.RouteName)) - { - return new(); - } + using var context = new ZooDatabase(); return context.Routes .Include(x => x.Preserves) @@ -44,11 +41,7 @@ namespace ZooDataBaseImplement.Implements public RouteViewModel? GetElement(RouteSearchModel model) { - if (string.IsNullOrEmpty(model.RouteName) && - !model.Id.HasValue) - { - return null; - } + using var context = new ZooDatabase(); return context.Routes .Include(x => x.Preserves) diff --git a/git/JurasicZoo/ZooDataBaseImplement/ZooDatabase.cs b/git/JurasicZoo/ZooDataBaseImplement/ZooDatabase.cs index 2eb0c3f..be88260 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/ZooDatabase.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/ZooDatabase.cs @@ -17,7 +17,7 @@ namespace ZooDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=jurasiczoo;Username=postgres;Password=1212"); + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=jurasiczoo;Username=postgres;Password=98987667"); } base.OnConfiguring(optionsBuilder); }