partially made graphics
This commit is contained in:
parent
35aef0cdb5
commit
8088518d83
50
Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs
Normal file
50
Canteen/CanteenBusinessLogic/BusinessLogics/GraphicLogic.cs
Normal file
@ -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<string, double>(rec.ProductName, Convert.ToInt32(rec.Price))).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraphicViewModel GetGraphicByCount()
|
||||||
|
{
|
||||||
|
return new GraphicViewModel
|
||||||
|
{
|
||||||
|
Title = "Диаграмма продаваемости блюд",
|
||||||
|
ColumnName = "Блюда",
|
||||||
|
ValueName = "Количество блюд",
|
||||||
|
Data = GetEducation().Select(rec => new Tuple<string, double>(rec.ProductName, rec.Price)).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ProductViewModel> GetEducation()
|
||||||
|
{
|
||||||
|
return _educationStorage.GetFullList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
19
Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs
Normal file
19
Canteen/CanteenContracts/ViewModels/GraphicViewModel.cs
Normal file
@ -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<Tuple<string, double>> Data { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public class ProductCook
|
public class ProductCook
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using CanteenContracts.BindingModels;
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenContracts.ViewModels;
|
||||||
using CanteenDatabaseImplement.Models;
|
using CanteenDatabaseImplement.Models;
|
||||||
using CanteenDataModels.Models;
|
using CanteenDataModels.Models;
|
||||||
using CanteenManagerApp.Models;
|
using CanteenManagerApp.Models;
|
||||||
@ -363,6 +364,15 @@ namespace CanteenManagerApp.Controllers
|
|||||||
});
|
});
|
||||||
Response.Redirect("Dishes");
|
Response.Redirect("Dishes");
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Graphic()
|
||||||
|
{
|
||||||
|
if (APIClient.Manager == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Model = APIClient.GetRequest<List<GraphicViewModel>>($"api/main/GetGraphic");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
68
Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml
Normal file
68
Canteen/CanteenManagerApp/Views/Home/Graphic.cshtml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
@using System.Web;
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Diagram";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<form asp-action="Index">
|
||||||
|
<div id="Count"></div>
|
||||||
|
<div id="Price"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@{
|
||||||
|
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
google.charts.load('current', { 'packages': ['corechart'] });
|
||||||
|
google.charts.setOnLoadCallback(Count);
|
||||||
|
google.charts.setOnLoadCallback(Price);
|
||||||
|
@if (ViewBag.Model != null)
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
function Count() {
|
||||||
|
var data = new google.visualization.DataTable();
|
||||||
|
data.addColumn('string', '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[0].ColumnName))');
|
||||||
|
data.addColumn('number', '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[0].ValueName))');
|
||||||
|
@foreach (var row in ViewBag.Model[0].Data)
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
data.addRow(['@Html.Raw(HttpUtility.JavaScriptStringEncode(row.Item1))', @row.Item2]);
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
var options = {
|
||||||
|
'title': '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[0].Title))',
|
||||||
|
'width': 1200,
|
||||||
|
'height': 900
|
||||||
|
};
|
||||||
|
var chart = new google.visualization.PieChart(document.getElementById('Count'));
|
||||||
|
|
||||||
|
console.log(options);
|
||||||
|
chart.draw(data, options);
|
||||||
|
}
|
||||||
|
function Price() {
|
||||||
|
var data = new google.visualization.DataTable();
|
||||||
|
data.addColumn('string', '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[1].ColumnName))');
|
||||||
|
data.addColumn('number', '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[1].ValueName))');
|
||||||
|
@foreach (var row in ViewBag.Model[1].Data)
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
data.addRow(['@Html.Raw(HttpUtility.JavaScriptStringEncode(row.Item1))', @row.Item2]);
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
var options = {
|
||||||
|
'title': '@Html.Raw(HttpUtility.JavaScriptStringEncode(ViewBag.Model[1].Title))',
|
||||||
|
'width': 1200,
|
||||||
|
'height': 900
|
||||||
|
};
|
||||||
|
var chart = new google.visualization.ColumnChart(document.getElementById('Price'));
|
||||||
|
chart.draw(data, options);
|
||||||
|
}
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
</script>
|
@ -34,6 +34,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Graphic">Графики</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
using CanteenBusinessLogic.BusinessLogics;
|
||||||
using CanteenContracts.BindingModels;
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.BusinessLogicsContracts;
|
using CanteenContracts.BusinessLogicsContracts;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenContracts.ViewModels;
|
||||||
using CanteenDataModels.Models;
|
using CanteenDataModels.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -16,14 +18,16 @@ namespace CanteenRestApi.Controllers
|
|||||||
private readonly IDishLogic _dish;
|
private readonly IDishLogic _dish;
|
||||||
private readonly IProductLogic _product;
|
private readonly IProductLogic _product;
|
||||||
private readonly ITablewareLogic _tableware;
|
private readonly ITablewareLogic _tableware;
|
||||||
|
private readonly IGraphicLogic _gl;
|
||||||
|
|
||||||
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware)
|
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware, IGraphicLogic gl)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_cook = cook;
|
_cook = cook;
|
||||||
_dish = dish;
|
_dish = dish;
|
||||||
_product = product;
|
_product = product;
|
||||||
_tableware = tableware;
|
_tableware = tableware;
|
||||||
|
_gl = gl;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -146,5 +150,14 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public GraphicViewModel[] GetGraphic()
|
||||||
|
{
|
||||||
|
return new GraphicViewModel[]
|
||||||
|
{
|
||||||
|
_gl.GetGraphicByCount(),
|
||||||
|
_gl.GetGraphicByPrice()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ builder.Services.AddTransient<ICookLogic, CookLogic>();
|
|||||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
builder.Services.AddTransient<IDishLogic, DishLogic>();
|
builder.Services.AddTransient<IDishLogic, DishLogic>();
|
||||||
builder.Services.AddTransient<ITablewareLogic, TablewareLogic>();
|
builder.Services.AddTransient<ITablewareLogic, TablewareLogic>();
|
||||||
|
builder.Services.AddTransient<IGraphicLogic, GraphicLogic>();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
Loading…
Reference in New Issue
Block a user