interim commit

This commit is contained in:
Denis 2023-05-17 16:02:26 +03:00
parent 40c8117b7f
commit 35aef0cdb5
21 changed files with 543 additions and 208 deletions

View File

@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts;
using CanteenContracts.SearchModel; using CanteenContracts.SearchModel;
using CanteenContracts.StoragesContracts; using CanteenContracts.StoragesContracts;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,6 +23,28 @@ namespace CanteenBusinessLogic.BusinessLogics
_logger = logger; _logger = logger;
_productStorage = productStorage; _productStorage = productStorage;
} }
public bool AddCooksToProduct(ProductSearchModel model, ICookModel cook)
{
var product = _productStorage.GetElement(model);
product.ProductCooks[cook.Id] = cook;
if (_productStorage.Update(new()
{
Id = product.Id,
ProductName = product.ProductName,
Price = product.Price,
ManagerId = product.ManagerId,
ProductCooks = product.ProductCooks
}) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Create(ProductBindingModel model) public bool Create(ProductBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -0,0 +1,17 @@
using CanteenContracts.SearchModel;
using CanteenContracts.View;
using CanteenDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanteenContracts.BindingModels
{
public class ProductCookBindingModel
{
public int ProductId { get; set; }
public List<ICookModel> Cooks { get; set; } = new();
}
}

View File

@ -1,6 +1,7 @@
using CanteenContracts.BindingModels; using CanteenContracts.BindingModels;
using CanteenContracts.SearchModel; using CanteenContracts.SearchModel;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -16,5 +17,6 @@ namespace CanteenContracts.BusinessLogicsContracts
bool Create(ProductBindingModel model); bool Create(ProductBindingModel model);
bool Update(ProductBindingModel model); bool Update(ProductBindingModel model);
bool Delete(ProductBindingModel model); bool Delete(ProductBindingModel model);
bool AddCooksToProduct(ProductSearchModel model, ICookModel cook);
} }
} }

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" /> <ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -4,12 +4,14 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Newtonsoft.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace CanteenContracts.View namespace CanteenContracts.View
{ {
public class ProductViewModel : IProductModel public class ProductViewModel : IProductModel
{ {
public int Id { get; set; }
[DisplayName("Название продукта")] [DisplayName("Название продукта")]
public string ProductName { get; set; } = string.Empty; public string ProductName { get; set; } = string.Empty;
@ -21,7 +23,12 @@ namespace CanteenContracts.View
public Dictionary<int, ICookModel> ProductCooks { get; set; } = new(); public Dictionary<int, ICookModel> ProductCooks { get; set; } = new();
public int Id { get; set; } public ProductViewModel() { }
[JsonConstructor]
public ProductViewModel(Dictionary<int, CookViewModel> ProductCooks)
{
this.ProductCooks = ProductCooks.ToDictionary(x => x.Key, x => x.Value as ICookModel);
}
} }
} }

View File

