From 1d879cc6602ce753c5027fb67254234afa67a1fa Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Sun, 26 May 2024 19:33:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B0=D1=8E=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComputerShop.sln | 3 + .../ComputerShopContracts.csproj | 4 + .../ViewModels/RequestViewModel.cs | 9 + .../ViewModels/ShipmentViewModel.cs | 9 + .../Implements/OrderStorage.cs | 5 +- .../Implements/RequestStorage.cs | 8 +- .../Implements/ShipmentStorage.cs | 7 +- ComputerShopDatabaseImplement/Models/Order.cs | 2 + .../Models/Request.cs | 5 +- .../Models/Shipment.cs | 4 +- .../Models/ShipmentOrder.cs | 5 + ComputerShopImplementerApp/APIUser.cs | 146 +++++- .../ComputerShopImplementerApp.csproj | 4 +- .../Controllers/HomeController.cs | 460 ++++++++++++++++++ ComputerShopImplementerApp/Program.cs | 22 + .../Views/Home/ConnectRequestAssembly.cshtml | 100 ++++ .../Views/Home/CreateOrder.cshtml | 61 +++ .../Views/Home/CreateRequest.cshtml | 49 ++ .../Views/Home/CreateShipment.cshtml | 48 ++ .../Views/Home/DeleteOrder.cshtml | 94 ++++ .../Views/Home/DeleteRequest.cshtml | 81 +++ .../Views/Home/DeleteShipment.cshtml | 80 +++ .../Views/Home/Orders.cshtml | 66 +++ .../Views/Home/Requests.cshtml | 75 +++ .../Views/Home/Shipments.cshtml | 62 +++ .../Views/Home/UpdateOrder.cshtml | 107 ++++ .../Views/Home/UpdateRequest.cshtml | 96 ++++ .../Views/Home/UpdateShipment.cshtml | 103 ++++ .../Views/Shared/_Layout.cshtml | 12 +- .../ComputerShopRestApi.csproj | 1 + .../Controllers/OrderController.cs | 14 +- .../Controllers/RequestController.cs | 2 +- .../Controllers/ShipmentController.cs | 2 +- ComputerShopRestApi/Program.cs | 6 + 34 files changed, 1735 insertions(+), 17 deletions(-) create mode 100644 ComputerShopImplementerApp/Views/Home/ConnectRequestAssembly.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/CreateOrder.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/CreateRequest.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/CreateShipment.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/DeleteOrder.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/DeleteRequest.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/DeleteShipment.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/Orders.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/Requests.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/Shipments.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/UpdateOrder.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/UpdateRequest.cshtml create mode 100644 ComputerShopImplementerApp/Views/Home/UpdateShipment.cshtml diff --git a/ComputerShop.sln b/ComputerShop.sln index 5f018c7..bcc0cec 100644 --- a/ComputerShop.sln +++ b/ComputerShop.sln @@ -14,6 +14,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDatabaseImplement", "ComputerShopDatabaseImplement\ComputerShopDatabaseImplement.csproj", "{CDE4C963-67B5-47A6-A394-901E95EA40F7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopImplementerApp", "ComputerShopImplementerApp\ComputerShopImplementerApp.csproj", "{0E13C365-F2CC-4A32-BDD0-52E2DB324734}" + ProjectSection(ProjectDependencies) = postProject + {BBCF398B-D800-4D8D-99E8-F7ED2CC14A65} = {BBCF398B-D800-4D8D-99E8-F7ED2CC14A65} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ComputerShopContracts/ComputerShopContracts.csproj b/ComputerShopContracts/ComputerShopContracts.csproj index ac0c524..0e1d43c 100644 --- a/ComputerShopContracts/ComputerShopContracts.csproj +++ b/ComputerShopContracts/ComputerShopContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/ComputerShopContracts/ViewModels/RequestViewModel.cs b/ComputerShopContracts/ViewModels/RequestViewModel.cs index 8157fff..807ccc3 100644 --- a/ComputerShopContracts/ViewModels/RequestViewModel.cs +++ b/ComputerShopContracts/ViewModels/RequestViewModel.cs @@ -1,4 +1,5 @@ using ComputerShopDataModels.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -29,5 +30,13 @@ namespace ComputerShopContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; + + public RequestViewModel() { } + + [JsonConstructor] + public RequestViewModel(Dictionary requestOrders) + { + this.RequestOrders = requestOrders.ToDictionary(x => x.Key, x => x.Value as IOrderModel); + } } } diff --git a/ComputerShopContracts/ViewModels/ShipmentViewModel.cs b/ComputerShopContracts/ViewModels/ShipmentViewModel.cs index 51ec3b2..c954bf6 100644 --- a/ComputerShopContracts/ViewModels/ShipmentViewModel.cs +++ b/ComputerShopContracts/ViewModels/ShipmentViewModel.cs @@ -1,4 +1,5 @@ using ComputerShopDataModels.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -25,5 +26,13 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Дата поставки")] public DateTime DateShipment { get; set; } = DateTime.Now; + + public ShipmentViewModel() { } + + [JsonConstructor] + public ShipmentViewModel(Dictionary shipmentOrders) + { + this.ShipmentOrders = shipmentOrders.ToDictionary(x => x.Key, x => x.Value as IOrderModel); + } } } diff --git a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs index 9ea174b..3607374 100644 --- a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs @@ -21,7 +21,7 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFullList() { using var context = new ComputerShopDatabase(); - return context.Orders.Select(x => x.GetViewModel).ToList(); + return context.Orders.OrderBy(x => x.DateCreate).Select(x => x.GetViewModel).ToList(); } //Учитывается id пользователя (везде получение списка только тех записей, что создал сам пользователь) @@ -33,6 +33,7 @@ namespace ComputerShopDatabaseImplement.Implements { return context.Orders .Where(x => (x.UserId == model.UserId) && (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)) + .OrderBy(x => x.DateCreate) .Select(x => x.GetViewModel) .ToList(); } @@ -41,12 +42,14 @@ namespace ComputerShopDatabaseImplement.Implements { return context.Orders .Where(x => (x.UserId == model.UserId) && (x.Status == model.Status)) + .OrderBy(x => x.DateCreate) .Select(x => x.GetViewModel) .ToList(); } //возвращение просто всех заказов пользователя (замена GetFullList) return context.Orders .Where(x => x.UserId == model.UserId) + .OrderBy(x => x.DateCreate) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs index 5ab8ec6..51c1dd2 100644 --- a/ComputerShopDatabaseImplement/Implements/RequestStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/RequestStorage.cs @@ -15,6 +15,7 @@ namespace ComputerShopDatabaseImplement.Implements public class RequestStorage : IRequestStorage { //id пользователя учитывается в GetFilteredList + //!!!ТУТ ДОБАВИЛ .OrderBy(x => x.DateRequest) public List GetFullList() { using var context = new ComputerShopDatabase(); @@ -23,6 +24,7 @@ namespace ComputerShopDatabaseImplement.Implements .ThenInclude(x => x.Order) .Include(x => x.Assembly) .ToList() + .OrderBy(x => x.DateRequest) .Select(x => x.GetViewModel) .ToList(); } @@ -30,7 +32,7 @@ namespace ComputerShopDatabaseImplement.Implements //Учитывается id пользователя (везде получение списка только тех записей, что создал сам пользователь) public List GetFilteredList(RequestSearchModel model) { using var context = new ComputerShopDatabase(); - + //!!!ТУТ ДОБАВИЛ .OrderBy(x => x.DateRequest) //сортировка по дате создания заявки if (model.DateFrom.HasValue && model.DateTo.HasValue) { @@ -39,6 +41,7 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.Orders) .ThenInclude(x => x.Order) .Include(x => x.Assembly) + .OrderBy(x => x.DateRequest) .Select(x => x.GetViewModel) .ToList(); } @@ -51,6 +54,7 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.Orders) .ThenInclude(x => x.Order) .Include(x => x.Assembly) + .OrderBy(x => x.DateRequest) .Select(x => x.GetViewModel) .ToList(); } @@ -63,6 +67,7 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.Orders) .ThenInclude(x => x.Order) .Include (x => x.Assembly) + .OrderBy(x => x.DateRequest) .Select(x => x.GetViewModel) .ToList(); } @@ -73,6 +78,7 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.Orders) .ThenInclude(x => x.Order) .Include(x => x.Assembly) + .OrderBy(x => x.DateRequest) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs index 11aa5d4..beb2ff0 100644 --- a/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/ShipmentStorage.cs @@ -18,11 +18,12 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFullList() { using var context = new ComputerShopDatabase(); - + //!!!ТУТ ДОБАВИЛ .OrderBy(x => x.DateShipment) return context.Shipments .Include(x => x.Orders) .ThenInclude(x => x.Order) .ToList() + .OrderBy(x => x.DateShipment) .Select(x => x.GetViewModel) .ToList(); } @@ -31,6 +32,7 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFilteredList(ShipmentSearchModel model) { using var context = new ComputerShopDatabase(); + //!!!ТУТ ДОБАВИЛ .OrderBy(x => x.DateShipment) //сортировка по дате поставки if (model.DateFrom.HasValue && model.DateTo.HasValue) { @@ -38,6 +40,7 @@ namespace ComputerShopDatabaseImplement.Implements .Where(x => (x.UserId == model.UserId) && (x.DateShipment >= model.DateFrom && x.DateShipment <= model.DateTo)) .Include(x => x.Orders) .ThenInclude(x => x.Order) + .OrderBy(x => x.DateShipment) .Select(x => x.GetViewModel) .ToList(); } @@ -48,6 +51,7 @@ namespace ComputerShopDatabaseImplement.Implements .Where(x => x.ProviderName == model.ProviderName && x.UserId == model.UserId) .Include(x => x.Orders) .ThenInclude(x => x.Order) + .OrderBy(x => x.DateShipment) .Select(x => x.GetViewModel) .ToList(); } @@ -56,6 +60,7 @@ namespace ComputerShopDatabaseImplement.Implements .Where(x => x.UserId == model.UserId) .Include(x => x.Orders) .ThenInclude(x => x.Order) + .OrderBy(x => x.DateShipment) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopDatabaseImplement/Models/Order.cs index 2b81b1a..4e2878f 100644 --- a/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopDatabaseImplement/Models/Order.cs @@ -60,7 +60,9 @@ namespace ComputerShopDatabaseImplement.Models return; } //DateCreate не обновляю, потому что странно менять дату оформления заказа после его создания + //НА ВСКИЙ ДОБАВИЛ Status = model.Status; + DateCreate = model.DateCreate; } //отдельный метод изменения стоимости заказа (+ или -) на стоимость сборки внутри заявки (после действий с заявками, кот. привязаны к заказу) diff --git a/ComputerShopDatabaseImplement/Models/Request.cs b/ComputerShopDatabaseImplement/Models/Request.cs index d23b86d..86e4b68 100644 --- a/ComputerShopDatabaseImplement/Models/Request.cs +++ b/ComputerShopDatabaseImplement/Models/Request.cs @@ -75,6 +75,7 @@ namespace ComputerShopDatabaseImplement.Models { ClientFIO = model.ClientFIO; } + DateRequest = model.DateRequest; //DateMake не обновляю, потому что странно менять дату оформления заявки после её создания //Обновление ссылки на сборку (assemblyId) отдельным методом } @@ -100,9 +101,11 @@ namespace ComputerShopDatabaseImplement.Models var requestOrders = context.RequestOrders.Where(x => x.RequestId == model.Id).ToList(); //удаление тех заказов, которых нет в модели (+ изменение суммы у удаляемых заказов) + //ИЗМЕНЕНО: удаление всех заказов if (requestOrders != null && requestOrders.Count > 0) { - var delOrders = requestOrders.Where(x => !model.RequestOrders.ContainsKey(x.OrderId)); + //var delOrders = requestOrders.Where(x => !model.RequestOrders.ContainsKey(x.OrderId)); + var delOrders = requestOrders; foreach (var delOrder in delOrders) { context.RequestOrders.Remove(delOrder); diff --git a/ComputerShopDatabaseImplement/Models/Shipment.cs b/ComputerShopDatabaseImplement/Models/Shipment.cs index a0559cc..150669c 100644 --- a/ComputerShopDatabaseImplement/Models/Shipment.cs +++ b/ComputerShopDatabaseImplement/Models/Shipment.cs @@ -87,9 +87,11 @@ namespace ComputerShopDatabaseImplement.Models { var shipmentOrders = context.ShipmentOrders.Where(x => x.ShipmentId == model.Id).ToList(); //удаление тех заказов, которых нет в модели + //ИСПРАВЛЕНО: удаление всех заказов if (shipmentOrders != null && shipmentOrders.Count > 0) { - context.ShipmentOrders.RemoveRange(shipmentOrders.Where(x => !model.ShipmentOrders.ContainsKey(x.OrderId))); + //context.ShipmentOrders.RemoveRange(shipmentOrders.Where(x => !model.ShipmentOrders.ContainsKey(x.OrderId))); + context.ShipmentOrders.RemoveRange(shipmentOrders); context.SaveChanges(); } //добавление новых заказов diff --git a/ComputerShopDatabaseImplement/Models/ShipmentOrder.cs b/ComputerShopDatabaseImplement/Models/ShipmentOrder.cs index 84409cf..a06824c 100644 --- a/ComputerShopDatabaseImplement/Models/ShipmentOrder.cs +++ b/ComputerShopDatabaseImplement/Models/ShipmentOrder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,6 +19,10 @@ namespace ComputerShopDatabaseImplement.Models [Required] public int OrderId { get; set; } + //МБ НАДО ТАК: + //[ForeignKey("OrderId")] + //public virtual Order Order { get; set; } + public virtual Shipment Shipment { get; set; } = new(); public virtual Order Order { get; set; } = new(); } diff --git a/ComputerShopImplementerApp/APIUser.cs b/ComputerShopImplementerApp/APIUser.cs index 9ceff37..4ba33ed 100644 --- a/ComputerShopImplementerApp/APIUser.cs +++ b/ComputerShopImplementerApp/APIUser.cs @@ -1,13 +1,16 @@ using ComputerShopContracts.ViewModels; +using ComputerShopDatabaseImplement.Models; +using ComputerShopDataModels.Models; using Newtonsoft.Json; +using System.Data; using System.Net.Http.Headers; using System.Text; namespace ComputerShopImplementerApp { - public class APIUser - { - private static readonly HttpClient _user = new(); + public class APIUser + { + private static readonly HttpClient _user = new HttpClient { Timeout = TimeSpan.FromMinutes(10) }; public static UserViewModel? User { get; set; } = null; @@ -24,15 +27,73 @@ namespace ComputerShopImplementerApp var result = response.Result.Content.ReadAsStringAsync().Result; if (response.Result.IsSuccessStatusCode) { - return JsonConvert.DeserializeObject(result); - } + // var settings = new JsonSerializerSettings + // { + // TypeNameHandling = TypeNameHandling.All + //}; + + //return JsonConvert.DeserializeObject(result, settings); + return JsonConvert.DeserializeObject(result); + } else { throw new Exception(result); } } - public static void PostRequest(string requestUrl, T model) + public static async Task GetRequestAsync(string requestUrl) + { + var response = await _user.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + + public static async Task GetRequestShipmentAsync(string requestUrl) + { + var response = await _user.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) + { + var settings = new JsonSerializerSettings + { + Converters = new List { new OrderConverter() } + }; + + return JsonConvert.DeserializeObject(result, settings); + } + else + { + throw new Exception(result); + } + } + + public static async Task GetRequestRequestAsync(string requestUrl) + { + var response = await _user.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) + { + var settings = new JsonSerializerSettings + { + Converters = new List { new RequestConverter(), new AssemblyConverter() } + }; + + return JsonConvert.DeserializeObject(result, settings); + } + 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"); @@ -45,5 +106,76 @@ namespace ComputerShopImplementerApp throw new Exception(result); } } - } + + public static async Task PostRequestAsync(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = await _user.PostAsync(requestUrl, data); + + var result = await response.Content.ReadAsStringAsync(); + if (!response.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } + + public class OrderConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(IOrderModel); + //return true; + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return serializer.Deserialize(reader); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + serializer.Serialize(writer, value); + } + } + + public class RequestConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(IRequestModel); + //return true; + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return serializer.Deserialize(reader); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + serializer.Serialize(writer, value); + } + } + + public class AssemblyConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(IAssemblyModel); + //return true; + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return serializer.Deserialize(reader); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + serializer.Serialize(writer, value); + } + } } diff --git a/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj b/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj index cbc510a..a380be2 100644 --- a/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj +++ b/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj @@ -7,11 +7,13 @@ - + + + diff --git a/ComputerShopImplementerApp/Controllers/HomeController.cs b/ComputerShopImplementerApp/Controllers/HomeController.cs index c3557e6..000126b 100644 --- a/ComputerShopImplementerApp/Controllers/HomeController.cs +++ b/ComputerShopImplementerApp/Controllers/HomeController.cs @@ -3,6 +3,9 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using ComputerShopDataModels.Enums; +using ComputerShopDataModels.Models; +using ComputerShopContracts.SearchModels; namespace ComputerShopImplementerApp.Controllers { @@ -24,6 +27,463 @@ namespace ComputerShopImplementerApp.Controllers return View(/*APIUser.GetRequest>($"api/main/getorders?userId={APIUser.User.Id}")*/); } + // ЗАКАЗЫ ЗАКАЗЫ ЗАКАЗЫ ЗАКАЗЫ ЗАКАЗЫ + + //!!!МБ ДОБАВИТЬ [HttpGet] + public IActionResult Orders() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}")); + } + + [HttpGet] + public OrderViewModel GetOrder(int orderId) + { + if (APIUser.User == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIUser.GetRequest($"api/order/getorder?id={orderId}"); + if (result == null) + { + return default; + } + return result; + } + + + + + [HttpGet] + public IActionResult CreateOrder() + { + //!!!ПОТОМ УДАЛИТЬ + //ViewBag.OrderStatuses = APIUser.GetRequest>("api/order/getorderstatuses"); + return View(); + } + + + [HttpPost] + public void CreateOrder(OrderStatus status, DateTime date) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + //if (count <= 0) + //{ + // throw new Exception("Количество и сумма должны быть больше 0"); + //} + APIUser.PostRequest("api/order/createorder", new OrderBindingModel + { + UserId = APIUser.User.Id, + Status = status, + DateCreate = date, + Sum = 0 + }); + Response.Redirect("Orders"); + } + + + + [HttpGet] + public IActionResult UpdateOrder() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + //ViewBag.Statuses = + return View(); + } + + //МБ ПОСТАВИТЬ int? и передавать order.Value + [HttpPost] + public void UpdateOrder(int order, OrderStatus status, DateTime date, double sum) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + if (order == null) + { + throw new Exception("Выберите заказ для изменения"); + } + if (status == null) + { + throw new Exception("Выберите статус для заказа"); + } + //if (count <= 0) + //{ + // throw new Exception("Количество и сумма должны быть больше 0"); + //} + APIUser.PostRequest("api/order/updateorder", new OrderBindingModel + { + Id = order, + UserId = APIUser.User.Id, + Status = status, + DateCreate = date, + Sum = sum + }); + Response.Redirect("Orders"); + } + + + [HttpGet] + public IActionResult DeleteOrder() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + //ViewBag.Statuses = + return View(); + } + + [HttpPost] + public void DeleteOrder(int order) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + //if (count <= 0) + //{ + // throw new Exception("Количество и сумма должны быть больше 0"); + //} + APIUser.PostRequest("api/order/deleteorder", new OrderBindingModel + { + Id = order + }); + Response.Redirect("Orders"); + } + + + + + + // ПАРТИИ ТОВАРОВ ПАРТИИ ТОВАРОВ ПАРТИИ ТОВАРОВ ПАРТИИ ТОВАРОВ ПАРТИИ ТОВАРОВ + + public async Task Shipments() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + var shipments = await APIUser.GetRequestShipmentAsync>($"api/shipment/getshipments?userId={APIUser.User.Id}"); + + return View(shipments); + } + + [HttpGet] + public async Task GetShipment(int shipmentId) + { + if (APIUser.User == null) + { + throw new Exception("Необходима авторизация"); + } + //GetRequestShipmentAsync + var result = await APIUser.GetRequestShipmentAsync($"api/shipment/getshipment?id={shipmentId}"); + if (result == null) + { + return default; + } + return result; + } + + + [HttpGet] + public IActionResult CreateShipment() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + return View(); + } + + + [HttpPost] + public void CreateShipment(string providerName, DateTime date, int[] orders) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + // Создаем словарь из выбранных заказов + var selectedOrders = new Dictionary(); + foreach (var orderId in orders) + { + selectedOrders.Add(orderId, new OrderSearchModel { Id = orderId } as IOrderModel); + //var orderModel = APIUser.GetRequest($"api/order/getorder?id={orderId}"); + //selectedOrders.Add(orderId, orderModel); + } + + APIUser.PostRequest("api/shipment/createshipment", new ShipmentBindingModel + { + UserId = APIUser.User.Id, + ProviderName = providerName, + DateShipment = date, + ShipmentOrders = selectedOrders + }); + Response.Redirect("Shipments"); + } + + + //!!!МБ СДЕЛАТЬ ПО АНАЛОГИИ С public async Task Shipments() + [HttpGet] + public async Task UpdateShipment() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Shipments = await APIUser.GetRequestShipmentAsync>($"api/shipment/getshipments?userId={APIUser.User.Id}"); + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + return View(); + } + + [HttpPost] + public void UpdateShipment(int shipment, string providerName, DateTime date, int[] orders) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + // Создаем словарь из выбранных заказов + var selectedOrders = new Dictionary(); + foreach (var orderId in orders) + { + selectedOrders.Add(orderId, new OrderSearchModel { Id = orderId } as IOrderModel); + } + + APIUser.PostRequest("api/shipment/updateshipment", new ShipmentBindingModel + { + Id = shipment, + UserId = APIUser.User.Id, + ProviderName = providerName, + DateShipment = date, + ShipmentOrders = selectedOrders + }); + Response.Redirect("Shipments"); + } + + [HttpGet] + public async Task DeleteShipment() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Shipments = await APIUser.GetRequestShipmentAsync>($"api/shipment/getshipments?userId={APIUser.User.Id}"); + return View(); + } + + + //[HttpPost] + //public void DeleteShipment(int shipment) + //{ + // if (APIUser.User == null) + // { + // throw new Exception("Вход только авторизованным"); + // } + // APIUser.PostRequest("api/shipment/deleteshipment", new ShipmentBindingModel + // { + // Id = shipment + // }); + // Response.Redirect("Shipments"); + //} + + + [HttpPost] + public async Task DeleteShipment(int shipment) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + await APIUser.PostRequestAsync("api/shipment/deleteshipment", new ShipmentBindingModel + { + Id = shipment + }); + return RedirectToAction("Shipments"); + } + + + + + // ЗАЯВКИ НА СБОРКИ ЗАЯВКИ НА СБОРКИ ЗАЯВКИ НА СБОРКИ ЗАЯВКИ НА СБОРКИ ЗАЯВКИ НА СБОРКИ + + + //public IActionResult Requests() + //{ + // if (APIUser.User == null) + // { + // return Redirect("~/Home/Enter"); + // } + // return View(APIUser.GetRequest>($"api/request/getrequests?userId={APIUser.User.Id}")); + //} + + + //МБ ТАК Requests + public async Task Requests() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + var requests = await APIUser.GetRequestRequestAsync>($"api/request/getrequests?userId={APIUser.User.Id}"); + //var shipments = await APIUser.GetRequestShipmentAsync>($"api/shipment/getshipments?userId={APIUser.User.Id}"); + + return View(requests); + } + + + [HttpGet] + public async Task GetRequest(int requestId) + { + if (APIUser.User == null) + { + throw new Exception("Необходима авторизация"); + } + //GetRequestShipmentAsync + var result = await APIUser.GetRequestRequestAsync($"api/request/getrequest?id={requestId}"); + if (result == null) + { + return default; + } + return result; + } + + + + [HttpGet] + public IActionResult CreateRequest() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + return View(); + } + + + [HttpPost] + public void CreateRequest(string clientFIO, DateTime date, int[] orders) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + // Создаем словарь из выбранных заказов + var selectedOrders = new Dictionary(); + foreach (var orderId in orders) + { + selectedOrders.Add(orderId, new OrderSearchModel { Id = orderId } as IOrderModel); + } + + APIUser.PostRequest("api/request/createrequest", new RequestBindingModel + { + UserId = APIUser.User.Id, + ClientFIO = clientFIO, + DateRequest = date, + RequestOrders = selectedOrders + }); + Response.Redirect("Requests"); + } + + + [HttpGet] + public async Task UpdateRequest() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Requests = await APIUser.GetRequestRequestAsync>($"api/request/getrequests?userId={APIUser.User.Id}"); + ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + return View(); + } + + [HttpPost] + public void UpdateRequest(int request, string clientFIO, DateTime date, int[] orders) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + // Создаем словарь из выбранных заказов + var selectedOrders = new Dictionary(); + foreach (var orderId in orders) + { + selectedOrders.Add(orderId, new OrderSearchModel { Id = orderId } as IOrderModel); + } + + APIUser.PostRequest("api/request/updaterequest", new RequestBindingModel + { + Id = request, + UserId = APIUser.User.Id, + ClientFIO = clientFIO, + DateRequest = date, + RequestOrders = selectedOrders + }); + Response.Redirect("Requests"); + } + + + [HttpGet] + public async Task ConnectRequestAssembly() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Requests = await APIUser.GetRequestRequestAsync>($"api/request/getrequests?userId={APIUser.User.Id}"); + //ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + ViewBag.Assemblies = APIUser.GetRequest>($"api/") + return View(); + } + + + + + + + [HttpGet] + public async Task DeleteRequest() + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + ViewBag.Requests = await APIUser.GetRequestRequestAsync>($"api/request/getrequests?userId={APIUser.User.Id}"); + return View(); + } + + [HttpPost] + public async Task DeleteRequest(int request) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + await APIUser.PostRequestAsync("api/request/deleterequest", new RequestBindingModel + { + Id = request + }); + return RedirectToAction("Requests"); + } + + + // ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ + [HttpGet] public IActionResult Privacy() { diff --git a/ComputerShopImplementerApp/Program.cs b/ComputerShopImplementerApp/Program.cs index 9260ebb..71b858d 100644 --- a/ComputerShopImplementerApp/Program.cs +++ b/ComputerShopImplementerApp/Program.cs @@ -1,7 +1,29 @@ +using ComputerShopBusinessLogic.BusinessLogics; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; +using ComputerShopDatabaseImplement.Implements; +using ComputerShopDatabaseImplement.Models; +using ComputerShopDataModels.Models; using ComputerShopImplementerApp; var builder = WebApplication.CreateBuilder(args); +//builder.Services.AddTransient(); +//builder.Services.AddTransient(); +//builder.Services.AddTransient(); +//builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + // Add services to the container. builder.Services.AddControllersWithViews(); diff --git a/ComputerShopImplementerApp/Views/Home/ConnectRequestAssembly.cshtml b/ComputerShopImplementerApp/Views/Home/ConnectRequestAssembly.cshtml new file mode 100644 index 0000000..0c66490 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/ConnectRequestAssembly.cshtml @@ -0,0 +1,100 @@ +@{ + ViewData["Title"] = "Connect request with assembly"; +} +
+

