diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/CookLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/CookLogic.cs index c1e4314..e876417 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/CookLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/CookLogic.cs @@ -116,7 +116,7 @@ namespace CanteenBusinessLogic.BusinessLogics if (model.ManagerId <= 0) { - throw new ArgumentNullException("id менеджера должен дыть больше 0", nameof(model.ManagerId)); + throw new ArgumentNullException("id менеджера должен быть больше 0", nameof(model.ManagerId)); } if (string.IsNullOrEmpty(model.Position)) diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs index 2557bd4..d20b917 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -115,11 +116,6 @@ namespace CanteenBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия блюда", nameof(model.DishName)); } - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена блюда должна быть больше 0", nameof(model.Price)); - } - if (model.ManagerId <= 0) { throw new ArgumentNullException("id менеджера должен быть больше 0", nameof(model.ManagerId)); @@ -133,5 +129,25 @@ namespace CanteenBusinessLogic.BusinessLogics throw new InvalidOperationException("Блюдо с таким названием уже есть"); } } + + public bool AddCooksToProduct(DishSearchModel model, ProductViewModel product, int count) + { + var dish = _dishStorage.GetElement(model); + dish.DishProducts[product.Id] = (product, count); + if (_dishStorage.Update(new() + { + Id = dish.Id, + DishName = dish.DishName, + ManagerId = dish.ManagerId, + DishProducts = dish.DishProducts + + }) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } } } diff --git a/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs b/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs index f1a9ada..b262b07 100644 --- a/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs @@ -12,6 +12,5 @@ namespace CanteenContracts.BindingModels public int Id { get; set; } public int VisitorId { get; set; } public string TablewareName { get; set; } = string.Empty; - public int Count { get; set; } } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs index d328dcc..c3f49a1 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs @@ -16,5 +16,6 @@ namespace CanteenContracts.BusinessLogicsContracts bool Create(DishBindingModel model); bool Update(DishBindingModel model); bool Delete(DishBindingModel model); + bool AddCooksToProduct(DishSearchModel model, ProductViewModel product, int count); } } diff --git a/Canteen/CanteenContracts/ViewModels/DishViewModel.cs b/Canteen/CanteenContracts/ViewModels/DishViewModel.cs index 8ea7f6d..4f7b293 100644 --- a/Canteen/CanteenContracts/ViewModels/DishViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/DishViewModel.cs @@ -1,4 +1,5 @@ using CanteenDataModels.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -18,5 +19,11 @@ namespace CanteenContracts.View public int ManagerId { get; set; } public int Id { get; set; } public Dictionary DishProducts { get; set; } + public DishViewModel() { } + [JsonConstructor] + public DishViewModel(Dictionary DishProducts) + { + this.DishProducts = DishProducts.ToDictionary(x => x.Key, x => (x.Value.Item1 as IProductModel, x.Value.Item2)); + } } } diff --git a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs index 3373526..f02cab0 100644 --- a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs @@ -15,8 +15,6 @@ namespace CanteenContracts.View [DisplayName("Название прибора")] public string TablewareName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } [DisplayName("ID прибора")] public int Id { get; set; } } diff --git a/Canteen/CanteenDataModels/Models/ITablewareModel.cs b/Canteen/CanteenDataModels/Models/ITablewareModel.cs index 4adc942..4f5f200 100644 --- a/Canteen/CanteenDataModels/Models/ITablewareModel.cs +++ b/Canteen/CanteenDataModels/Models/ITablewareModel.cs @@ -10,6 +10,5 @@ namespace CanteenDataModels.Models { int VisitorId { get; } string TablewareName { get; } - int Count { get; } } } diff --git a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs index b3a1ae6..fa30e77 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs @@ -32,7 +32,7 @@ namespace CanteenDatabaseImplement.Implements public List GetFilteredList(DishSearchModel model) { - if (string.IsNullOrEmpty(model.DishName)) + if (string.IsNullOrEmpty(model.DishName) && !model.ManagerId.HasValue) { return new(); } @@ -99,6 +99,8 @@ namespace CanteenDatabaseImplement.Implements dish.Update(model); context.SaveChanges(); + if (model.DishProducts != null) + dish.UpdateDishProduct(context, model); context.Database.CommitTransaction(); return dish.GetViewModel; diff --git a/Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.Designer.cs b/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs similarity index 98% rename from Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.Designer.cs rename to Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs index 8cec8ef..c314402 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.Designer.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CanteenDatabaseImplement.Migrations { [DbContext(typeof(CanteenDatabase))] - [Migration("20230408175356_InitialMigr")] - partial class InitialMigr + [Migration("20230517172033_InitMigr")] + partial class InitMigr { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -210,6 +210,9 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CountTablewares") + .HasColumnType("int"); + b.Property("Description") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -217,7 +220,8 @@ namespace CanteenDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("float"); - b.Property("TablewareId") + b.Property("TablewareId") + .IsRequired() .HasColumnType("int"); b.Property("VisitorId") @@ -322,9 +326,6 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); - b.Property("TablewareName") .IsRequired() .HasColumnType("nvarchar(max)"); diff --git a/Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.cs b/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs similarity index 99% rename from Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.cs rename to Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs index 4b1b6fc..2242219 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/20230408175356_InitialMigr.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace CanteenDatabaseImplement.Migrations { /// - public partial class InitialMigr : Migration + public partial class InitMigr : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -137,8 +137,7 @@ namespace CanteenDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), VisitorId = table.Column(type: "int", nullable: false), - TablewareName = table.Column(type: "nvarchar(max)", nullable: false), - Count = table.Column(type: "int", nullable: false) + TablewareName = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { @@ -230,6 +229,7 @@ namespace CanteenDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), VisitorId = table.Column(type: "int", nullable: false), TablewareId = table.Column(type: "int", nullable: false), + CountTablewares = table.Column(type: "int", nullable: true), Description = table.Column(type: "nvarchar(max)", nullable: false), Sum = table.Column(type: "float", nullable: true) }, diff --git a/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs b/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs index 4730a9a..6acfe8a 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs @@ -207,6 +207,9 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CountTablewares") + .HasColumnType("int"); + b.Property("Description") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -214,7 +217,8 @@ namespace CanteenDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("float"); - b.Property("TablewareId") + b.Property("TablewareId") + .IsRequired() .HasColumnType("int"); b.Property("VisitorId") @@ -319,9 +323,6 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); - b.Property("TablewareName") .IsRequired() .HasColumnType("nvarchar(max)"); diff --git a/Canteen/CanteenDatabaseImplement/Models/Dish.cs b/Canteen/CanteenDatabaseImplement/Models/Dish.cs index 55df1ed..4eb74da 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Dish.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Dish.cs @@ -12,84 +12,6 @@ using System.Threading.Tasks; namespace CanteenDatabaseImplement.Models { - //public class Dish : IDishModel - //{ - // public int Id { get; private set; } - // [Required] - // public string DishName { get; private set; } = string.Empty; - // [Required] - // public double Cost { get; private set; } - // [Required] - // public int ManagerId { get; private set; } - // private Dictionary? _dishProduct = null; - // public Dictionary DishProduct - // { - // get - // { - // if (_dishProduct == null) - // { - // _dishProduct = Product - // .ToDictionary(recPC => recPC.ProductId, recPC => (recPC.Product as IProductModel, recPC.CountProductProduct)); - // } - // return _dishProduct; - // } - // } - // [ForeignKey("DishId")] - // public virtual List Product { get; set; } = new(); - // public static Dish? Create(CanteenDatabase context, DishBindingModel model) - // { - // return new Dish() - // { - // Id = model.Id, - // DishName = model.DishName, - // Cost = model.Cost, - // Product = model.DishProduct.Select(x => new DishProduct - // { - // Product = context.Product.First(y => y.Id == x.Key) - // }).ToList() - // }; - // } - - // public void Update(DishBindingModel model) - // { - // DishName = model.DishName; - // Cost = model.Cost; - // } - - // public DishViewModel GetViewModel => new() - // { - // Id = Id, - // DishName = DishName, - // Cost = Cost, - // DishProduct = DishProduct, - // ManagerId = ManagerId - // }; - - // public Dictionary DishProduct => throw new NotImplementedException(); - - // public void UpdateProduct(CanteenDatabase context, DishBindingModel model) - // { - // var dishProduct = context.DishProduct.Where(record => record.ProductId == model.Id).ToList(); - // if (dishProduct != null && dishProduct.CountProduct > 0) - // { - // context.DishProduct.RemoveRange(dishProduct.Where(record => !model.DishProduct.ContainsKey(record.ProductId))); - // context.SaveChanges(); - // } - - // var product = context.Product.First(x => x.Id == Id); - // foreach (var pc in model.DishProduct) - // { - // context.DishProduct.Add(new DishProduct - // { - // Product = product, - // Dish = context.Dishes.First(x => x.Id == pc.Key), - // }); - // context.SaveChanges(); - // } - - // _dishProduct = null; - // } - //} public class Dish : IDishModel { public int Id { get; set; } diff --git a/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs b/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs index 95fffc7..8b736b7 100644 --- a/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs +++ b/Canteen/CanteenDatabaseImplement/Models/ProductCook.cs @@ -10,7 +10,7 @@ namespace CanteenDatabaseImplement.Models { public class ProductCook { - public int Id { get; private set; } + public int Id { get; set; } [Required] public int ProductId { get; set; } diff --git a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs index 96b52b1..aa3b507 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs @@ -19,8 +19,6 @@ namespace CanteenDatabaseImplement.Models public int VisitorId { get; private set; } [Required] public string TablewareName { get; private set; } = string.Empty; - [Required] - public int Count { get; private set; } [ForeignKey("TablewareId")] public virtual List Orders { get; set; } = new(); public virtual Visitor Visitor { get; set; } @@ -35,8 +33,7 @@ namespace CanteenDatabaseImplement.Models { Id = model.Id, VisitorId = model.VisitorId, - TablewareName = model.TablewareName, - Count = model.Count + TablewareName = model.TablewareName }; } diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index edd5017..3bab88b 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -77,8 +77,6 @@ namespace CanteenManagerApp.Controllers }); Response.Redirect("Enter"); - - return; } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] @@ -88,18 +86,18 @@ namespace CanteenManagerApp.Controllers } [HttpGet] - public IActionResult Cooks() + public IActionResult CookList() { if (APIClient.Manager == null) { return Redirect("~/Home/Enter"); } - ViewBag.Cooks = APIClient.GetRequest>($"api/main/getcooklist? ={APIClient.Manager.Id}"); + ViewBag.CookList = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); return View(); } [HttpGet] - public IActionResult CreateCook() + public IActionResult CookCreate() { if (APIClient.Manager == null) { @@ -109,7 +107,7 @@ namespace CanteenManagerApp.Controllers } [HttpPost] - public void CreateCook(string FIO, string position) + public void CookCreate(string FIO, string position) { if (APIClient.Manager == null) { @@ -121,77 +119,96 @@ namespace CanteenManagerApp.Controllers throw new Exception("ФИО не должно быть пустым"); } - APIClient.PostRequest("api/main/createcook", new CookBindingModel + APIClient.PostRequest("api/main/cookcreate", new CookBindingModel { ManagerId = APIClient.Manager.Id, FIO = FIO, Position = position }); - Response.Redirect("Cooks"); + Response.Redirect("CookList"); } [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() + public IActionResult CookDelete() { if (APIClient.Manager == null) { return Redirect("~/Home/Enter"); } + ViewBag.CookList = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); return View(); } - [HttpPost] - public void UpdateCook(string FIO, string postition) + public void CookDelete(int id) { if (APIClient.Manager == null) { throw new Exception("Доступ возможен только авторизованным пользователям"); } - APIClient.PostRequest("api/main/updatecook", new CookBindingModel + if (id <= 0) { - Id = APIClient.Manager.Id, - FIO = FIO, - Position = postition + throw new Exception("Выберите повара"); + } + APIClient.PostRequest("api/main/CookDelete", new CookBindingModel + { + Id = id }); - Response.Redirect("Cooks"); - } + Response.Redirect("CookList"); + } [HttpGet] - public IActionResult Products() + public IActionResult CookUpdate() { 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}"); + ViewBag.CookList = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); return View(); } [HttpPost] - public void CreateProduct(string name, double price) + public void CookUpdate(int Id, string FIO, string position) + { + if (APIClient.Manager == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + APIClient.PostRequest("api/main/CookUpdate", new CookBindingModel + { + Id = Id, + FIO = FIO, + Position = position, + ManagerId = APIClient.Manager.Id + }); + Response.Redirect("CookList"); + } + + [HttpGet] + public IActionResult ProductList() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.ProductList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); + return View(); + } + + [HttpGet] + public IActionResult ProductCreate() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.CookList = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); + return View(); + } + + [HttpPost] + public void ProductCreate(string name, double price) { if (APIClient.Manager == null) { @@ -202,29 +219,29 @@ namespace CanteenManagerApp.Controllers { throw new Exception("Наименование продукта не должно быть пустым"); } - APIClient.PostRequest("api/main/createproduct", new ProductBindingModel + APIClient.PostRequest("api/main/ProductCreate", new ProductBindingModel { ManagerId = APIClient.Manager.Id, ProductName = name, Price = price }); - Response.Redirect("Products"); + Response.Redirect("ProductList"); } [HttpGet] - public IActionResult AddCooksToProduct() + public IActionResult ProductAddCooks() { 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}"); + ViewBag.ProductList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); + ViewBag.CookList = APIClient.GetRequest>($"api/main/getcooklist?managerId={APIClient.Manager.Id}"); return View(); } [HttpPost] - public void AddCooksToProduct(int selectedProduct, int selectedCook) + public void ProductAddCooks(int selectedProduct, int selectedCook) { if (APIClient.Manager == null) { @@ -239,64 +256,85 @@ namespace CanteenManagerApp.Controllers { throw new Exception("Должен быть выбран повар"); } - APIClient.PostRequest("api/main/addcookstoproduct", Tuple.Create + APIClient.PostRequest("api/main/ProductAddCooks", Tuple.Create ( new ProductSearchModel { Id = selectedProduct }, new CookViewModel { Id = selectedCook } )); - Response.Redirect("Products"); + Response.Redirect("ProductList"); } [HttpGet] - public IActionResult DeleteProduct(int productId) + public IActionResult ProductDelete() { 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(); + ViewBag.ProductList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); + return Redirect("~/Home/ProductList"); } [HttpPost] - public void UpdateProduct(string productName, double price) + public void ProductDelete(int id) { if (APIClient.Manager == null) { throw new Exception("Доступ возможен только авторизованным пользователям"); } - APIClient.PostRequest("api/main/updateproduct", new ProductBindingModel + if (id <= 0) { - Id = APIClient.Manager.Id, - ProductName = productName, - Price = price + throw new Exception("Выберите продукт"); + } + APIClient.PostRequest("api/main/ProductDelete", new ProductBindingModel + { + Id = id }); - Response.Redirect("Products"); + + Response.Redirect("ProductList"); } [HttpGet] - public IActionResult Dishes() + public IActionResult ProductUpdate() { if (APIClient.Manager == null) { return Redirect("~/Home/Enter"); } - ViewBag.Dishes = APIClient.GetRequest>($"api/main/getdishlist?managerId={APIClient.Manager.Id}"); + ViewBag.ProductList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); + return View(); + } + + [HttpPost] + public void ProductUpdate(int Id, string name, double price) + { + if (APIClient.Manager == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + APIClient.PostRequest("api/main/productupdate", new ProductBindingModel + { + Id = Id, + ProductName = name, + Price = price, + ManagerId = APIClient.Manager.Id + }); + Response.Redirect("ProductList"); + } + + [HttpGet] + public IActionResult DishList() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DishList = APIClient.GetRequest>($"api/main/GetDishList?managerId={APIClient.Manager.Id}"); return View(); } [HttpGet] - public IActionResult CreateDish() + public IActionResult DishCreate() { if (APIClient.Manager == null) { @@ -306,63 +344,123 @@ namespace CanteenManagerApp.Controllers } [HttpPost] - public void CreateDish(string dishName, double price) + public void DishCreate(string name) { if (APIClient.Manager == null) { throw new Exception("Доступ возможен только авторизованным пользователям"); } - if (string.IsNullOrEmpty(dishName)) + if (string.IsNullOrEmpty(name)) { throw new Exception("Наименование блюда не должно быть пустым"); } - APIClient.PostRequest("api/main/createdish", new DishBindingModel + APIClient.PostRequest("api/main/dishcreate", new DishBindingModel { ManagerId = APIClient.Manager.Id, - DishName = dishName, - Price = price + DishName = name }); - Response.Redirect("Dishes"); + Response.Redirect("DishList"); } [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() + public IActionResult DishAddProducts() { if (APIClient.Manager == null) { return Redirect("~/Home/Enter"); } + ViewBag.DishList = APIClient.GetRequest>($"api/main/getdishlist?managerId={APIClient.Manager.Id}"); + ViewBag.productList = APIClient.GetRequest>($"api/main/getproductlist?managerId={APIClient.Manager.Id}"); return View(); } [HttpPost] - public void UpdateDish(string dishName, double price) + public void DishAddProducts(int selectedDish, int selectedProduct, int count) { if (APIClient.Manager == null) { throw new Exception("Доступ возможен только авторизованным пользователям"); } - APIClient.PostRequest("api/main/updatedish", new DishBindingModel + + if (selectedDish <= 0) { - Id = APIClient.Manager.Id, - DishName = dishName, - Price = price + throw new Exception("Должно быть выбрано блюдо"); + } + if (selectedProduct <= 0) + { + throw new Exception("Должен быть выбран продукт"); + } + if (count <= 0) + { + throw new Exception("Количество продукта должно быть больше 0"); + } + APIClient.PostRequest("api/main/dishaddproducts", Tuple.Create + ( + new DishSearchModel { Id = selectedDish }, + new ProductViewModel { Id = selectedProduct }, + count + )); + + Response.Redirect("DishList"); + } + + [HttpGet] + public IActionResult DishDelete() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DishList = APIClient.GetRequest>($"api/main/getdishlist?managerId={APIClient.Manager.Id}"); + return View(); + } + [HttpPost] + public void DishDelete(int id) + { + if (APIClient.Manager == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + if (id <= 0) + { + throw new Exception("Выберите блюдо"); + } + APIClient.PostRequest("api/main/DishDelete", new DishBindingModel + { + Id = id }); - Response.Redirect("Dishes"); + + Response.Redirect("ProductList"); + } + [HttpGet] + public IActionResult DishUpdate() + { + if (APIClient.Manager == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DishList = APIClient.GetRequest>($"api/main/getdishlist?managerId={APIClient.Manager.Id}"); + return View(); + } + + [HttpPost] + public void DishUpdate(int Id, string name, double price) + { + if (APIClient.Manager == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + APIClient.PostRequest("api/main/DishUpdate", new DishBindingModel + { + Id = Id, + DishName = name, + Price = price, + ManagerId = APIClient.Manager.Id + }); + Response.Redirect("DishList"); } [HttpGet] public IActionResult Graphic() diff --git a/Canteen/CanteenManagerApp/Views/Home/CreateCook.cshtml b/Canteen/CanteenManagerApp/Views/Home/CookCreate.cshtml similarity index 94% rename from Canteen/CanteenManagerApp/Views/Home/CreateCook.cshtml rename to Canteen/CanteenManagerApp/Views/Home/CookCreate.cshtml index 9eed680..8ce32ec 100644 --- a/Canteen/CanteenManagerApp/Views/Home/CreateCook.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/CookCreate.cshtml @@ -1,6 +1,6 @@  @{ - ViewData["Title"] = "Cook"; + ViewData["Title"] = "CookList"; }

Добавление повара

diff --git a/Canteen/CanteenManagerApp/Views/Home/DeleteCook.cshtml b/Canteen/CanteenManagerApp/Views/Home/CookDelete.cshtml similarity index 80% rename from Canteen/CanteenManagerApp/Views/Home/DeleteCook.cshtml rename to Canteen/CanteenManagerApp/Views/Home/CookDelete.cshtml index b9601fc..fc4ba89 100644 --- a/Canteen/CanteenManagerApp/Views/Home/DeleteCook.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/CookDelete.cshtml @@ -13,7 +13,7 @@
Выберите повара
- +
diff --git a/Canteen/CanteenManagerApp/Views/Home/CookList.cshtml b/Canteen/CanteenManagerApp/Views/Home/CookList.cshtml new file mode 100644 index 0000000..9f19be7 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/CookList.cshtml @@ -0,0 +1,30 @@ +@{ + ViewData["Title"] = "CookList"; +} + +
+

Список поваров

+ Добавить повара + Удалить повара + Обновить повара + + + + + + + + + + @foreach (var cook in ViewBag.CookList) + { + + + + + + } + +
НомерФИОДолжность
@cook.Id@cook.FIO@cook.Position
+
+ \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml.cs b/Canteen/CanteenManagerApp/Views/Home/CookList.cshtml.cs similarity index 80% rename from Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml.cs rename to Canteen/CanteenManagerApp/Views/Home/CookList.cshtml.cs index 60da7bf..d5e6463 100644 --- a/Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml.cs +++ b/Canteen/CanteenManagerApp/Views/Home/CookList.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace CanteenManagerApp.Views.Home +namespace CanteenManagerApp.Views.Home.Cook { public class CooksModel : PageModel { diff --git a/Canteen/CanteenManagerApp/Views/Home/CookUpdate.cshtml b/Canteen/CanteenManagerApp/Views/Home/CookUpdate.cshtml new file mode 100644 index 0000000..329a04d --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/CookUpdate.cshtml @@ -0,0 +1,44 @@ +@using Newtonsoft.Json; +@{ + ViewData["Title"] = "CookUpdate"; +} +
+

Данные повара

+
+
+
+
Повар:
+
+
+
+
ФИО:
+
+
+
+
Должность:
+
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml b/Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml deleted file mode 100644 index 51a91f8..0000000 --- a/Canteen/CanteenManagerApp/Views/Home/Cooks.cshtml +++ /dev/null @@ -1,59 +0,0 @@ -@{ - ViewData["Title"] = "Cooks"; -} - -
-

Список поваров

- Добавить повара - - Обновить повара - - - - - - - - - - @foreach (var cook in ViewBag.Cooks) - { - - - - - - } - -
НомерФИОДолжность
@cook.Id@cook.FIO@cook.Position
-
- -
- -
- - \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/DIshDelete.cshtml b/Canteen/CanteenManagerApp/Views/Home/DIshDelete.cshtml new file mode 100644 index 0000000..ec751e9 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/DIshDelete.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "DishDelete"; +} +
+

Удаление блюда

+
+ +
+
+
Выберите блюдо
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/DishAddProducts.cshtml b/Canteen/CanteenManagerApp/Views/Home/DishAddProducts.cshtml new file mode 100644 index 0000000..cae926c --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/DishAddProducts.cshtml @@ -0,0 +1,48 @@ +@using CanteenContracts.View; +@{ + ViewData["Title"] = "DishAddProducts"; +} +
+

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

+
+ +
+
+
Блюдо:
+
+ +
+
+
+
Продукт:
+
+ +
+
+
+
Количество:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/CreateDish.cshtml b/Canteen/CanteenManagerApp/Views/Home/DishCreate.cshtml similarity index 54% rename from Canteen/CanteenManagerApp/Views/Home/CreateDish.cshtml rename to Canteen/CanteenManagerApp/Views/Home/DishCreate.cshtml index cd9d2d2..f181adf 100644 --- a/Canteen/CanteenManagerApp/Views/Home/CreateDish.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/DishCreate.cshtml @@ -1,6 +1,6 @@  @{ - ViewData["Title"] = "Dish"; + ViewData["Title"] = "DishCreate"; }

Добавление блюда

@@ -14,14 +14,7 @@
Название блюда:
- - @* *@ -
-
-
-
Цена:
-
- +
diff --git a/Canteen/CanteenManagerApp/Views/Home/DishList.cshtml b/Canteen/CanteenManagerApp/Views/Home/DishList.cshtml new file mode 100644 index 0000000..d265696 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/DishList.cshtml @@ -0,0 +1,31 @@ +@{ + ViewData["Title"] = "DishList"; +} + +
+

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

+ Добавить блюдо + Удалить блюдо + Обновить блюдо + Привязать продукт + + + + + + + + + + @foreach (var cook in ViewBag.DishList) + { + + + + + + } + +
НомерНазваниеЦена
@cook.Id@cook.DishName@cook.Price
+
+ \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/DishUpdate.cshtml b/Canteen/CanteenManagerApp/Views/Home/DishUpdate.cshtml new file mode 100644 index 0000000..0cbc94a --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/DishUpdate.cshtml @@ -0,0 +1,38 @@ +@{ + ViewData["Title"] = "DishUpdate"; +} +
+

Данные блюда

+
+
+
+
Блюдо:
+
+
+
+
Название:
+
+
+
+
Цена:
+
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml b/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml deleted file mode 100644 index c1a3d00..0000000 --- a/Canteen/CanteenManagerApp/Views/Home/Dishes.cshtml +++ /dev/null @@ -1,59 +0,0 @@ -@{ - ViewData["Title"] = "Products"; -} - -
-

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

- Добавить продукт - - Обновить продукт - - - - - - - - - - @foreach (var cook in ViewBag.Cooks) - { - - - - - - } - -
НомерНазваниеЦена
@cook.Id@cook.Name@cook.Price
-
- -
- -
- - \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml b/Canteen/CanteenManagerApp/Views/Home/ProductAddCooks.cshtml similarity index 82% rename from Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml rename to Canteen/CanteenManagerApp/Views/Home/ProductAddCooks.cshtml index 9c79c8a..2e0a6f0 100644 --- a/Canteen/CanteenManagerApp/Views/Home/AddCooksToProduct.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/ProductAddCooks.cshtml @@ -1,6 +1,6 @@ @using CanteenContracts.View; @{ - ViewData["Title"] = "AddCooksToProduct"; + ViewData["Title"] = "ProductAddCooks"; }

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

@@ -15,7 +15,7 @@
Продукты:
- @foreach (var cook in ViewBag.Cooks as List) + @foreach (var cook in ViewBag.CookList as List) { } diff --git a/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml b/Canteen/CanteenManagerApp/Views/Home/ProductCreate.cshtml similarity index 60% rename from Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml rename to Canteen/CanteenManagerApp/Views/Home/ProductCreate.cshtml index fee4277..c416214 100644 --- a/Canteen/CanteenManagerApp/Views/Home/CreateProduct.cshtml +++ b/Canteen/CanteenManagerApp/Views/Home/ProductCreate.cshtml @@ -1,6 +1,6 @@ @using CanteenContracts.View; @{ - ViewData["Title"] = "Product"; + ViewData["Title"] = "ProductCreate"; }

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

@@ -20,18 +20,7 @@
Цена:
- -
-
-
-
Цена:
-
- +
diff --git a/Canteen/CanteenManagerApp/Views/Home/ProductDelete.cshtml b/Canteen/CanteenManagerApp/Views/Home/ProductDelete.cshtml new file mode 100644 index 0000000..631528c --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/ProductDelete.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "ProductDelete"; +} +
+

Удаление продукта

+
+ +
+
+
Выберите продукт
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/ProductList.cshtml b/Canteen/CanteenManagerApp/Views/Home/ProductList.cshtml new file mode 100644 index 0000000..4753c91 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/ProductList.cshtml @@ -0,0 +1,32 @@ +@using CanteenContracts.View; +@{ + ViewData["Title"] = "ProductList"; +} + +
+

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

+ Добавить продукт + Удалить продукт + Обновить продукт + Привязать повара + + + + + + + + + + @foreach (var product in ViewBag.ProductList) + { + + + + + + } + +
НомерНазваниеЦена
@product.Id@product.ProductName@product.Price
+
+ diff --git a/Canteen/CanteenManagerApp/Views/Home/ProductUpdate.cshtml b/Canteen/CanteenManagerApp/Views/Home/ProductUpdate.cshtml new file mode 100644 index 0000000..40e9fd7 --- /dev/null +++ b/Canteen/CanteenManagerApp/Views/Home/ProductUpdate.cshtml @@ -0,0 +1,38 @@ +@{ + ViewData["Title"] = "ProductUpdate"; +} +
+

Данные продукта

+
+
+
+
Повар:
+
+
+
+
ФИО:
+
+
+
+
Цена:
+
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/Canteen/CanteenManagerApp/Views/Home/Products.cshtml b/Canteen/CanteenManagerApp/Views/Home/Products.cshtml deleted file mode 100644 index 5447da9..0000000 --- a/Canteen/CanteenManagerApp/Views/Home/Products.cshtml +++ /dev/null @@ -1,61 +0,0 @@ -@using CanteenContracts.View; -@{ - ViewData["Title"] = "Products"; -} - -
-

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

- Добавить продукт - - Обновить продукт - Привязать повара - - - - - - - - - - @foreach (var product in ViewBag.Products) - { - - - - - - } - -
НомерНазваниеЦена
@product.Id@product.ProductName@product.Price
-
- -
- -
- - diff --git a/Canteen/CanteenManagerApp/Views/Home/UpdateCook.cshtml b/Canteen/CanteenManagerApp/Views/Home/UpdateCook.cshtml deleted file mode 100644 index e1dd794..0000000 --- a/Canteen/CanteenManagerApp/Views/Home/UpdateCook.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ -@{ -} diff --git a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml index c3faac9..f65f83e 100644 --- a/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml +++ b/Canteen/CanteenManagerApp/Views/Shared/_Layout.cshtml @@ -20,13 +20,13 @@