@ -16,7 +16,7 @@ namespace CanteenDatabaseImplement.Implements
{ {
public DishViewModel? GetElement(DishSearchModel model) public DishViewModel? GetElement(DishSearchModel model)
{ {
if (!model.Id.HasValue && string.IsNullOrEmpty(model.DishName)) if (!model.Id.HasValue)
{ {
return null; return null;
} }

View File

@ -15,7 +15,7 @@ namespace CanteenDatabaseImplement.Implements
{ {
public ManagerViewModel? GetElement(ManagerSearchModel model) public ManagerViewModel? GetElement(ManagerSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && string.IsNullOrEmpty(model.PhoneNumber) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
{ {
return null; return null;
} }

View File

@ -32,7 +32,7 @@ namespace CanteenDatabaseImplement.Implements
public ProductViewModel? GetElement(ProductSearchModel model) public ProductViewModel? GetElement(ProductSearchModel model)
{ {
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ProductName)) if (!model.Id.HasValue)
{ {
return null; return null;
} }
@ -46,7 +46,7 @@ namespace CanteenDatabaseImplement.Implements
public List<ProductViewModel> GetFilteredList(ProductSearchModel model) public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{ {
if (string.IsNullOrEmpty(model.ProductName)) if (!model.ManagerId.HasValue)
{ {
return new(); return new();
} }
@ -56,7 +56,7 @@ namespace CanteenDatabaseImplement.Implements
return context.Products return context.Products
.Include(x => x.Cooks) .Include(x => x.Cooks)
.ThenInclude(x => x.Cook) .ThenInclude(x => x.Cook)
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)) .Where(x => ((model.Id.HasValue && x.Id == model.Id) || (model.ManagerId.HasValue && model.ManagerId == x.ManagerId)))
.Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }
@ -112,8 +112,9 @@ namespace CanteenDatabaseImplement.Implements
} }
product.Update(model); product.Update(model);
context.SaveChanges(); context.SaveChanges();
if (model.ProductCooks != null)
product.UpdateProductCooks(context, model);
context.Database.CommitTransaction(); context.Database.CommitTransaction();
return product.GetViewModel; return product.GetViewModel;

View File

@ -8,84 +8,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace CanteenDatabaseImplement.Models namespace CanteenDatabaseImplement.Models
{ {
//public class Product : IProductModel
//{
// public int Id { get; private set; }
// [Required]
// public string ProductName { get; private set; } = string.Empty;
// [Required]
// public double Cost { get; private set; }
// [Required]
// public int ManagerId { get; private set; }
// private Dictionary<int, ICookModel>? _productCooks = null;
// [NotMapped]
// public Dictionary<int, ICookModel> ProductCooks
// {
// get
// {
// if (_productCooks == null)
// {
// _productCooks = Cooks.ToDictionary(record => record.CookId, record => record.Cook as ICookModel);
// }
// return _productCooks;
// }
// }
// [ForeignKey("ProductId")]
// public virtual List<ProductCook> Cooks { get; set; } = new();
// [ForeignKey("ProductId")]
// public virtual List<DishProduct> Dishes { get; set; } = new();
// public static Product? Create(CanteenDatabase context, ProductBindingModel model)
// {
// return new Product()
// {
// Id = model.Id,
// ProductName = model.ProductName,
// Cost = model.Cost,
// Cooks = model.ProductCooks.Select(x => new ProductCook
// {
// Cook = context.Cooks.First(y => y.Id == x.Key)
// }).ToList()
// };
// }
// public void Update(ProductBindingModel model)
// {
// ProductName = model.ProductName;
// Cost = model.Cost;
// }
// public ProductViewModel GetViewModel => new()
// {
// Id = Id,
// ProductName = ProductName,
// Cost = Cost,
// ProductCooks = ProductCooks,
// ManagerId = ManagerId
// };
// public void UpdateCooks(CanteenDatabase context, ProductBindingModel model)
// {
// var productCooks = context.ProductCooks.Where(record => record.ProductId == model.Id).ToList();
// if (productCooks != null && productCooks.Count > 0)
// {
// context.ProductCooks.RemoveRange(productCooks.Where(record => !model.ProductCooks.ContainsKey(record.CookId)));
// context.SaveChanges();
// }
// var product = context.Products.First(x => x.Id == Id);
// foreach (var pc in model.ProductCooks)
// {
// context.ProductCooks.Add(new ProductCook
// {
// Product = product,
// Cook = context.Cooks.First(x => x.Id == pc.Key),
// });
// context.SaveChanges();
// }
// _productCooks = null;
// }
//}
public class Product : IProductModel public class Product : IProductModel
{ {
public int Id { get; set; } public int Id { get; set; }
@ -133,7 +55,7 @@ namespace CanteenDatabaseImplement.Models
ManagerId = model.ManagerId, ManagerId = model.ManagerId,
Cooks = model.ProductCooks.Select(x => new ProductCook Cooks = model.ProductCooks.Select(x => new ProductCook
{ {
Cook = context.Cooks.First(y => y.Id == x.Key), Cook = context.Cooks.First(y => y.Id == x.Key)
}).ToList() }).ToList()
}; };
} }
@ -157,7 +79,7 @@ namespace CanteenDatabaseImplement.Models
public void UpdateProductCooks(CanteenDatabase context, ProductBindingModel model) public void UpdateProductCooks(CanteenDatabase context, ProductBindingModel model)
{ {
var productCookers = context.ProductCook.Where(rec => rec.ProductId == model.Id).ToList(); var productCookers = context.ProductCook.Where(rec => rec.ProductId == model.Id).ToList();
if (productCookers != null && (productCookers.Count() > 0)) if (productCookers != null)
{ {
context.ProductCook.RemoveRange(productCookers.Where(rec => !model.ProductCooks.ContainsKey(rec.CookId))); context.ProductCook.RemoveRange(productCookers.Where(rec => !model.ProductCooks.ContainsKey(rec.CookId)));
context.SaveChanges(); context.SaveChanges();

View File

@ -7,7 +7,11 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize> <Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,7 +1,12 @@
using CanteenContracts.BindingModels; using CanteenContracts.BindingModels;
using CanteenContracts.SearchModel;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenDatabaseImplement.Models;
using CanteenDataModels.Models;
using CanteenManagerApp.Models; using CanteenManagerApp.Models;
using FluentNHibernate.Conventions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Data;
using System.Diagnostics; using System.Diagnostics;
@ -15,7 +20,7 @@ namespace CanteenManagerApp.Controllers
{ {
_logger = logger; _logger = logger;
} }
[HttpGet]
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.Manager == null) if (APIClient.Manager == null)
@ -25,87 +30,12 @@ namespace CanteenManagerApp.Controllers
return View(); return View();
} }
public IActionResult Cooks()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
return View();
}
[HttpGet]
public IActionResult Products()
{
ViewBag.Products = new List<ProductViewModel>();
return View();
}
[HttpGet]
public IActionResult Dishes()
{
ViewBag.Dishes = new List<DishViewModel>();
return View();
}
public IActionResult Privacy()
{
return View();
}
[HttpGet]
public IActionResult CreateCook()
{
return View();
}
[HttpPost]
public void CreateCook(string FIO, string position)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
if (string.IsNullOrEmpty(FIO))
{
throw new Exception("ФИО не должно быть пустым");
}
APIClient.PostRequest("api/main/createcook", new CookBindingModel
{
ManagerId = APIClient.Manager.Id,
FIO = FIO,
Position = position
});
Response.Redirect("Cooks");
}
[HttpPost]
public IActionResult DeleteCook(int CookId)
{
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
return Redirect("~/Home/Cooks");
}
[HttpGet]
public IActionResult CreateProduct()
{
return View();
}
[HttpGet]
public IActionResult CreateDish()
{
return View();
}
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Enter(string login, string password) public void Enter(string login, string password)
{ {
@ -155,5 +85,284 @@ namespace CanteenManagerApp.Controllers
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpGet]
public IActionResult Cooks()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist? ={APIClient.Manager.Id}");
return View();
}
[HttpGet]
public IActionResult CreateCook()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void CreateCook(string FIO, string position)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
if (string.IsNullOrEmpty(FIO))
{
throw new Exception("ФИО не должно быть пустым");
}
APIClient.PostRequest("api/main/createcook", new CookBindingModel
{
ManagerId = APIClient.Manager.Id,
FIO = FIO,
Position = position
});
Response.Redirect("Cooks");
}
[HttpGet]
public IActionResult DeleteCook(int CookId)
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
APIClient.PostRequest("api/main/deletecook", new CookBindingModel { Id = CookId }); ;
return Redirect("~/Home/Cooks");
}
[HttpGet]
public IActionResult UpdateCook()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void UpdateCook(string FIO, string postition)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
APIClient.PostRequest("api/main/updatecook", new CookBindingModel
{
Id = APIClient.Manager.Id,
FIO = FIO,
Position = postition
});
Response.Redirect("Cooks");
}
[HttpGet]
public IActionResult Products()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
return View();
}
[HttpGet]
public IActionResult CreateProduct()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
return View();
}
[HttpPost]
public void CreateProduct(string name, double price)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception("Наименование продукта не должно быть пустым");
}
APIClient.PostRequest("api/main/createproduct", new ProductBindingModel
{
ManagerId = APIClient.Manager.Id,
ProductName = name,
Price = price
});
Response.Redirect("Products");
}
[HttpGet]
public IActionResult AddCooksToProduct()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>($"api/main/getproductlist?managerId={APIClient.Manager.Id}");
ViewBag.Cooks = APIClient.GetRequest<List<CookViewModel>>($"api/main/getcooklist?managerId={APIClient.Manager.Id}");
return View();
}
[HttpPost]
public void AddCooksToProduct(int selectedProduct, int selectedCook)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
if (selectedProduct <= 0)
{
throw new Exception("Должен быть выбран продукт");
}
if (selectedCook <= 0)
{
throw new Exception("Должен быть выбран повар");
}
APIClient.PostRequest("api/main/addcookstoproduct", Tuple.Create
(
new ProductSearchModel { Id = selectedProduct },
new CookViewModel { Id = selectedCook }
));
Response.Redirect("Products");
}
[HttpGet]
public IActionResult DeleteProduct(int productId)
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
APIClient.PostRequest("api/main/deleteproduct", new ProductBindingModel { Id = productId });
return Redirect("~/Home/Products");
}
[HttpGet]
public IActionResult UpdateProduct()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void UpdateProduct(string productName, double price)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
APIClient.PostRequest("api/main/updateproduct", new ProductBindingModel
{
Id = APIClient.Manager.Id,
ProductName = productName,
Price = price
});
Response.Redirect("Products");
}
[HttpGet]
public IActionResult Dishes()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Dishes = APIClient.GetRequest<List<DishViewModel>>($"api/main/getdishlist?managerId={APIClient.Manager.Id}");
return View();
}
[HttpGet]
public IActionResult CreateDish()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void CreateDish(string dishName, double price)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
if (string.IsNullOrEmpty(dishName))
{
throw new Exception("Наименование блюда не должно быть пустым");
}
APIClient.PostRequest("api/main/createdish", new DishBindingModel
{
ManagerId = APIClient.Manager.Id,
DishName = dishName,
Price = price
});
Response.Redirect("Dishes");
}
[HttpGet]
public IActionResult DeleteDish(int dishId)
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
APIClient.PostRequest("api/main/deletedish", new DishBindingModel { Id = dishId });
return Redirect("~/Home/Dishes");
}
[HttpGet]
public IActionResult UpdateDish()
{
if (APIClient.Manager == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void UpdateDish(string dishName, double price)
{
if (APIClient.Manager == null)
{
throw new Exception("Доступ возможен только авторизованным пользователям");
}
APIClient.PostRequest("api/main/updatedish", new DishBindingModel
{
Id = APIClient.Manager.Id,
DishName = dishName,
Price = price
});
Response.Redirect("Dishes");
}
} }
} }

