diff --git a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs index c660d68..6db61af 100644 --- a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs +++ b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; using SecurirySystemClientApp.Models; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; using System.Diagnostics; namespace SecurirySystemClientApp.Controllers @@ -7,26 +9,130 @@ namespace SecurirySystemClientApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); } - + [HttpGet] public IActionResult Privacy() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); + } + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + { + Id = APIClient.Client.Id, + ClientFIO = fio, + Email = login, + Password = password + }); + APIClient.Client.ClientFIO = fio; + APIClient.Client.Email = login; + APIClient.Client.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("Введите логин и пароль"); + } + APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + if (APIClient.Client == 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("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new ClientBindingModel + { + ClientFIO = fio, + Email = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + [HttpGet] + public IActionResult Create() + { + ViewBag.Secures = APIClient.GetRequest>("api/main/getsecurelist"); + return View(); + } + [HttpPost] + public void Create(int secure, int count) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + ClientId = APIClient.Client.Id, + SecureId = secure, + Count = count, + Sum = Calc(count, secure) + }); + Response.Redirect("Index"); + } + [HttpPost] + public double Calc(int count, int secure) + { + var prod = APIClient.GetRequest($"api/main/getsecure?secureId={secure}"); + return count * (prod?.Price ?? 1); } } + } diff --git a/SecuritySystem/SecurirySystemClientApp/Program.cs b/SecuritySystem/SecurirySystemClientApp/Program.cs index 0727468..d2be4bc 100644 --- a/SecuritySystem/SecurirySystemClientApp/Program.cs +++ b/SecuritySystem/SecurirySystemClientApp/Program.cs @@ -1,10 +1,9 @@ +using SecurirySystemClientApp; var builder = WebApplication.CreateBuilder(args); - // Add services to the container. builder.Services.AddControllersWithViews(); - var app = builder.Build(); - +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -12,16 +11,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?}"); - -app.Run(); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); +app.Run(); \ No newline at end of file diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml new file mode 100644 index 0000000..850a7b9 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml @@ -0,0 +1,54 @@ +@{ + ViewData["Title"] = "Создание заказа"; +} +
+

Создание заказа

+
+
+
+
Изделие:
+
+ +
+
+
+
Количество:
+
+ +
+
+
+
Сумма:
+
+ +
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml.cs b/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml.cs new file mode 100644 index 0000000..b9b99be --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Create.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace SecurirySystemClientApp.Views.Home +{ + public class CreateModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..4b0a408 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Вход"; +} +
+

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

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml.cs b/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml.cs new file mode 100644 index 0000000..6d0d381 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Enter.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace SecurirySystemClientApp.Views.Home +{ + public class EnterModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Index.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Index.cshtml index d2d19bd..7a4501e 100644 --- a/SecuritySystem/SecurirySystemClientApp/Views/Home/Index.cshtml +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Index.cshtml @@ -1,8 +1,75 @@ -@{ - ViewData["Title"] = "Home Page"; +@using SecuritySystemContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Главная"; } -
-

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.SecureName) + + @Html.DisplayFor(modelItem => + item.DateCreate) + + @Html.DisplayFor(modelItem => + item.Count) + + @Html.DisplayFor(modelItem => + item.Sum) + + @Html.DisplayFor(modelItem => + item.Status) +
+ }
diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Privacy.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Privacy.cshtml index af4fb19..e045ccd 100644 --- a/SecuritySystem/SecurirySystemClientApp/Views/Home/Privacy.cshtml +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Privacy.cshtml @@ -1,6 +1,34 @@ -@{ - ViewData["Title"] = "Privacy Policy"; +@using SecuritySystemContracts.ViewModels +@model ClientViewModel +@{ + ViewData["Title"] = "Политика приватности"; } -

@ViewData["Title"]

- -

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

+
+

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

+
+
+
+
Логин:
+
+ +
+
+
+
Пароль:
+
+ +
+
+
+
ФИО:
+
+ +
+
+
+
+
+ +
+
+
diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..10020f6 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml @@ -0,0 +1,26 @@ +@{ + ViewData["Title"] = "Регистрация"; +} +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml.cs b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml.cs new file mode 100644 index 0000000..84ebcbf --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace SecurirySystemClientApp.Views.Home +{ + public class RegisterModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml index 2bef716..bf0d50c 100644 --- a/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml +++ b/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - AbstractShowClientApp + @ViewData["Title"] - SecuritySystemClientApp @@ -43,7 +43,7 @@ diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs index 0a898fa..cca3cf1 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs @@ -41,14 +41,7 @@ namespace SecuritySystemDatabaseImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } - using var context = new SecuritySystemDatabase(); - return context.Clients - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetFilteredList(model).FirstOrDefault(); } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/SecuritySystem/SecuritySystemFileImplement/Implements/ClientStorage.cs b/SecuritySystem/SecuritySystemFileImplement/Implements/ClientStorage.cs index 65a19c8..87a1427 100644 --- a/SecuritySystem/SecuritySystemFileImplement/Implements/ClientStorage.cs +++ b/SecuritySystem/SecuritySystemFileImplement/Implements/ClientStorage.cs @@ -42,11 +42,7 @@ namespace SecuritySystemFileImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } - return source.Clients.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetFilteredList(model).FirstOrDefault(); } public ClientViewModel? Insert(ClientBindingModel model) { diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/ClientStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/ClientStorage.cs index 6b11129..787199b 100644 --- a/SecuritySystem/SecuritySystemListImplement/Implements/ClientStorage.cs +++ b/SecuritySystem/SecuritySystemListImplement/Implements/ClientStorage.cs @@ -47,22 +47,7 @@ namespace SecuritySystemListImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } - foreach (var client in _source.Clients) - { - if ( - (!string.IsNullOrEmpty(model.Email) && - client.Email == model.Email) || - (model.Id.HasValue && client.Id == model.Id) - ) - { - return client.GetViewModel; - } - } - return null; + return GetFilteredList(model).FirstOrDefault(); } public ClientViewModel? Insert(ClientBindingModel model) {