diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/ProductLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/ProductLogic.cs index d61b213..71af624 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/ProductLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/ProductLogic.cs @@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.StoragesContracts; using CanteenContracts.View; +using CanteenDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -22,6 +23,28 @@ namespace CanteenBusinessLogic.BusinessLogics _logger = logger; _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) { CheckModel(model); diff --git a/Canteen/CanteenContracts/BindingModels/ProductCookBindingModel.cs b/Canteen/CanteenContracts/BindingModels/ProductCookBindingModel.cs new file mode 100644 index 0000000..0b1b158 --- /dev/null +++ b/Canteen/CanteenContracts/BindingModels/ProductCookBindingModel.cs @@ -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 Cooks { get; set; } = new(); + } +} diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IProductLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IProductLogic.cs index d41ab54..9c3d034 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IProductLogic.cs @@ -1,6 +1,7 @@ using CanteenContracts.BindingModels; using CanteenContracts.SearchModel; using CanteenContracts.View; +using CanteenDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -16,5 +17,6 @@ namespace CanteenContracts.BusinessLogicsContracts bool Create(ProductBindingModel model); bool Update(ProductBindingModel model); bool Delete(ProductBindingModel model); + bool AddCooksToProduct(ProductSearchModel model, ICookModel cook); } } diff --git a/Canteen/CanteenContracts/CanteenContracts.csproj b/Canteen/CanteenContracts/CanteenContracts.csproj index 89209ad..dd1f114 100644 --- a/Canteen/CanteenContracts/CanteenContracts.csproj +++ b/Canteen/CanteenContracts/CanteenContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs b/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs index 7e8630f..0b90941 100644 --- a/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs @@ -4,12 +4,14 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using Newtonsoft.Json; using System.Threading.Tasks; namespace CanteenContracts.View { public class ProductViewModel : IProductModel { + public int Id { get; set; } [DisplayName("Название продукта")] public string ProductName { get; set; } = string.Empty; @@ -21,7 +23,12 @@ namespace CanteenContracts.View public Dictionary ProductCooks { get; set; } = new(); - public int Id { get; set; } + public ProductViewModel() { } + [JsonConstructor] + public ProductViewModel(Dictionary ProductCooks) + { + this.ProductCooks = ProductCooks.ToDictionary(x => x.Key, x => x.Value as ICookModel); + } } } diff --git a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs index 8c7794d..b3a1ae6 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs @@ -16,7 +16,7 @@ namespace CanteenDatabaseImplement.Implements { public DishViewModel? GetElement(DishSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.DishName)) + if (!model.Id.HasValue) { return null; } diff --git a/Canteen/CanteenDatabaseImplement/Implements/ManagerStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/ManagerStorage.cs index bab2254..7329e6b 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/ManagerStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/ManagerStorage.cs @@ -15,7 +15,7 @@ namespace CanteenDatabaseImplement.Implements { 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; } diff --git a/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs index 6045ecb..2ef9078 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/ProductStorage.cs @@ -32,7 +32,7 @@ namespace CanteenDatabaseImplement.Implements public ProductViewModel? GetElement(ProductSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.ProductName)) + if (!model.Id.HasValue) { return null; } @@ -46,7 +46,7 @@ namespace CanteenDatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { - if (string.IsNullOrEmpty(model.ProductName)) + if (!model.ManagerId.HasValue) { return new(); } @@ -56,7 +56,7 @@ namespace CanteenDatabaseImplement.Implements return context.Products .Include(x => x.Cooks) .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(); } @@ -112,8 +112,9 @@ namespace CanteenDatabaseImplement.Implements } product.Update(model); - context.SaveChanges(); + if (model.ProductCooks != null) + product.UpdateProductCooks(context, model); context.Database.CommitTransaction(); return product.GetViewModel; diff --git a/Canteen/CanteenDatabaseImplement/Models/Product.cs b/Canteen/CanteenDatabaseImplement/Models/Product.cs index e17749b..e08ffef 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Product.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Product.cs @@ -8,84 +8,6 @@ using System.ComponentModel.DataAnnotations.Schema; 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? _productCooks = null; - // [NotMapped] - // public Dictionary ProductCooks - // { - // get - // { - // if (_productCooks == null) - // { - // _productCooks = Cooks.ToDictionary(record => record.CookId, record => record.Cook as ICookModel); - // } - // return _productCooks; - // } - // } - // [ForeignKey("ProductId")] - // public virtual List Cooks { get; set; } = new(); - // [ForeignKey("ProductId")] - // public virtual List 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 int Id { get; set; } @@ -133,7 +55,7 @@ namespace CanteenDatabaseImplement.Models ManagerId = model.ManagerId, 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() }; } @@ -157,7 +79,7 @@ namespace CanteenDatabaseImplement.Models public void UpdateProductCooks(CanteenDatabase context, ProductBindingModel model) { 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.SaveChanges(); diff --git a/Canteen/CanteenManagerApp/CanteenManagerApp.csproj b/Canteen/CanteenManagerApp/CanteenManagerApp.csproj index 2f7fef4..bf26b76 100644 --- a/Canteen/CanteenManagerApp/CanteenManagerApp.csproj +++ b/Canteen/CanteenManagerApp/CanteenManagerApp.csproj @@ -7,7 +7,11 @@ - True + False + + + + False diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index 2d6333c..9d02571 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -1,7 +1,12 @@ using CanteenContracts.BindingModels; +using CanteenContracts.SearchModel; using CanteenContracts.View; +using CanteenDatabaseImplement.Models; +using CanteenDataModels.Models; using CanteenManagerApp.Models; +using FluentNHibernate.Conventions; using Microsoft.AspNetCore.Mvc; +using System.Data; using System.Diagnostics; @@ -15,7 +20,7 @@ namespace CanteenManagerApp.Controllers { _logger = logger; } - + [HttpGet] public IActionResult Index() { if (APIClient.Manager == null) @@ -25,87 +30,12 @@ namespace CanteenManagerApp.Controllers return View(); } - - public IActionResult Cooks() - { - if (APIClient.Manager == null) - { - return Redirect("~/Home/Enter"); - } - ViewBag.Cooks = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); - return View(); - } - - [HttpGet] - public IActionResult Products() - { - ViewBag.Products = new List(); - return View(); - } - - [HttpGet] - public IActionResult Dishes() - { - ViewBag.Dishes = new List(); - 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] public IActionResult Enter() { return View(); } + [HttpPost] public void Enter(string login, string password) { @@ -155,5 +85,284 @@ namespace CanteenManagerApp.Controllers { 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>($"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>($"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>($"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>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); + ViewBag.Cooks = APIClient.GetRequest>($"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>($"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"); + } + } } \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml b/Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml new file mode 100644 index 0000000..9c79c8a --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml @@ -0,0 +1,42 @@ +@using CanteenContracts.View; +@{ + ViewData["Title"] = "AddCooksToProduct"; +} +
+

