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 @@