Связывание заявки со сборкой

+
+
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+
+ +
+ + +
+
+ + +
+ +
+
+ + @* !!!МБ УБРАТЬ disabled *@ + +
+ +
+ +
+
+
+
+
+ + + diff --git a/ComputerShopImplementerApp/Views/Home/CreateOrder.cshtml b/ComputerShopImplementerApp/Views/Home/CreateOrder.cshtml new file mode 100644 index 0000000..67ac356 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/CreateOrder.cshtml @@ -0,0 +1,61 @@ +@using ComputerShopDataModels.Enums; +@{ + ViewData["Title"] = "Create order"; +} +
+

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

+
+
+
+
Статус заказа:
+
+ + @* !!!ПОТОМ УДАЛИТЬ *@ + @* *@ +
+
+
+
Дата создания:
+
+
+
+
Сумма:
+
+
+
+
+
+
+
+ +@* !!!МБ НАДО БУДЕТ *@ +@* *@ diff --git a/ComputerShopImplementerApp/Views/Home/CreateRequest.cshtml b/ComputerShopImplementerApp/Views/Home/CreateRequest.cshtml new file mode 100644 index 0000000..d95c720 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/CreateRequest.cshtml @@ -0,0 +1,49 @@ +@{ + ViewData["Title"] = "Create request"; +} +
+

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

