Вливаю

This commit is contained in:
Leozillo73 2024-05-31 23:47:17 +04:00
parent 4310c47ceb
commit c9fb6972e2
5 changed files with 104 additions and 39 deletions

View File

@ -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<HomeController> _logger;
private readonly IPreserveLogic _preservelLogic;
private readonly IClientLogic _clientLogic;
private readonly IRouteLogic _dorctorVisitLogic;
public HomeController(ILogger<HomeController> 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<List<PreserveViewModel>>("api/main/getRoutes");
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<PreserveViewModel>>($"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<List<PreserveViewModel>>($"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<PreserveViewModel>? GetPreserve(int preserveId)
{
var prod =
APIClient.GetRequest<PreserveViewModel>($"api/main/getcanned?cannedId={canned}"
);
return count * (prod?.PreservePrice ?? 1);
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIClient.GetRequest<Tuple<PreserveViewModel>>($"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<List<RouteViewModel>>($"api/route/getroutes?Clientid={APIClient.Client.Id}"));
var helpme = APIClient.GetRequest<List<RouteViewModel>>($"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<List<PreserveViewModel>>($"api/preserve/getpreserves");
ViewBag.Preserves = APIClient.GetRequest<List<PreserveViewModel>>($"api/preserve/getpreserves?employeeid={1}");
//ViewBag.Services = APIClient.GetRequest<List<ServiceViewModel>>($"api/service/getservices?doctorid={null}");
return View();
}
[HttpPost]
@ -173,30 +238,37 @@ namespace ZooClientApp.Controllers
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
Dictionary<int, IPreserveModel> a = new Dictionary<int, IPreserveModel>();
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<List<PreserveViewModel>>($"api/preserve/getpreserves?employeeid={1}");
return View();
//return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
}
}
}

View File

@ -46,7 +46,7 @@
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.RoutePrice)
@Html.DisplayFor(modelItem => item.RouteName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)

View File

@ -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<int, IPreserveModel> RoutePreserves

View File

@ -28,10 +28,7 @@ namespace ZooDataBaseImplement.Implements
public List<RouteViewModel> 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)

View File

@ -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);
}