+привязка и подготовка к отчетам

This commit is contained in:
Алексей Тихоненков 2024-08-27 15:39:57 +04:00
parent 5e83a249b6
commit 436bb27344
6 changed files with 181 additions and 6 deletions

View File

@ -46,13 +46,13 @@ namespace DiningRoomRestApi.Controllers
}
[HttpGet]
public List<OrderViewModel>? GetOrderList(int Id)
public List<OrderViewModel>? GetOrderList(int UserId)
{
try
{
return _order.ReadList(new OrderSearchModel
{
Id = Id,
UserId = UserId,
});
}
catch (Exception ex)
@ -397,5 +397,21 @@ namespace DiningRoomRestApi.Controllers
throw;
}
}
}
[HttpGet]
public ProductViewModel GetProductById(int productId)
{
try
{
var elem = _product.ReadElement(new ProductSearchModel { Id = productId });
if (elem == null)
return null;
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения по id={Id}", productId);
throw;
}
}
}
}

View File

@ -15,6 +15,7 @@ using System.Globalization;
using System.Numerics;
using DiningRoomDataModels.Enums;
using System.Reflection;
using DocumentFormat.OpenXml.Office2010.Excel;
namespace DiningRoomUserApp.Controllers
{
@ -357,6 +358,101 @@ namespace DiningRoomUserApp.Controllers
});
Response.Redirect("Drinks");
}
[HttpGet]
public IActionResult AddProductToOrder()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Orders = APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorderlist?UserId={APIClient.User.Id}");
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?UserId={APIClient.User.Id}");
return View();
}
[HttpPost]
public void AddProductToOrder(int product, int order)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
APIClient.PostRequest("api/main/updateorder", new OrderBindingModel
{
Id = order,
ProductId = product,
Status = OrderStatus.Принят,
});
Response.Redirect("Products");
}
[HttpGet]
public IActionResult ComponentOrderReport()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/main/getcomponentlist?userid={APIClient.User.Id}");
return View();
}
//[HttpPost]
//public void ComponentOrderReport(List<int> components, string type)
//{
// if (APIClient.User == null)
// {
// throw new Exception("Вы как суда попали? Суда вход только авторизованным");
// }
// if (components.Count <= 0)
// {
// throw new Exception("Количество должно быть больше 0");
// }
// if (string.IsNullOrEmpty(type))
// {
// throw new Exception("Неверный тип отчета");
// }
// if (type == "docx")
// {
// APIClient.PostRequest("api/reportadministrator/createmealplanlistwordfile", new ReportComponentsBindingModel
// {
// Dinners = dinners,
// FileName = "C:\\wordfile.docx"
// });
// Response.Redirect("GetWordFile");
// }
// else
// {
// APIClient.PostRequest("api/reportadministrator/createmealplanlistexcelfile", new ReportComponentsBindingModel
// {
// Dinners = dinners,
// FileName = "C:\\exelfile.xlsx"
// });
// Response.Redirect("GetExcelFile");
// }
//}
[HttpGet]
public IActionResult GetWordFile()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return new PhysicalFileResult("C:\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return new PhysicalFileResult("C:\\exelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
[HttpGet]
public IActionResult Privacy()

View File

@ -0,0 +1,24 @@

@{
ViewData["Title"] = "AddProductToOrder";
}
<head>
<link rel="stylesheet" href="~/css/style.css" asp-append-version="true" />
</head>
<div class="text-center">
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1">Привязка блюда к заказу</h2>
</div>
<form method="post">
<div class="spisok">
<label class="u-label u-text-custom-color-1 u-label-1">Название блюда: </label>
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.Products, "Id", "ProductName"))"></select>
</div>
<div class="spisok">
<label class="u-label u-text-custom-color-1 u-label-1">Номер заказа: </label>
<select id="order" name="order" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders, "Id", "Name"))"></select>
</div>
<div class="button">
<button class="button-action">Добавить привязку</button>
</div>
</form>

View File

@ -0,0 +1,39 @@
@using DiningRoomContracts.ViewModels
@{
ViewData["Title"] = "ComponentOrderReport";
}
<head>
<link rel="stylesheet" href="~/css/style.css" asp-append-version="true" />
</head>
<div class="text-center">
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1">Отчет (word/excel)</h2>
</div>
<form method="post">
<div class="file-format">
<label class="form-label">Формат файла:</label>
<div class="radio-buttons">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="label-word" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="label-exel" for="xlsx">Excel-файл</label>
</div>
</div>
<br>
<div class="row">
<div class="col-4">Продукты:</div>
<div class="col-8">
<select name="components" class="form-control" multiple size="5" id="components">
@foreach (var service in ViewBag.Components)
{
<option value="@service.Id">@service.ComponentName</option>
}
</select>
</div>
</div>
<br>
<div class="buttons-create-file">
<button type ="submit" class="button-action">Создать</button>
</div>
</form>

View File

@ -8,7 +8,7 @@
<link rel="stylesheet" href="~/css/style.css" asp-append-version="true" />
</head>
<div class="text-center">
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Добавить блюдо</h2>
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Добавить напиток</h2>
</div>
<form method="post">
<input name="drinkName" style="margin-bottom: 20px" type="text" placeholder="Введите название напитка" class="form-control" />

View File

@ -59,7 +59,7 @@
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li class="nav-item">
<a class="nav-link" asparea="" asp-controller="Home" asp-action="MealPlanDinnerReport">Отчет (word/excel)</a>
<a class="nav-link" asparea="" asp-controller="Home" asp-action="ComponentOrderReport">Отчет (word/excel)</a>
</li>
<li class="nav-item">
<a class="nav-link" asparea="" asp-controller="Home" asp-action="AddDinnerToFile">Отчет (pdf) </a>
@ -67,7 +67,7 @@
</ul>
</li>
<li class="nav-item">
<a class="nav-link" asparea="" asp-controller="Home" asp-action="AddRoomToMealPlan">Привязка</a>
<a class="nav-link" asparea="" asp-controller="Home" asp-action="AddProductToOrder">Привязка</a>
</li>
<li class="nav-item">
<a class="nav-link" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>