Рабочий интерфейс основных сущностей готов. Остались заказы\алк.карты\отчеты. Должно быть легко
This commit is contained in:
parent
b05ca974f1
commit
5e83a249b6
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace DiningRoomDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DiningRoomDatabase))]
|
||||
[Migration("20240827000029_InitialCreate")]
|
||||
[Migration("20240827004449_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
@ -151,6 +151,14 @@ namespace DiningRoomUserApp.Controllers
|
||||
}
|
||||
return View(APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?userId={APIClient.User.Id}"));
|
||||
}
|
||||
public IActionResult Drinks()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<DrinkViewModel>>($"api/main/getdrinklist?userId={APIClient.User.Id}"));
|
||||
}
|
||||
public IActionResult CreateProduct()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
@ -250,6 +258,105 @@ namespace DiningRoomUserApp.Controllers
|
||||
});
|
||||
Response.Redirect("Products");
|
||||
}
|
||||
public IActionResult CreateDrink()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
var list = _component.ReadList(new ComponentSearchModel { UserId = APIClient.User.Id });
|
||||
var simpComponent = list.Select(x => new { ComponentId = x.Id, ComponentName = x.ComponentName });
|
||||
ViewBag.components = new MultiSelectList(simpComponent, "ComponentId", "ComponentName");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateDrink(string drinkName, double drinkPrice, int[] components)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
if (drinkName.Length <=0 || drinkPrice<=0 || components.Length == 0)
|
||||
{
|
||||
throw new Exception("Введите данные");
|
||||
}
|
||||
Dictionary<int, (IComponentModel, int)> _drinkComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
foreach (int id in components)
|
||||
{
|
||||
_drinkComponents.Add(id, (_component.ReadElement(new ComponentSearchModel { Id = id }), 1));
|
||||
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/main/createdrink", new DrinkBindingModel
|
||||
{
|
||||
DrinkName = drinkName,
|
||||
Cost = drinkPrice,
|
||||
UserId = APIClient.User.Id,
|
||||
DrinkComponents = _drinkComponents,
|
||||
});
|
||||
Response.Redirect("Drinks");
|
||||
}
|
||||
public IActionResult UpdateDrink()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Drinks = APIClient.GetRequest<List<DrinkViewModel>>($"api/main/getdrinklist?userid={APIClient.User.Id}");
|
||||
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>($"api/main/getcomponentlist?userid={APIClient.User.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateDrink(int drink, string drinkName, double drinkPrice, List<int> components)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
if (drinkName.Length <= 0 || drinkPrice <= 0)
|
||||
{
|
||||
throw new Exception("Введите данные");
|
||||
}
|
||||
Dictionary<int, (IComponentModel, int)> _drinkComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
foreach (int id in components)
|
||||
{
|
||||
_drinkComponents.Add(id, (new ComponentSearchModel { Id = id } as IComponentModel, 1));
|
||||
|
||||
}
|
||||
APIClient.PostRequest("api/main/updatedrink", new DrinkBindingModel
|
||||
{
|
||||
Id = drink,
|
||||
DrinkName = drinkName,
|
||||
Cost = drinkPrice,
|
||||
UserId = APIClient.User.Id,
|
||||
DrinkComponents = _drinkComponents,
|
||||
});
|
||||
Response.Redirect("Drinks");
|
||||
}
|
||||
|
||||
public IActionResult DeleteDrink()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Drinks = APIClient.GetRequest<List<DrinkViewModel>>($"api/main/getdrinklist?userId={APIClient.User.Id}");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void DeleteDrink(int drink)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
APIClient.PostRequest("api/main/deletedrink", new DrinkBindingModel
|
||||
{
|
||||
Id = drink
|
||||
});
|
||||
Response.Redirect("Drinks");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
|
28
DiningRoom/DiningRoomUserApp/Views/Home/CreateDrink.cshtml
Normal file
28
DiningRoom/DiningRoomUserApp/Views/Home/CreateDrink.cshtml
Normal file
@ -0,0 +1,28 @@
|
||||
@using DiningRoomContracts.ViewModels
|
||||
|
||||
@model ComponentViewModel
|
||||
@{
|
||||
ViewData["Title"] = "CreateDrink";
|
||||
}
|
||||
<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">
|
||||
<input name="drinkName" style="margin-bottom: 20px" type="text" placeholder="Введите название напитка" class="form-control" />
|
||||
<input name="drinkPrice" style="margin-bottom: 20px" type="number" placeholder="Введите стоимость напитка" class="form-control" step="1" />
|
||||
<div class="spisok">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Продукты: </label>
|
||||
<div>
|
||||
@Html.ListBox("components", (MultiSelectList)ViewBag.Components, new { @class = "form-control", size = "10" })
|
||||
</div>
|
||||
</div>
|
||||
<div class="button">
|
||||
<button class="button-action" type="submit">Сохранить</button>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="Drinks" class="button-action">Назад</a>
|
||||
</div>
|
||||
</form>
|
22
DiningRoom/DiningRoomUserApp/Views/Home/DeleteDrink.cshtml
Normal file
22
DiningRoom/DiningRoomUserApp/Views/Home/DeleteDrink.cshtml
Normal file
@ -0,0 +1,22 @@
|
||||
@{
|
||||
ViewData["Title"] = "DeleteDrink";
|
||||
}
|
||||
<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="drink" name="drink" class="form-control" asp-items="@(new SelectList(@ViewBag.Drinks, "Id", "DrinkName"))"></select>
|
||||
</div>
|
||||
<div class="button">
|
||||
<button type="submit" class="button-action">Удалить</button>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="Drinks" class="button-action">Назад</a>
|
||||
</div>
|
||||
</form>
|
59
DiningRoom/DiningRoomUserApp/Views/Home/Drinks.cshtml
Normal file
59
DiningRoom/DiningRoomUserApp/Views/Home/Drinks.cshtml
Normal file
@ -0,0 +1,59 @@
|
||||
@using DiningRoomContracts.ViewModels
|
||||
|
||||
@model List<DrinkViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Drinks";
|
||||
}
|
||||
<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="main">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название напитка
|
||||
</th>
|
||||
<th>
|
||||
Цена
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr style="height: 75px">
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DrinkName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Cost)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="buttons-action-with-drink">
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="CreateDrink" class="button-action" style="width: 130px">Добавить</a>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="UpdateDrink" class="button-action" style="width: 130px">Изменить</a>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="DeleteDrink" class="button-action" style="width: 130px">Удалить</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
42
DiningRoom/DiningRoomUserApp/Views/Home/UpdateDrink.cshtml
Normal file
42
DiningRoom/DiningRoomUserApp/Views/Home/UpdateDrink.cshtml
Normal file
@ -0,0 +1,42 @@
|
||||
@using DiningRoomContracts.ViewModels;
|
||||
@{
|
||||
ViewData["Title"] = "UpdateDrink";
|
||||
}
|
||||
<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="drink" name="drink" class="form-control" asp-items="@(new SelectList(@ViewBag.Drinks, "Id", "DrinkName"))"></select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input name="drinkName" style="margin-bottom: 20px" type="text" placeholder="Введите новое название напитка" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input name="drinkPrice" style="margin-bottom: 20px" type="number" placeholder="Введите новую стоимость напитка" class="form-control" step="1" />
|
||||
</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 component in ViewBag.Components)
|
||||
{
|
||||
<option value="@component.Id" data-name="@component.Id">@component.ComponentName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="button">
|
||||
<button class="button-action">Сохранить</button>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="Drinks" class="button-action">Назад</a>
|
||||
</div>
|
||||
|
||||
</form>
|
@ -36,35 +36,7 @@
|
||||
<button class="button-action">Сохранить</button>
|
||||
</div>
|
||||
<div class="button">
|
||||
<a asp-area="" asp-controller="Home" asp-action="Rooms" class="button-action">Назад</a>
|
||||
<a asp-area="" asp-controller="Home" asp-action="Products" class="button-action">Назад</a>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var room = $('#room').val();
|
||||
$("#dinners option:selected").removeAttr("selected");
|
||||
if (room) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetRoom",
|
||||
data: { roomId: room },
|
||||
success: function (result) {
|
||||
$('#roomNumber').val(result.roomNumber);
|
||||
$('#roomPrice').val(result.RoomPrice);
|
||||
$('#dateCreate').val(result.DateCreate);
|
||||
$.map(result.item2, function (n) {
|
||||
$(`option[data-name=${n.item2}]`).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#room').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user