+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ +@* !!!МБ НАДО БУДЕТ *@ + + diff --git a/ComputerShopImplementerApp/Views/Home/CreateShipment.cshtml b/ComputerShopImplementerApp/Views/Home/CreateShipment.cshtml new file mode 100644 index 0000000..fbde002 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/CreateShipment.cshtml @@ -0,0 +1,48 @@ +@{ + ViewData["Title"] = "Create shipment"; +} +
+

Создание партии товаров

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ +@* !!!МБ НАДО БУДЕТ *@ + + diff --git a/ComputerShopImplementerApp/Views/Home/DeleteOrder.cshtml b/ComputerShopImplementerApp/Views/Home/DeleteOrder.cshtml new file mode 100644 index 0000000..021ccad --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/DeleteOrder.cshtml @@ -0,0 +1,94 @@ +@using ComputerShopDataModels.Enums; +@{ + ViewData["Title"] = "Update order"; +} + +
+
+

Удаление заказа

+
+
+ + + @**@ +
+
+ + @* *@ + +
+ @*
+
Статус заказа:
+
+ +
+
*@ +
+ + @*
*@@*
*@ +
+ @*
+
Дата создания:
+
+
*@ +
+ + @*
*@ + +
+ @*
+
Сумма:
+
+
*@ +
+
+
+
+
+ + + + diff --git a/ComputerShopImplementerApp/Views/Home/DeleteRequest.cshtml b/ComputerShopImplementerApp/Views/Home/DeleteRequest.cshtml new file mode 100644 index 0000000..a817718 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/DeleteRequest.cshtml @@ -0,0 +1,81 @@ +@{ + ViewData["Title"] = "Delete request"; +} +
+

