diff --git a/git/JurasicZoo/ZooRestApi/Controllers/MainController.cs b/git/JurasicZoo/ZooRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..864fe72 --- /dev/null +++ b/git/JurasicZoo/ZooRestApi/Controllers/MainController.cs @@ -0,0 +1,85 @@ +using Microsoft.AspNetCore.Mvc; +using ZooContracts.BindingModels; +using ZooContracts.BuisnessLogicsContracts; +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.SearchModels; +using ZooContracts.ViewModels; + +namespace ZooRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IRouteLogic _route; + private readonly IPreserveLogic _preserve; + public MainController(ILogger logger, IRouteLogic route, + IPreserveLogic preserve) + { + _logger = logger; + _route = route; + _preserve = preserve; + } + [HttpGet] + public List? GetPreserveList() + { + try + { + return _preserve.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpGet] + public PreserveViewModel? GetPreserve(int preserveId) + { + try + { + return _preserve.ReadElement(new PreserveSearchModel + { + Id = + preserveId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения заповедника по id={Id}", + preserveId); + throw; + } + } + [HttpGet] + public List? GetRoutes(int clientId) + { + try + { + return _route.ReadList(new RouteSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка маршрутов клиента id ={ Id}", clientId); + throw; + } + } + [HttpPost] + public void CreateRoute(RouteBindingModel model) + { + try + { + _route.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания маршрута"); + throw; + } + } + } +} diff --git a/git/JurasicZoo/ZooShowEmployeeApp/APIEmployee.cs b/git/JurasicZoo/ZooShowEmployeeApp/APIEmployee.cs new file mode 100644 index 0000000..0fba6f7 --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/APIEmployee.cs @@ -0,0 +1,45 @@ +using ZooContracts.ViewModels; +using Newtonsoft.Json; +using System.Net.Http.Headers; +using System.Text; + +namespace ZooShowEmployeeApp +{ + public static class APIEmployee + { + private static readonly HttpClient _employee = new(); + public static EmployeeViewModel? Employee { get; set; } = null; + public static void Connect(IConfiguration configuration) + { + _employee.BaseAddress = new Uri(configuration["IPAddress"]); + _employee.DefaultRequestHeaders.Accept.Clear(); + _employee.DefaultRequestHeaders.Accept.Add(new + MediaTypeWithQualityHeaderValue("application/json")); + } + public static T? GetRequest(string requestUrl) + { + var response = _employee.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, + "application/json"); + var response = _employee.PostAsync(requestUrl, data); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs index 079018e..2ef7739 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNetCore.Mvc; +using ZooContracts.BindingModels; +using ZooContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using ZooShowEmployeeApp.Models; @@ -15,18 +17,117 @@ namespace ZooShowEmployeeApp.Controllers public IActionResult Index() { - return View(); + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIEmployee.GetRequest>($"api/main/getorders?clientId={APIEmployee.Employee.Id}")); } + [HttpGet] public IActionResult Privacy() { - return View(); + if (APIEmployee.Employee == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIEmployee.Employee); } + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIEmployee.Employee == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIEmployee.PostRequest("api/employee/updatedata", new + EmployeeBindingModel + { + Id = APIEmployee.Employee.Id, + EmployeeFIO = fio, + Login = login, + Password = password + }); ; + APIEmployee.Employee.EmployeeFIO = fio; + APIEmployee.Employee.Login = login; + APIEmployee.Employee.Password = password; + Response.Redirect("Index"); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + return View(new ErrorViewModel + { + RequestId = + Activity.Current?.Id ?? HttpContext.TraceIdentifier + }); + } + [HttpGet] + public IActionResult Enter() + { + return View(); + } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIEmployee.Employee = + APIEmployee.GetRequest($"api/employee/login?login={login}&password={password}"); + if (APIEmployee.Employee == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + [HttpPost] + public void Register(string login, string password, string fio) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIEmployee.PostRequest("api/employee/register", new + EmployeeBindingModel + { + EmployeeFIO = fio, + Login = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + [HttpGet] + public IActionResult Create() + { + ViewBag.Preserver = + APIEmployee.GetRequest>("api/main/getpreservelist"); + return View(); + } + [HttpPost] + public double Calc(int count, int preserve) + { + var prod = + APIEmployee.GetRequest($"api/main/getpreserve?preserveId={preserve}" + ); + return count * (prod?.PreservePrice ?? 1); } } } diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Program.cs b/git/JurasicZoo/ZooShowEmployeeApp/Program.cs index 0727468..27af573 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Program.cs +++ b/git/JurasicZoo/ZooShowEmployeeApp/Program.cs @@ -1,10 +1,10 @@ +using ZooShowEmployeeApp; +using Microsoft.EntityFrameworkCore.Infrastructure; var builder = WebApplication.CreateBuilder(args); - // Add services to the container. builder.Services.AddControllersWithViews(); - var app = builder.Build(); - +APIEmployee.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -12,16 +12,11 @@ if (!app.Environment.IsDevelopment()) // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } - app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseRouting(); - app.UseAuthorization(); - app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); - + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/CreatePreserve.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/CreatePreserve.cshtml new file mode 100644 index 0000000..2a49487 --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/CreatePreserve.cshtml @@ -0,0 +1,49 @@ +@{ + ViewData["Title"] = "Create"; +} +
+

Создание Заповедника

+
+
+
+
Название:
+
+ +
+
+
+
Стоимость:
+
+ +
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Enter.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..bda60a1 --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Enter.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Enter"; +} +
+

Вход в приложение

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml index d2d19bd..9b41072 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Index.cshtml @@ -1,8 +1,65 @@ -@{ +@using ZooContracts.ViewModels +@model List +@{ ViewData["Title"] = "Home Page"; } -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Маршруты

+
+
+ @{ + 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) +
+ }
diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Privacy.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Privacy.cshtml index af4fb19..783bfb1 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Privacy.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Privacy.cshtml @@ -1,6 +1,38 @@ -@{ +@using ZooContracts.ViewModels +@model ClientViewModel +@{ ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

+
+

Личные данные

+
+
+
+
Логин:
+
+ +
+
+
+
Пароль:
+
+ +
+
+
+
ФИО:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Register.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..a2f84ee --- /dev/null +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/Register.cshtml @@ -0,0 +1,27 @@ +@{ + ViewData["Title"] = "Register"; +} +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml index 7fbcc70..7c959ab 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Shared/_Layout.cshtml @@ -6,24 +6,28 @@ @ViewData["Title"] - ZooShowEmployeeApp - + +