View File

@ -0,0 +1,42 @@
@using CanteenContracts.View;
@{
ViewData["Title"] = "AddCooksToProduct";
}
<div class="text-center">
<h2 class="display-4">Привязка повара к продукту</h2>
</div>
<style>
.row {
margin-top: 10px;
}
</style>
<form method="post">
<div class="row">
<div class="col-4">Продукты:</div>
<div class="col-8">
<select name="selectedProduct">
@foreach (var product in ViewBag.Products as List<ProductViewModel>)
{
<option value="@product.Id">@product.ProductName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4">Повар:</div>
<div class="col-8">
<select name="selectedCook">
@foreach (var cook in ViewBag.Cooks as List<CookViewModel>)
{
<option value="@cook.Id">@cook.FIO</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Добавить" class="btn btn-primary" />
</div>
</div>
</form>

View File

@ -1,4 +1,4 @@
 @using CanteenContracts.View;
@{ @{
ViewData["Title"] = "Product"; ViewData["Title"] = "Product";
} }
@ -6,7 +6,7 @@
<h2 class="display-4">Добавление продукта</h2> <h2 class="display-4">Добавление продукта</h2>
</div> </div>
<style> <style>
.row{ .row {
margin-top: 10px; margin-top: 10px;
} }
</style> </style>
@ -14,14 +14,24 @@
<div class="row"> <div class="row">
<div class="col-4">Название продукта:</div> <div class="col-4">Название продукта:</div>
<div class="col-8"> <div class="col-8">
<input type="text" name="FIO" id="FIO" /> <input type="text" name="name" id="name" />
@* <select id="bouquet" name="bouquet" class="form-control" asp-items="@(new SelectList(@ViewBag.Bouquets, "Id", "BouquetName"))"></select>*@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Цена:</div> <div class="col-4">Цена:</div>
<div class="col-8"> <div class="col-8">
<input type="text" name="position" id="position" /> <input type="text" name="price" id="price" />
</div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8">
<select name="selectedCooks" multiple>
@foreach (var cook in ViewBag.Cooks as List<CookViewModel>)
{
<option value="@cook.Id">@cook.FIO</option>
}
</select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">

View File

@ -1,32 +1,59 @@
@{ @{
ViewData["Title"] = "Dishes"; ViewData["Title"] = "Products";
} }
<body> <body>
<div class="container"> <div class="container">
<h2>Список блюд</h2> <h2>Список список продуктов</h2>
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateDish", "Home")'">Добавить блюдо</button> <a type="button" class="btn btn-success" href="/Home/CreateCook">Добавить продукт</a>
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateDish", "Home")'">Удалить блюдо</button> <button type="submit" class="btn btn-danger" form="selectCookForm">Удалить продукт</button>
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateDish", "Home")'">Обновить блюдо</button> <a type="button" class="btn btn-warning" href="/Home/UpdateCook">Обновить продукт</a>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Номер</th> <th>Номер</th>
<th>Название блюда</th> <th>Название</th>
<th>Цена</th> <th>Цена</th>
<th>Менеджер</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var cook in ViewBag.Dishes) @foreach (var cook in ViewBag.Cooks)
{ {
<tr> <tr onclick="selectCook(this)">
<td>@cook.Id</td> <td>@cook.Id</td>
<td>@cook.DishName</td> <td>@cook.Name</td>
<td>@cook.Price</td> <td>@cook.Price</td>
<td>@cook.ManagerId</td> </tr>
</tr>
} }
</tbody> </tbody>
</table> </table>
</div> </div>
</body> </body>
<form id="selectCookForm" method="post" action="/Home/DeleteCook">
<input type="hidden" id="ProductId" name="ProductId" value="" />
</form>
<style>
.selected-row {
background-color: lightgray;
}
</style>
<script>
function selectCook(row) {
var ProductId = document.getElementById("ProductId");
var previousValue = ProductId.value;
var currentValue = row.cells[0].innerText;
if (previousValue === currentValue) {
ProductId.value = "";
row.classList.remove("selected-row");
} else {
ProductId.value = currentValue;
var rows = document.getElementsByTagName("tr");
for (var i = 0; i < rows.length; i++) {
rows[i].classList.remove("selected-row");
}
row.classList.add("selected-row");
}
}
</script>

View File

@ -7,15 +7,15 @@
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Логин:</div> <div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div> <div class="col-8"><input type="text" name="login" value="@ViewBag.Data.Login" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Пароль:</div> <div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div> <div class="col-8"><input type="password" name="password" value="@ViewBag.Data.Password" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">ФИО:</div> <div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" value="@Model.ClientFIO" /></div> <div class="col-8"><input type="text" name="fio" value="@ViewBag.Data.ClientFIO" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>

View File

@ -1,32 +1,61 @@
@{ @using CanteenContracts.View;
@{
ViewData["Title"] = "Products"; ViewData["Title"] = "Products";
} }
<body> <body>
<div class="container"> <div class="container">
<h2>Список продуктов</h2> <h2>Список продуктов</h2>
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Добавить продукт</button> <a type="button" class="btn btn-success" href="/Home/CreateProduct">Добавить продукт</a>
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Удалить продукт</button> <button type="submit" class="btn btn-danger" form="selectProductForm">Удалить продукт</button>
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateProduct", "Home")'">Обновить продукт</button> <a type="button" class="btn btn-warning" href="/Home/UpdateProduct">Обновить продукт</a>
<a type="button" class="btn btn-warning" href="/Home/AddCooksToProduct">Привязать повара</a>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Номер</th> <th>Номер</th>
<th>Название продукта</th> <th>Название</th>
<th>Цена</th> <th>Цена</th>
<th>Менеджер</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var cook in ViewBag.Products) @foreach (var product in ViewBag.Products)
{ {
<tr> <tr onclick="selectProduct(this)">
<td>@cook.Id</td> <td>@product.Id</td>
<td>@cook.ProductName</td> <td>@product.ProductName</td>
<td>@cook.Price</td> <td>@product.Price</td>
<td>@cook.ManagerId</td> </tr>
</tr>
} }
</tbody> </tbody>
</table> </table>
</div> </div>
</body> </body>
<form id="selectProductForm" method="post" action="/Home/DeleteProduct">
<input type="hidden" id="ProductId" name="ProductId" value="" />
</form>
<style>
.selected-row {
background-color: lightgray;
}
</style>
<script>
function selectProduct(row) {
var productIdInput = document.getElementById("ProductId");
var previousValue = productIdInput.value;
var currentValue = row.cells[0].innerText;
if (previousValue === currentValue) {
productIdInput.value = "";
row.classList.remove("selected-row");
} else {
productIdInput.value = currentValue;
var rows = document.getElementsByTagName("tr");
for (var i = 0; i < rows.length; i++) {
rows[i].classList.remove("selected-row");
}
row.classList.add("selected-row");
}
}
</script>