Удаление заявки

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+
+
+ + + + diff --git a/ComputerShopImplementerApp/Views/Home/DeleteShipment.cshtml b/ComputerShopImplementerApp/Views/Home/DeleteShipment.cshtml new file mode 100644 index 0000000..7b9164f --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/DeleteShipment.cshtml @@ -0,0 +1,80 @@ +@{ + ViewData["Title"] = "Delete shipment"; +} +
+

Удаление партии товаров

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+
+
+ + + diff --git a/ComputerShopImplementerApp/Views/Home/Orders.cshtml b/ComputerShopImplementerApp/Views/Home/Orders.cshtml new file mode 100644 index 0000000..0b2a852 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/Orders.cshtml @@ -0,0 +1,66 @@ +@using ComputerShopContracts.ViewModels + +@model List +@* !!!ТУТ СКОРЕЕ ВСЕГО НАДО ПОМЕНЯТЬ *@ +@{ + ViewData["Title"] = "Orders"; +} + +
+

Заказы

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать заказ + Обновить заказ + Удалить заказ +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + Дата создания + + Статус + + Сумма +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.Status) + + @Html.DisplayFor(modelItem => item.Sum) +
+ } +
+ diff --git a/ComputerShopImplementerApp/Views/Home/Requests.cshtml b/ComputerShopImplementerApp/Views/Home/Requests.cshtml new file mode 100644 index 0000000..bffba7d --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/Requests.cshtml @@ -0,0 +1,75 @@ +@using ComputerShopContracts.ViewModels + +@model List +@* !!!ТУТ СКОРЕЕ ВСЕГО НАДО ПОМЕНЯТЬ *@ +@{ + ViewData["Title"] = "Requests"; +} + +
+

