From c5db6541c636dedf2085d487daca5e2c92b89e9f Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 25 Mar 2023 17:28:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D1=81?= =?UTF-8?q?=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopClientApp/APIClient.cs | 55 ++++++++++++++ .../BlacksmithWorkshopClientApp.csproj | 8 ++ .../Views/Home/Index.cshtml | 74 ++++++++++++++++++- .../Views/Home/Privacy.cshtml | 29 +++++++- .../Views/Shared/_Layout.cshtml | 24 ++++-- .../appsettings.json | 4 +- 6 files changed, 178 insertions(+), 16 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs new file mode 100644 index 0000000..f26821b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/APIClient.cs @@ -0,0 +1,55 @@ +using BlacksmithWorkshopContracts.ViewModels; +using Newtonsoft.Json; +using System.Net.Http.Headers; +using System.Text; + +namespace BlacksmithWorkshopClientApp +{ + //класс, который общается с RestAPI. Под клиентом тут подразумевается клиент, общающийся с API, а не созданный нами + public class APIClient + { + private static readonly HttpClient _client = new(); + + //поле, хранящее клиента, которого необходимо авторизовать + public static ClientViewModel? Client { get; set; } = null; + + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } + + //Get-запрос + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + + //Post-запрос + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = _client.PostAsync(requestUrl, data); + + var result = response.Result.Content.ReadAsStringAsync().Result; + + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/BlacksmithWorkshopClientApp.csproj b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/BlacksmithWorkshopClientApp.csproj index c78c9c7..d2be2f5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/BlacksmithWorkshopClientApp.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/BlacksmithWorkshopClientApp.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Index.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Index.cshtml index d2d19bd..637e888 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Index.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Index.cshtml @@ -1,8 +1,74 @@ -@{ - ViewData["Title"] = "Home Page"; +@using BlacksmithWorkshopContracts.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.ManufactureName) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.Count) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.Status) +
+ } +
\ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Privacy.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Privacy.cshtml index af4fb19..25133f4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Privacy.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Home/Privacy.cshtml @@ -1,6 +1,29 @@ -@{ +@using BlacksmithWorkshopContracts.ViewModels + +@model ClientViewModel + +@{ ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

-

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

+
+

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

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+
+
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml index 81450bd..ba56dfb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml @@ -11,19 +11,27 @@