Привязка повара к продукту

+
+ +
+
+
Продукты:
+
+ +
+
+
+
Повар:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml b/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml index f44fe62..fee4277 100644 --- a/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml @@ -1,4 +1,4 @@ - +@using CanteenContracts.View; @{ ViewData["Title"] = "Product"; } @@ -6,7 +6,7 @@

Добавление продукта

@@ -14,14 +14,24 @@
Название продукта:
- - @* *@ +
Цена:
- + +
+
+
+
Цена:
+
+
diff --git a/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml b/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml index 6528712..c1a3d00 100644 --- a/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml @@ -1,32 +1,59 @@ @{ - ViewData["Title"] = "Dishes"; + ViewData["Title"] = "Products"; }
-

Список блюд

- - - +

Список список продуктов

+ Добавить продукт + + Обновить продукт - + - - @foreach (var cook in ViewBag.Dishes) + @foreach (var cook in ViewBag.Cooks) { - - - - - - + + + + + }
НомерНазвание блюдаНазвание ЦенаМенеджер
@cook.Id@cook.DishName@cook.Price@cook.ManagerId
@cook.Id@cook.Name@cook.Price
- \ No newline at end of file + +
+ +
+ + \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Privacy.cshtml b/Canteen/CanteenManagerApp/Views/Home/Privacy.cshtml index ebd9eb2..94e75e6 100644 --- a/Canteen/CanteenManagerApp/Views/Home/Privacy.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/Privacy.cshtml @@ -7,15 +7,15 @@
Логин:
-
+
Пароль:
-
+
ФИО:
-
+
diff --git a/Canteen/CanteenManagerApp/Views/Home/Products.cshtml b/Canteen/CanteenManagerApp/Views/Home/Products.cshtml index 44ab57e..5447da9 100644 --- a/Canteen/CanteenManagerApp/Views/Home/Products.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/Products.cshtml @@ -1,32 +1,61 @@ -@{ +@using CanteenContracts.View; +@{ ViewData["Title"] = "Products"; }

Список продуктов

- - - + Добавить продукт + + Обновить продукт + Привязать повара - + - - @foreach (var cook in ViewBag.Products) + @foreach (var product in ViewBag.Products) { - - - - - - + + + + + }
НомерНазвание продуктаНазвание ЦенаМенеджер
@cook.Id@cook.ProductName@cook.Price@cook.ManagerId
@product.Id@product.ProductName@product.Price
- \ No newline at end of file + + + + + + diff --git a/Canteen/CanteenManagerApp/Views/Shared/Error.cshtml b/Canteen/CanteenManagerApp/Views/Shared/Error.cshtml index a1e0478..d31cf3e 100644 --- a/Canteen/CanteenManagerApp/Views/Shared/Error.cshtml +++ b/Canteen/CanteenManagerApp/Views/Shared/Error.cshtml @@ -6,10 +6,10 @@

Error.

An error occurred while processing your request.

-@if (Model.ShowRequestId) +@if (ViewBag.Data.ShowRequestId) {

- Request ID: @Model.RequestId + Request ID: @ViewBag.Data.RequestId

} diff --git a/Canteen/CanteenRestApi/CanteenRestApi.csproj b/Canteen/CanteenRestApi/CanteenRestApi.csproj index ca38aec..9c6c316 100644 --- a/Canteen/CanteenRestApi/CanteenRestApi.csproj +++ b/Canteen/CanteenRestApi/CanteenRestApi.csproj @@ -7,7 +7,11 @@ - True + False + + + + False diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index 37419af..131414e 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -2,6 +2,7 @@ using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.View; +using CanteenDataModels.Models; using Microsoft.AspNetCore.Mvc; namespace CanteenRestApi.Controllers @@ -39,6 +40,19 @@ namespace CanteenRestApi.Controllers } } [HttpGet] + public List? 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? GetTablewareList() { try @@ -77,6 +91,7 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpPost] public void DeleteCook(CookBindingModel model) { @@ -90,6 +105,7 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpPost] public void CreateDish(DishBindingModel model) { @@ -116,5 +132,19 @@ namespace CanteenRestApi.Controllers throw; } } + + [HttpPost] + public void AddCooksToProduct(Tuple model) + { + try + { + _product.AddCooksToProduct(model.Item1, model.Item2); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } } } \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj index 8951bd9..e7b320f 100644 --- a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj +++ b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj @@ -7,7 +7,11 @@ - True + False + + + + False diff --git a/Canteen/CanteenVisitorApp/Views/Shared/Error.cshtml b/Canteen/CanteenVisitorApp/Views/Shared/Error.cshtml index a1e0478..d31cf3e 100644 --- a/Canteen/CanteenVisitorApp/Views/Shared/Error.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Shared/Error.cshtml @@ -6,10 +6,10 @@

Error.

An error occurred while processing your request.

-@if (Model.ShowRequestId) +@if (ViewBag.Data.ShowRequestId) {

- Request ID: @Model.RequestId + Request ID: @ViewBag.Data.RequestId

}