Заявки на сборки

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + // !!!ДОБАВИТЬ ЭТИ МЕТОДЫ В HOME КОНТРОЛЛЕР И ТАКИЕ ЖЕ СТРАНИЦЫ +

+ Создать заявку + Связать заявку со сборкой + Обновить заявку + Удалить заявку +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Номер + + Дата оформления + + ФИО клиента-заявителя + + Название сборки + + Стоимость сборки +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.DateRequest) + + @Html.DisplayFor(modelItem => item.ClientFIO) + + @Html.DisplayFor(modelItem => item.Assembly.AssemblyName) + + @Html.DisplayFor(modelItem => item.Assembly.Price) +
+ } +
+ + diff --git a/ComputerShopImplementerApp/Views/Home/Shipments.cshtml b/ComputerShopImplementerApp/Views/Home/Shipments.cshtml new file mode 100644 index 0000000..544e6fe --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/Shipments.cshtml @@ -0,0 +1,62 @@ +@using ComputerShopContracts.ViewModels + +@model List +@* !!!ТУТ СКОРЕЕ ВСЕГО НАДО ПОМЕНЯТЬ *@ +@{ + ViewData["Title"] = "Shipments"; +} + +
+

Партии товаров

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + // !!!ДОБАВИТЬ ЭТИ МЕТОДЫ В HOME КОНТРОЛЛЕР И ТАКИЕ ЖЕ СТРАНИЦЫ +

