From 8088518d83d7753ea415cf5c3f60ea710127a30f Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 17 May 2023 16:59:48 +0300 Subject: [PATCH] partially made graphics --- .../BusinessLogics/GraphicLogic.cs | 50 ++++++++++++++ .../BusinessLogicsContracts/IGraphicLogic.cs | 16 +++++ .../ViewModels/GraphicViewModel.cs | 19 ++++++ .../Models/ProductCook.cs | 2 +- .../Controllers/HomeController.cs | 12 +++- .../Views/Home/Graphic.cshtml | 68 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 3 + .../Controllers/MainController.cs | 15 +++- Canteen/CanteenRestApi/Program.cs | 2 +- 9 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs create mode 100644 Canteen/CanteenContracts/BusinessLogicsContracts/IGraphicLogic.cs create mode 100644 Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs create mode 100644 Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs new file mode 100644 index 0000000..fd9ca7f --- /dev/null +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs @@ -0,0 +1,50 @@ +using CanteenContracts.BindingModels; +using CanteenContracts.BusinessLogicsContracts; +using CanteenContracts.StoragesContracts; +using CanteenContracts.View; +using CanteenContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenBusinessLogic.BusinessLogics +{ + public class GraphicLogic : IGraphicLogic + { + private readonly IProductStorage _educationStorage; + + public GraphicLogic(IProductStorage educationStorage) + { + _educationStorage = educationStorage; + } + + public GraphicViewModel GetGraphicByPrice() + { + return new GraphicViewModel + { + Title = "Диаграмма выполненных заказов каждым поваром", + ColumnName = "Повара", + ValueName = "Количество заказов", + Data = GetEducation().Select(rec => new Tuple(rec.ProductName, Convert.ToInt32(rec.Price))).ToList() + }; + } + + public GraphicViewModel GetGraphicByCount() + { + return new GraphicViewModel + { + Title = "Диаграмма продаваемости блюд", + ColumnName = "Блюда", + ValueName = "Количество блюд", + Data = GetEducation().Select(rec => new Tuple(rec.ProductName, rec.Price)).ToList() + }; + } + + private List GetEducation() + { + return _educationStorage.GetFullList(); + } + } +} diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IGraphicLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IGraphicLogic.cs new file mode 100644 index 0000000..868c9a2 --- /dev/null +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IGraphicLogic.cs @@ -0,0 +1,16 @@ +using CanteenContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.BusinessLogicsContracts +{ + public interface IGraphicLogic + { + public GraphicViewModel GetGraphicByPrice(); + + public GraphicViewModel GetGraphicByCount(); + } +} diff --git a/Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs b/Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs new file mode 100644 index 0000000..843a1cb --- /dev/null +++ b/Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.ViewModels +{ + public class GraphicViewModel + { + public string ColumnName { get; set; } + + public string ValueName { get; set; } + + public string Title { get; set; } + + public List> Data { get; set; } + } +} diff --git a/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs b/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs index 8b736b7..95fffc7 100644 --- a/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs +++ b/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs @@ -10,7 +10,7 @@ namespace CanteenDatabaseImplement.Models { public class ProductCook { - public int Id { get; set; } + public int Id { get; private set; } [Required] public int ProductId { get; set; } diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index 9d02571..edd5017 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -1,6 +1,7 @@ using CanteenContracts.BindingModels; using CanteenContracts.SearchModel; using CanteenContracts.View; +using CanteenContracts.ViewModels; using CanteenDatabaseImplement.Models; using CanteenDataModels.Models; using CanteenManagerApp.Models; @@ -363,6 +364,15 @@ namespace CanteenManagerApp.Controllers }); Response.Redirect("Dishes"); } - + [HttpGet] + public IActionResult Graphic() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Model = APIClient.GetRequest>($"api/main/GetGraphic"); + return View(); + } } } \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml b/Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml new file mode 100644 index 0000000..907a137 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml @@ -0,0 +1,68 @@ +@using System.Web; + +@{ + ViewData["Title"] = "Diagram"; +} + +
+
+
+
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } +} + + + \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml index 3dd3783..c3faac9 100644 --- a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml +++ b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml @@ -34,6 +34,9 @@ + diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index 131414e..f165514 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -1,7 +1,9 @@ +using CanteenBusinessLogic.BusinessLogics; using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.View; +using CanteenContracts.ViewModels; using CanteenDataModels.Models; using Microsoft.AspNetCore.Mvc; @@ -16,14 +18,16 @@ namespace CanteenRestApi.Controllers private readonly IDishLogic _dish; private readonly IProductLogic _product; private readonly ITablewareLogic _tableware; + private readonly IGraphicLogic _gl; - public MainController(ILogger logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware) + public MainController(ILogger logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware, IGraphicLogic gl) { _logger = logger; _cook = cook; _dish = dish; _product = product; _tableware = tableware; + _gl = gl; } [HttpGet] @@ -146,5 +150,14 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpGet] + public GraphicViewModel[] GetGraphic() + { + return new GraphicViewModel[] + { + _gl.GetGraphicByCount(), + _gl.GetGraphicByPrice() + }; + } } } \ No newline at end of file diff --git a/Canteen/CanteenRestApi/Program.cs b/Canteen/CanteenRestApi/Program.cs index 115a7d2..868c60d 100644 --- a/Canteen/CanteenRestApi/Program.cs +++ b/Canteen/CanteenRestApi/Program.cs @@ -21,7 +21,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); - +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();