From 429a35d86816b2739e456bd7ff79ada6dcfe5e98 Mon Sep 17 00:00:00 2001 From: tellsense Date: Fri, 3 May 2024 22:00:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 3 +- .../Views/Home/Create.cshtml | 87 ++++++------ .../SushiBarClientApp/Views/Home/Index.cshtml | 134 +++++++++--------- .../ViewModels/OrderViewModel.cs | 5 +- SushiBar/SushiBarDataModels/IOrderModel.cs | 3 +- SushiBar/SushiBarDatabaseImplement/Order.cs | 14 +- SushiBar/SushiBarFileImplement/Order.cs | 15 +- .../SushiBarFileImplement/OrderStorage.cs | 47 ++++-- SushiBar/SushiBarListImplement/Order.cs | 9 +- .../SushiBarListImplement/OrderStorage.cs | 75 +++++++--- 10 files changed, 238 insertions(+), 154 deletions(-) diff --git a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs index 72b6a75..eb4a3b7 100644 --- a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs @@ -112,8 +112,7 @@ namespace SushiBarClientApp.Controllers [HttpGet] public IActionResult Create() { - ViewBag.Sushis = - APIClient.GetRequest>("api/main/getsushilist"); + ViewBag.Sushis = APIClient.GetRequest>("api/main/getsushilist"); return View(); } [HttpPost] diff --git a/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml index 97dda8d..06a2e11 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml @@ -1,53 +1,50 @@ @{ - ViewData["Title"] = "Create"; + ViewData["Title"] = "Create"; }
-

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

+

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

-
-
Изделие:
-
- -
-
-
-
Количество:
-
- -
-
-
-
Сумма:
-
- -
-
-
-
-
- -
-
+
+
Изделие:
+
+ +
+
+
+
Количество:
+
+
+
+
Сумма:
+
+
+
+
+
+
+ diff --git a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml index 4a2092c..843135f 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml @@ -1,75 +1,75 @@ @using SushiBarContracts.ViewModels + @model List + @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "Home Page"; } +
-

Заказы

+

Заказы

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

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

- return; - } -

- Создать заказ -

- - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - - } - -
- Номер - - Изделие - - Дата создания - - Количество - - Сумма - - Статус -
- @Html.DisplayFor(modelItem => - item.Id) - - @Html.DisplayFor(modelItem => - item.SushiName) - - @Html.DisplayFor(modelItem => - item.DateCreate) - - @Html.DisplayFor(modelItem => - item.Count) - - @Html.DisplayFor(modelItem => - item.Sum) - - @Html.DisplayFor(modelItem => - item.Status) -
- } + @{ + if (Model == null) + { +

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

+ return; + } + +

+ Создать заказ +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Номер + + Суши + + Дата создания + + Количество + + Сумма + + Статус +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.SushiName) + + @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/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index ec4c5a3..660e18d 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -13,7 +13,10 @@ namespace SushiBarContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int SushiId { get; set; } + public int ClientId { get; set; } + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + public int SushiId { get; set; } [DisplayName("Изделие")] public string SushiName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/SushiBar/SushiBarDataModels/IOrderModel.cs b/SushiBar/SushiBarDataModels/IOrderModel.cs index 14265bd..d68fbfa 100644 --- a/SushiBar/SushiBarDataModels/IOrderModel.cs +++ b/SushiBar/SushiBarDataModels/IOrderModel.cs @@ -10,7 +10,8 @@ namespace SushiBarDataModels.Models public interface IOrderModel : IId { int SushiId { get; } - int Count { get; } + int ClientId { get; } + int Count { get; } double Sum { get; } OrderStatus Status { get; } DateTime DateCreate { get; } diff --git a/SushiBar/SushiBarDatabaseImplement/Order.cs b/SushiBar/SushiBarDatabaseImplement/Order.cs index caec16c..0d8b10a 100644 --- a/SushiBar/SushiBarDatabaseImplement/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Order.cs @@ -9,8 +9,12 @@ namespace SushiBarDatabaseImplement.Models public class Order : IOrderModel { public int Id { get; private set; } + [Required] + public int ClientId { get; private set; } - [Required] + public virtual Client Client { get; private set; } = new(); + + [Required] public int SushiId { get; private set; } public virtual Sushi Sushi { get; set; } = new(); @@ -34,7 +38,9 @@ namespace SushiBarDatabaseImplement.Models return new Order() { Id = model.Id, - SushiId = model.SushiId, + ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), + SushiId = model.SushiId, Sushi = context.Sushis.First(x => x.Id == model.SushiId), Count = model.Count, Sum = model.Sum, @@ -57,7 +63,9 @@ namespace SushiBarDatabaseImplement.Models public OrderViewModel GetViewModel => new() { Id = Id, - SushiId = SushiId, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, + SushiId = SushiId, SushiName = Sushi.SushiName, Count = Count, Sum = Sum, diff --git a/SushiBar/SushiBarFileImplement/Order.cs b/SushiBar/SushiBarFileImplement/Order.cs index aedeec5..c9916cb 100644 --- a/SushiBar/SushiBarFileImplement/Order.cs +++ b/SushiBar/SushiBarFileImplement/Order.cs @@ -14,7 +14,8 @@ namespace SushiBarFileImplement.Models internal class Order : IOrderModel { public int Id { get; private set; } - public int SushiId { get; private set; } + public int ClientId { get; private set; } + public int SushiId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -31,7 +32,8 @@ namespace SushiBarFileImplement.Models { Id = model.Id, SushiId = model.SushiId, - Count = model.Count, + ClientId = model.ClientId, + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -50,7 +52,8 @@ namespace SushiBarFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), @@ -73,7 +76,8 @@ namespace SushiBarFileImplement.Models { Id = Id, SushiId = SushiId, - Count = Count, + ClientId = ClientId, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, @@ -83,7 +87,8 @@ namespace SushiBarFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("SushiId", SushiId.ToString()), - new XElement("Count", Count.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), diff --git a/SushiBar/SushiBarFileImplement/OrderStorage.cs b/SushiBar/SushiBarFileImplement/OrderStorage.cs index 0ffab27..e9c9142 100644 --- a/SushiBar/SushiBarFileImplement/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/OrderStorage.cs @@ -22,16 +22,27 @@ namespace SushiBarFileImplement.Implements public List GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList(); - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachSushiName(x.GetViewModel)).ToList(); - } + public List GetFilteredList(OrderSearchModel model) + { + if (model.DateFrom.HasValue) + { + return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)).ToList(); + } - public OrderViewModel? GetElement(OrderSearchModel model) + if (model.ClientId.HasValue && !model.Id.HasValue) + { + return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } + + if (model.Id.HasValue) + { + return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); + } + return new(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) { @@ -39,8 +50,24 @@ namespace SushiBarFileImplement.Implements } return AttachSushiName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; - public OrderViewModel? Insert(OrderBindingModel model) + var sushi = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId); + var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (sushi != null) + { + viewModel.SushiName = sushi.SushiName; + } + if (client != null) + { + viewModel.ClientFIO = client.ClientFIO; + } + return viewModel; + } + public OrderViewModel? Insert(OrderBindingModel model) { model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; var newOrder = Order.Create(model); diff --git a/SushiBar/SushiBarListImplement/Order.cs b/SushiBar/SushiBarListImplement/Order.cs index f1d69d4..cc64f35 100644 --- a/SushiBar/SushiBarListImplement/Order.cs +++ b/SushiBar/SushiBarListImplement/Order.cs @@ -14,7 +14,8 @@ namespace SushiBarListImplement.Models { public int Id { get; private set; } public int SushiId { get; private set; } - public int Count { get; private set; } + public int ClientId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; @@ -30,7 +31,8 @@ namespace SushiBarListImplement.Models { Id = model.Id, SushiId = model.SushiId, - Count = model.Count, + ClientId = model.ClientId, + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -52,7 +54,8 @@ namespace SushiBarListImplement.Models { Id = Id, SushiId = SushiId, - Count = Count, + ClientId = ClientId, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/SushiBar/SushiBarListImplement/OrderStorage.cs b/SushiBar/SushiBarListImplement/OrderStorage.cs index 957b9fa..e511276 100644 --- a/SushiBar/SushiBarListImplement/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/OrderStorage.cs @@ -30,24 +30,65 @@ namespace SushiBarListImplement.Implements return result; } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - if (model == null || !model.Id.HasValue) - { - return result; - } - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - result.Add(AttachSushiName(order.GetViewModel)); - } - } - return result; - } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.DateFrom.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + } + } + return result; + } - public OrderViewModel? GetElement(OrderSearchModel model) + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var package in _source.Sushis) + { + if (package.Id == order.SushiId) + { + viewModel.SushiName = package.SushiName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; + } + + public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) {