+ Создать партию товаров + Обновить партию товаров + Удалить партию товаров +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Поставщик + + Дата поставки +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.ProviderName) + + @Html.DisplayFor(modelItem => item.DateShipment) +
+ } +
+ + diff --git a/ComputerShopImplementerApp/Views/Home/UpdateOrder.cshtml b/ComputerShopImplementerApp/Views/Home/UpdateOrder.cshtml new file mode 100644 index 0000000..721ad72 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/UpdateOrder.cshtml @@ -0,0 +1,107 @@ +@using ComputerShopDataModels.Enums; +@{ + ViewData["Title"] = "Update order"; +} + +
+
+

Изменение заказа

+
+
+ + + @**@ +
+
+ +
+ +
+
+
+ + @* *@ + +
+@*
+
Статус заказа:
+
+ +
+
*@ +
+ + +
+@*
+
Дата создания:
+
+
*@ +
+ + @*
*@ + +
+@*
+
Сумма:
+
+
*@ +
+
+
+
+
+ + + diff --git a/ComputerShopImplementerApp/Views/Home/UpdateRequest.cshtml b/ComputerShopImplementerApp/Views/Home/UpdateRequest.cshtml new file mode 100644 index 0000000..c5e524c --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/UpdateRequest.cshtml @@ -0,0 +1,96 @@ +@{ + ViewData["Title"] = "Update request"; +} +
+

Изменение заявки

+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+
+
+ + @* !!!МБ УБРАТЬ disabled *@ + +
+
+ +
+ +
+
+
+
+
+ + + diff --git a/ComputerShopImplementerApp/Views/Home/UpdateShipment.cshtml b/ComputerShopImplementerApp/Views/Home/UpdateShipment.cshtml new file mode 100644 index 0000000..7517363 --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/UpdateShipment.cshtml @@ -0,0 +1,103 @@ +@{ + ViewData["Title"] = "Update shipment"; +} +
+

Изменение партии товаров

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + @* !!!МБ УБРАТЬ disabled *@ + +
+
+ +
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml b/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml index c6dc9c6..415e4fa 100644 --- a/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml @@ -17,10 +17,20 @@ + @* !!!Тут изменять asp-action и мб удалить "Личные данные" *@