View File

@ -6,10 +6,10 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId) @if (ViewBag.Data.ShowRequestId)
{ {
<p> <p>
<strong>Request ID:</strong> <code>@Model.RequestId</code> <strong>Request ID:</strong> <code>@ViewBag.Data.RequestId</code>
</p> </p>
} }

View File

@ -7,7 +7,11 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize> <Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,6 +2,7 @@ using CanteenContracts.BindingModels;
using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.BusinessLogicsContracts;
using CanteenContracts.SearchModel; using CanteenContracts.SearchModel;
using CanteenContracts.View; using CanteenContracts.View;
using CanteenDataModels.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace CanteenRestApi.Controllers namespace CanteenRestApi.Controllers
@ -39,6 +40,19 @@ namespace CanteenRestApi.Controllers
} }
} }
[HttpGet] [HttpGet]
public List<ProductViewModel>? GetProductList(int managerId)
{
try
{
return _product.ReadList(new ProductSearchModel { ManagerId = managerId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
public List<TablewareViewModel>? GetTablewareList() public List<TablewareViewModel>? GetTablewareList()
{ {
try try
@ -77,6 +91,7 @@ namespace CanteenRestApi.Controllers
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void DeleteCook(CookBindingModel model) public void DeleteCook(CookBindingModel model)
{ {
@ -90,6 +105,7 @@ namespace CanteenRestApi.Controllers
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void CreateDish(DishBindingModel model) public void CreateDish(DishBindingModel model)
{ {
@ -116,5 +132,19 @@ namespace CanteenRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void AddCooksToProduct(Tuple<ProductSearchModel, CookViewModel> model)
{
try
{
_product.AddCooksToProduct(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
} }
} }

View File

@ -7,7 +7,11 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize> <Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -6,10 +6,10 @@
<h1 class="text-danger">Error.</h1> <h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2> <h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId) @if (ViewBag.Data.ShowRequestId)
{ {
<p> <p>
<strong>Request ID:</strong> <code>@Model.RequestId</code> <strong>Request ID:</strong> <code>@ViewBag.Data.RequestId</code>
</p> </p>
} }