diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs index d20b917..341dc5a 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/DishLogic.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; @@ -130,16 +131,24 @@ namespace CanteenBusinessLogic.BusinessLogics } } - public bool AddCooksToProduct(DishSearchModel model, ProductViewModel product, int count) + public bool AddProductsToDish(DishBindingModel model, IProductModel product, int count) { - var dish = _dishStorage.GetElement(model); + var dish = _dishStorage.GetElement(new DishSearchModel { Id = model.Id}); dish.DishProducts[product.Id] = (product, count); + double allSum = 0; + foreach (var dishProduct in dish.DishProducts) + { + IProductModel _product = dishProduct.Value.Item1; + int _count = dishProduct.Value.Item2; + allSum += _product.Price * _count; + } if (_dishStorage.Update(new() { Id = dish.Id, DishName = dish.DishName, ManagerId = dish.ManagerId, - DishProducts = dish.DishProducts + DishProducts = dish.DishProducts, + Price = allSum }) == null) { diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/LunchLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/LunchLogic.cs index 0c14908..22e8828 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/LunchLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/LunchLogic.cs @@ -5,6 +5,7 @@ using CanteenContracts.SearchModels; using CanteenContracts.StoragesContracts; using CanteenContracts.View; using CanteenDataModels.Enums; +using CanteenDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -204,5 +205,15 @@ namespace CanteenBusinessLogic.BusinessLogics throw new InvalidOperationException("Такая связь уже есть"); } } + + public bool AddProductToLunch(LunchSearchModel model, IProductModel product, int count) + { + throw new NotImplementedException(); + } + + public bool AddOrderToLunch(LunchSearchModel model, IOrderModel order, int count) + { + throw new NotImplementedException(); + } } } diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/OrderLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/OrderLogic.cs index df74a98..3b193a5 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,6 +4,7 @@ using CanteenContracts.SearchModel; using CanteenContracts.SearchModels; using CanteenContracts.StoragesContracts; using CanteenContracts.View; +using CanteenDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -23,30 +24,15 @@ namespace CanteenBusinessLogic.BusinessLogics _logger = logger; _orderStorage = orderStorage; } - public bool AddCook(OrderCookBindingModel model) - { - CheckModel(model); - _logger.LogInformation("AddOrder. OrderId: {OrderId}. CookId: {CookId}", model.OrderId, model.CookId); - if (!_orderStorage.AddCook(model)) - { - _logger.LogWarning("AddOrder operation failed"); - return false; - } - return true; + public bool AddCooksToOrder(OrderSearchModel model, ICookModel cook) + { + throw new NotImplementedException(); } - public bool AddTableware(OrderTablewareBindingModel model) + public bool AddTablewareToOrder(OrderTablewareBindingModel model, ITablewareModel tableware, int count) { - CheckModel(model); - _logger.LogInformation("AddTableware. OrderId: {OrderId}. TablewareId: {TablewareId}", model.OrderId, model.TablewareId); - if (!_orderStorage.AddTableware(model)) - { - _logger.LogWarning("AddTableware operation failed"); - return false; - } - - return true; + throw new NotImplementedException(); } public bool Create(OrderBindingModel model) @@ -229,10 +215,10 @@ namespace CanteenBusinessLogic.BusinessLogics _logger.LogInformation("OrderTableware. OrderId: {OrderId}. TablewareId: {TablewareId}. VisitorId: {VisitorId}. CountTablewares: {CountTablewares}", model.OrderId, model.TablewareId, model.VisitorId, model.CountTablewares); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.OrderId}); - if (element != null && element.Id == model.OrderId && element.TablewareId == model.TablewareId) - { - throw new InvalidOperationException("Такая связь уже есть"); - } + //if (element != null && element.Id == model.OrderId && element.TablewareId == model.TablewareId) + //{ + // throw new InvalidOperationException("Такая связь уже есть"); + //} } } } diff --git a/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs b/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs index 8286564..718893c 100644 --- a/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs @@ -18,6 +18,6 @@ namespace CanteenContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } public Dictionary LunchProducts { get; set; } = new Dictionary(); + public Dictionary LunchOrders { get; set; } = new Dictionary(); } - } diff --git a/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs b/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs index c990938..4fba46e 100644 --- a/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs @@ -16,7 +16,8 @@ namespace CanteenContracts.BindingModels public double? Sum { get; set; } public int? TablewareId { get; set; } public int? CountTablewares { get; set; } - public Dictionary OrderDishes { get; set; } = new (); + public Dictionary OrderCooks { get; set; } = new (); + public Dictionary OrderTablewares { get; set; } = new (); } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs index c3f49a1..f69354d 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IDishLogic.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,6 +17,6 @@ namespace CanteenContracts.BusinessLogicsContracts bool Create(DishBindingModel model); bool Update(DishBindingModel model); bool Delete(DishBindingModel model); - bool AddCooksToProduct(DishSearchModel model, ProductViewModel product, int count); + bool AddProductsToDish(DishBindingModel model, IProductModel product, int count); } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs index 65fd433..63374e2 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/ILunchLogic.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; @@ -17,6 +18,7 @@ namespace CanteenContracts.BusinessLogicsContracts bool Update(LunchBindingModel model); bool Delete(LunchBindingModel model); bool Finish(LunchBindingModel model); - bool AddOrder(LunchOrderBindingModel model); + bool AddProductToLunch(LunchSearchModel model, IProductModel product, int count); + bool AddOrderToLunch(LunchSearchModel model, IOrderModel order, int count); } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs index c69cd5a..f30a37d 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.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,7 +17,7 @@ namespace CanteenContracts.BusinessLogicsContracts bool Create(OrderBindingModel model); bool Delete(OrderBindingModel model); bool Update(OrderBindingModel model); - bool AddCook(OrderCookBindingModel model); - bool AddTableware(OrderTablewareBindingModel model); + bool AddTablewareToOrder(OrderTablewareBindingModel model, ITablewareModel tableware, int count); + bool AddCooksToOrder(OrderSearchModel model, ICookModel cook); } } diff --git a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs index 7315071..7bf4105 100644 --- a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs +++ b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs @@ -20,7 +20,5 @@ namespace CanteenContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); - bool AddCook(OrderCookBindingModel model); - bool AddTableware(OrderTablewareBindingModel model); } } diff --git a/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs b/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs index 914ca70..c6c1eb9 100644 --- a/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs @@ -17,11 +17,10 @@ namespace CanteenContracts.View public string Description { get; set; } = string.Empty; [DisplayName("Сумма")] public double? Sum { get; set; } - public Dictionary OrderDishes { get; set; } = new Dictionary(); + public Dictionary OrderCooks { get; set; } = new Dictionary(); + public Dictionary OrderTablewares { get; set; } = new Dictionary(); [DisplayName("ID заказа")] public int Id { get; set; } - public int? TablewareId { get; set; } - public int? CountTablewares { get; set; } } } diff --git a/Canteen/CanteenDataModels/Models/IOrderModel.cs b/Canteen/CanteenDataModels/Models/IOrderModel.cs index 65e8832..a1eef5d 100644 --- a/Canteen/CanteenDataModels/Models/IOrderModel.cs +++ b/Canteen/CanteenDataModels/Models/IOrderModel.cs @@ -10,10 +10,9 @@ namespace CanteenDataModels.Models public interface IOrderModel : IId { int VisitorId { get; } - int? TablewareId { get; } - int? CountTablewares { get; } string Description { get; } double? Sum { get; } - Dictionary OrderDishes { get; } + Dictionary OrderCooks { get; } + Dictionary OrderTablewares { get; } } } diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index 170b0b7..c87f044 100644 --- a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs +++ b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs @@ -11,15 +11,12 @@ namespace CanteenDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-PA5STI0\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-A68O3K0;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity() - .HasKey(dp => new { dp.DishId, dp.ProductId }); - modelBuilder.Entity() .HasOne(dp => dp.Dish) .WithMany(d => d.Products) @@ -32,8 +29,6 @@ namespace CanteenDatabaseImplement .HasForeignKey(dp => dp.ProductId) .OnDelete(DeleteBehavior.NoAction); //===================================== - modelBuilder.Entity() - .HasKey(dp => new { dp.LunchId, dp.OrderId }); modelBuilder.Entity() .HasOne(dp => dp.Lunch) @@ -47,8 +42,6 @@ namespace CanteenDatabaseImplement .HasForeignKey(dp => dp.OrderId) .OnDelete(DeleteBehavior.NoAction); //===================================== - modelBuilder.Entity() - .HasKey(dp => new { dp.LunchId, dp.ProductId }); modelBuilder.Entity() .HasOne(dp => dp.Lunch) @@ -62,8 +55,6 @@ namespace CanteenDatabaseImplement .HasForeignKey(dp => dp.ProductId) .OnDelete(DeleteBehavior.NoAction); //===================================== - modelBuilder.Entity() - .HasKey(dp => new { dp.OrderId, dp.CookId }); modelBuilder.Entity() .HasOne(dp => dp.Order) @@ -77,23 +68,19 @@ namespace CanteenDatabaseImplement .HasForeignKey(dp => dp.CookId) .OnDelete(DeleteBehavior.NoAction); //===================================== - modelBuilder.Entity() - .HasKey(dp => new { dp.OrderId, dp.DishId }); - modelBuilder.Entity() + modelBuilder.Entity() .HasOne(dp => dp.Order) - .WithMany(d => d.Dishes) + .WithMany(d => d.Tablewares) .HasForeignKey(dp => dp.OrderId) .OnDelete(DeleteBehavior.NoAction); - modelBuilder.Entity() - .HasOne(dp => dp.Dish) + modelBuilder.Entity() + .HasOne(dp => dp.Tableware) .WithMany(p => p.Orders) - .HasForeignKey(dp => dp.DishId) + .HasForeignKey(dp => dp.TablewareId) .OnDelete(DeleteBehavior.NoAction); //===================================== - modelBuilder.Entity() - .HasKey(dp => new { dp.ProductId, dp.CookId }); modelBuilder.Entity() .HasOne(dp => dp.Product) @@ -125,7 +112,7 @@ namespace CanteenDatabaseImplement public virtual DbSet Products { set; get; } public virtual DbSet ProductCook { set; get; } public virtual DbSet LunchProduct { set; get; } - public virtual DbSet OrderDish { set; get; } + public virtual DbSet OrderTableware { set; get; } public virtual DbSet DishProduct { set; get; } public virtual DbSet Tablewares { set; get; } public virtual DbSet Visitors { set; get; } diff --git a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs index fa30e77..394c755 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/DishStorage.cs @@ -99,8 +99,7 @@ namespace CanteenDatabaseImplement.Implements dish.Update(model); context.SaveChanges(); - if (model.DishProducts != null) - dish.UpdateDishProduct(context, model); + dish.UpdateDishProduct(context, model); context.Database.CommitTransaction(); return dish.GetViewModel; diff --git a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs index 46b3212..5c9e277 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/LunchStorage.cs @@ -60,7 +60,6 @@ namespace CanteenDatabaseImplement.Implements (model.VisitorId.HasValue && model.VisitorId == x.VisitorId)) .Select(x => x.GetViewModel).ToList(); } - public List GetFullList() { using var context = new CanteenDatabase(); @@ -69,7 +68,6 @@ namespace CanteenDatabaseImplement.Implements .ThenInclude(x => x.Product) .Select(x => x.GetViewModel).ToList(); } - public LunchViewModel? Insert(LunchBindingModel model) { using var context = new CanteenDatabase(); @@ -99,7 +97,6 @@ namespace CanteenDatabaseImplement.Implements } } } - public LunchViewModel? Update(LunchBindingModel model) { using var context = new CanteenDatabase(); @@ -118,6 +115,10 @@ namespace CanteenDatabaseImplement.Implements lunch.Update(model); context.SaveChanges(); + if (model.LunchProducts != null) + lunch.UpdateProducts(context, model); + if (model.LunchOrders != null) + lunch.UpdateOrders(context, model); context.Database.CommitTransaction(); return lunch.GetViewModel; @@ -129,7 +130,6 @@ namespace CanteenDatabaseImplement.Implements } } } - public LunchViewModel? Delete(LunchBindingModel model) { using var context = new CanteenDatabase(); diff --git a/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs index dcd6f93..ce71536 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/OrderStorage.cs @@ -115,58 +115,5 @@ namespace CanteenDatabaseImplement.Implements return client.GetViewModel; } - - public bool AddCook(OrderCookBindingModel orderCook) - { - using var context = new CanteenDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - if (context.OrderCook.FirstOrDefault(rec => rec.OrderId == orderCook.OrderId && rec.CookId == orderCook.CookId) != null) - { - return false; - } - else - { - context.OrderCook.Add(new OrderCook { OrderId = orderCook.OrderId, CookId = orderCook.CookId }); - } - context.SaveChanges(); - transaction.Commit(); - return true; - } - catch - { - transaction.Rollback(); - throw; - } - } - - public bool AddTableware(OrderTablewareBindingModel model) - { - using var context = new CanteenDatabase(); - using var transaction = context.Database.BeginTransaction(); - try - { - if (context.Orders.FirstOrDefault(rec => rec.Id == model.OrderId && rec.TablewareId == model.TablewareId) != null) - { - var order = context.Orders.FirstOrDefault(rec => rec.Id == model.OrderId && rec.TablewareId == model.TablewareId); - order.CountTablewares = model.CountTablewares; - } - else - { - var order = context.Orders.FirstOrDefault(rec => rec.Id == model.OrderId); - order.TablewareId = model.TablewareId; - order.CountTablewares = model.CountTablewares; - } - context.SaveChanges(); - transaction.Commit(); - return true; - } - catch - { - transaction.Rollback(); - throw; - } - } } } diff --git a/Canteen/CanteenDatabaseImplement/Implements/TablewareStorage.cs b/Canteen/CanteenDatabaseImplement/Implements/TablewareStorage.cs index 4e48fae..57af0a3 100644 --- a/Canteen/CanteenDatabaseImplement/Implements/TablewareStorage.cs +++ b/Canteen/CanteenDatabaseImplement/Implements/TablewareStorage.cs @@ -27,7 +27,7 @@ namespace CanteenDatabaseImplement.Implements public List GetFilteredList(TablewareSearchModel model) { - if (string.IsNullOrEmpty(model.TablewareName)) + if (!model.VisitorId.HasValue) { return new(); } diff --git a/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs b/Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.Designer.cs similarity index 92% rename from Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs rename to Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.Designer.cs index c314402..7e8305e 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.Designer.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CanteenDatabaseImplement.Migrations { [DbContext(typeof(CanteenDatabase))] - [Migration("20230517172033_InitMigr")] - partial class InitMigr + [Migration("20230518211530_Init")] + partial class Init { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -78,19 +78,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountProducts") + .HasColumnType("int"); + b.Property("DishId") .HasColumnType("int"); b.Property("ProductId") .HasColumnType("int"); - b.Property("CountProducts") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("DishId", "ProductId"); + b.HasIndex("DishId"); b.HasIndex("ProductId"); @@ -133,19 +138,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountOrders") + .HasColumnType("int"); + b.Property("LunchId") .HasColumnType("int"); b.Property("OrderId") .HasColumnType("int"); - b.Property("CountOrders") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("LunchId", "OrderId"); + b.HasIndex("LunchId"); b.HasIndex("OrderId"); @@ -154,19 +164,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountProducts") + .HasColumnType("int"); + b.Property("LunchId") .HasColumnType("int"); b.Property("ProductId") .HasColumnType("int"); - b.Property("CountProducts") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("LunchId", "ProductId"); + b.HasIndex("LunchId"); b.HasIndex("ProductId"); @@ -210,9 +225,6 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CountTablewares") - .HasColumnType("int"); - b.Property("Description") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -220,17 +232,11 @@ namespace CanteenDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("float"); - b.Property("TablewareId") - .IsRequired() - .HasColumnType("int"); - b.Property("VisitorId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("TablewareId"); - b.HasIndex("VisitorId"); b.ToTable("Orders"); @@ -238,41 +244,51 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b => { - b.Property("OrderId") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CookId") .HasColumnType("int"); - b.Property("Id") + b.Property("OrderId") .HasColumnType("int"); - b.HasKey("OrderId", "CookId"); + b.HasKey("Id"); b.HasIndex("CookId"); + b.HasIndex("OrderId"); + b.ToTable("OrderCook"); }); - modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b => + modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountTablewares") + .HasColumnType("int"); + b.Property("OrderId") .HasColumnType("int"); - b.Property("DishId") + b.Property("TablewareId") .HasColumnType("int"); - b.Property("CountDishes") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); + b.HasIndex("OrderId"); - b.HasKey("OrderId", "DishId"); + b.HasIndex("TablewareId"); - b.HasIndex("DishId"); - - b.ToTable("OrderDish"); + b.ToTable("OrderTableware"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => @@ -302,19 +318,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b => { - b.Property("ProductId") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CookId") .HasColumnType("int"); - b.Property("Id") + b.Property("ProductId") .HasColumnType("int"); - b.HasKey("ProductId", "CookId"); + b.HasKey("Id"); b.HasIndex("CookId"); + b.HasIndex("ProductId"); + b.ToTable("ProductCook"); }); @@ -461,20 +482,12 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.Order", b => { - b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware") - .WithMany("Orders") - .HasForeignKey("TablewareId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("CanteenDatabaseImplement.Models.Visitor", "Visitor") .WithMany("Orders") .HasForeignKey("VisitorId") .OnDelete(DeleteBehavior.NoAction) .IsRequired(); - b.Navigation("Tableware"); - b.Navigation("Visitor"); }); @@ -497,23 +510,23 @@ namespace CanteenDatabaseImplement.Migrations b.Navigation("Order"); }); - modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b => + modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b => { - b.HasOne("CanteenDatabaseImplement.Models.Dish", "Dish") - .WithMany("Orders") - .HasForeignKey("DishId") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); - b.HasOne("CanteenDatabaseImplement.Models.Order", "Order") - .WithMany("Dishes") + .WithMany("Tablewares") .HasForeignKey("OrderId") .OnDelete(DeleteBehavior.NoAction) .IsRequired(); - b.Navigation("Dish"); + b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware") + .WithMany("Orders") + .HasForeignKey("TablewareId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); b.Navigation("Order"); + + b.Navigation("Tableware"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => @@ -566,8 +579,6 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b => { - b.Navigation("Orders"); - b.Navigation("Products"); }); @@ -591,9 +602,9 @@ namespace CanteenDatabaseImplement.Migrations { b.Navigation("Cooks"); - b.Navigation("Dishes"); - b.Navigation("Lunches"); + + b.Navigation("Tablewares"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => diff --git a/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs b/Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.cs similarity index 88% rename from Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs rename to Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.cs index 2242219..a441487 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/20230517172033_InitMigr.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/20230518211530_Init.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace CanteenDatabaseImplement.Migrations { /// - public partial class InitMigr : Migration + public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -130,6 +130,26 @@ namespace CanteenDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + VisitorId = table.Column(type: "int", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + Sum = table.Column(type: "float", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Visitors_VisitorId", + column: x => x.VisitorId, + principalTable: "Visitors", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Tablewares", columns: table => new @@ -154,14 +174,15 @@ namespace CanteenDatabaseImplement.Migrations name: "DishProduct", columns: table => new { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), DishId = table.Column(type: "int", nullable: false), ProductId = table.Column(type: "int", nullable: false), - Id = table.Column(type: "int", nullable: false), CountProducts = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_DishProduct", x => new { x.DishId, x.ProductId }); + table.PrimaryKey("PK_DishProduct", x => x.Id); table.ForeignKey( name: "FK_DishProduct_Dishes_DishId", column: x => x.DishId, @@ -178,13 +199,14 @@ namespace CanteenDatabaseImplement.Migrations name: "ProductCook", columns: table => new { - ProductId = table.Column(type: "int", nullable: false), - CookId = table.Column(type: "int", nullable: false), Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductId = table.Column(type: "int", nullable: false), + CookId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_ProductCook", x => new { x.ProductId, x.CookId }); + table.PrimaryKey("PK_ProductCook", x => x.Id); table.ForeignKey( name: "FK_ProductCook_Cooks_CookId", column: x => x.CookId, @@ -201,14 +223,15 @@ namespace CanteenDatabaseImplement.Migrations name: "LunchProduct", columns: table => new { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), LunchId = table.Column(type: "int", nullable: false), ProductId = table.Column(type: "int", nullable: false), - Id = table.Column(type: "int", nullable: false), CountProducts = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_LunchProduct", x => new { x.LunchId, x.ProductId }); + table.PrimaryKey("PK_LunchProduct", x => x.Id); table.ForeignKey( name: "FK_LunchProduct_Lunches_LunchId", column: x => x.LunchId, @@ -222,45 +245,18 @@ namespace CanteenDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Orders", + name: "LunchOrder", columns: table => new { Id = table.Column(type: "int", nullable: false) .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) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Tablewares_TablewareId", - column: x => x.TablewareId, - principalTable: "Tablewares", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_Visitors_VisitorId", - column: x => x.VisitorId, - principalTable: "Visitors", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "LunchOrder", - columns: table => new - { LunchId = table.Column(type: "int", nullable: false), OrderId = table.Column(type: "int", nullable: false), - Id = table.Column(type: "int", nullable: false), CountOrders = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_LunchOrder", x => new { x.LunchId, x.OrderId }); + table.PrimaryKey("PK_LunchOrder", x => x.Id); table.ForeignKey( name: "FK_LunchOrder_Lunches_LunchId", column: x => x.LunchId, @@ -277,13 +273,14 @@ namespace CanteenDatabaseImplement.Migrations name: "OrderCook", columns: table => new { - CookId = table.Column(type: "int", nullable: false), - OrderId = table.Column(type: "int", nullable: false), Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CookId = table.Column(type: "int", nullable: false), + OrderId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_OrderCook", x => new { x.OrderId, x.CookId }); + table.PrimaryKey("PK_OrderCook", x => x.Id); table.ForeignKey( name: "FK_OrderCook_Cooks_CookId", column: x => x.CookId, @@ -297,27 +294,28 @@ namespace CanteenDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "OrderDish", + name: "OrderTableware", columns: table => new { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), - DishId = table.Column(type: "int", nullable: false), - Id = table.Column(type: "int", nullable: false), - CountDishes = table.Column(type: "int", nullable: false) + TablewareId = table.Column(type: "int", nullable: false), + CountTablewares = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_OrderDish", x => new { x.OrderId, x.DishId }); + table.PrimaryKey("PK_OrderTableware", x => x.Id); table.ForeignKey( - name: "FK_OrderDish_Dishes_DishId", - column: x => x.DishId, - principalTable: "Dishes", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_OrderDish_Orders_OrderId", + name: "FK_OrderTableware_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "Id"); + table.ForeignKey( + name: "FK_OrderTableware_Tablewares_TablewareId", + column: x => x.TablewareId, + principalTable: "Tablewares", + principalColumn: "Id"); }); migrationBuilder.CreateIndex( @@ -330,6 +328,11 @@ namespace CanteenDatabaseImplement.Migrations table: "Dishes", column: "ManagerId"); + migrationBuilder.CreateIndex( + name: "IX_DishProduct_DishId", + table: "DishProduct", + column: "DishId"); + migrationBuilder.CreateIndex( name: "IX_DishProduct_ProductId", table: "DishProduct", @@ -340,11 +343,21 @@ namespace CanteenDatabaseImplement.Migrations table: "Lunches", column: "VisitorId"); + migrationBuilder.CreateIndex( + name: "IX_LunchOrder_LunchId", + table: "LunchOrder", + column: "LunchId"); + migrationBuilder.CreateIndex( name: "IX_LunchOrder_OrderId", table: "LunchOrder", column: "OrderId"); + migrationBuilder.CreateIndex( + name: "IX_LunchProduct_LunchId", + table: "LunchProduct", + column: "LunchId"); + migrationBuilder.CreateIndex( name: "IX_LunchProduct_ProductId", table: "LunchProduct", @@ -356,25 +369,35 @@ namespace CanteenDatabaseImplement.Migrations column: "CookId"); migrationBuilder.CreateIndex( - name: "IX_OrderDish_DishId", - table: "OrderDish", - column: "DishId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_TablewareId", - table: "Orders", - column: "TablewareId"); + name: "IX_OrderCook_OrderId", + table: "OrderCook", + column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_Orders_VisitorId", table: "Orders", column: "VisitorId"); + migrationBuilder.CreateIndex( + name: "IX_OrderTableware_OrderId", + table: "OrderTableware", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderTableware_TablewareId", + table: "OrderTableware", + column: "TablewareId"); + migrationBuilder.CreateIndex( name: "IX_ProductCook_CookId", table: "ProductCook", column: "CookId"); + migrationBuilder.CreateIndex( + name: "IX_ProductCook_ProductId", + table: "ProductCook", + column: "ProductId"); + migrationBuilder.CreateIndex( name: "IX_Products_ManagerId", table: "Products", @@ -402,20 +425,23 @@ namespace CanteenDatabaseImplement.Migrations name: "OrderCook"); migrationBuilder.DropTable( - name: "OrderDish"); + name: "OrderTableware"); migrationBuilder.DropTable( name: "ProductCook"); - migrationBuilder.DropTable( - name: "Lunches"); - migrationBuilder.DropTable( name: "Dishes"); + migrationBuilder.DropTable( + name: "Lunches"); + migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "Tablewares"); + migrationBuilder.DropTable( name: "Cooks"); @@ -423,13 +449,10 @@ namespace CanteenDatabaseImplement.Migrations name: "Products"); migrationBuilder.DropTable( - name: "Tablewares"); + name: "Visitors"); migrationBuilder.DropTable( name: "Managers"); - - migrationBuilder.DropTable( - name: "Visitors"); } } } diff --git a/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs b/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs index 6acfe8a..54bf5ff 100644 --- a/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs +++ b/Canteen/CanteenDatabaseImplement/Migrations/CanteenDatabaseModelSnapshot.cs @@ -75,19 +75,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountProducts") + .HasColumnType("int"); + b.Property("DishId") .HasColumnType("int"); b.Property("ProductId") .HasColumnType("int"); - b.Property("CountProducts") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("DishId", "ProductId"); + b.HasIndex("DishId"); b.HasIndex("ProductId"); @@ -130,19 +135,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountOrders") + .HasColumnType("int"); + b.Property("LunchId") .HasColumnType("int"); b.Property("OrderId") .HasColumnType("int"); - b.Property("CountOrders") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("LunchId", "OrderId"); + b.HasIndex("LunchId"); b.HasIndex("OrderId"); @@ -151,19 +161,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountProducts") + .HasColumnType("int"); + b.Property("LunchId") .HasColumnType("int"); b.Property("ProductId") .HasColumnType("int"); - b.Property("CountProducts") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); - - b.HasKey("LunchId", "ProductId"); + b.HasIndex("LunchId"); b.HasIndex("ProductId"); @@ -207,9 +222,6 @@ namespace CanteenDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CountTablewares") - .HasColumnType("int"); - b.Property("Description") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -217,17 +229,11 @@ namespace CanteenDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("float"); - b.Property("TablewareId") - .IsRequired() - .HasColumnType("int"); - b.Property("VisitorId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("TablewareId"); - b.HasIndex("VisitorId"); b.ToTable("Orders"); @@ -235,41 +241,51 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b => { - b.Property("OrderId") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CookId") .HasColumnType("int"); - b.Property("Id") + b.Property("OrderId") .HasColumnType("int"); - b.HasKey("OrderId", "CookId"); + b.HasKey("Id"); b.HasIndex("CookId"); + b.HasIndex("OrderId"); + b.ToTable("OrderCook"); }); - modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b => + modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b => { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountTablewares") + .HasColumnType("int"); + b.Property("OrderId") .HasColumnType("int"); - b.Property("DishId") + b.Property("TablewareId") .HasColumnType("int"); - b.Property("CountDishes") - .HasColumnType("int"); + b.HasKey("Id"); - b.Property("Id") - .HasColumnType("int"); + b.HasIndex("OrderId"); - b.HasKey("OrderId", "DishId"); + b.HasIndex("TablewareId"); - b.HasIndex("DishId"); - - b.ToTable("OrderDish"); + b.ToTable("OrderTableware"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => @@ -299,19 +315,24 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b => { - b.Property("ProductId") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CookId") .HasColumnType("int"); - b.Property("Id") + b.Property("ProductId") .HasColumnType("int"); - b.HasKey("ProductId", "CookId"); + b.HasKey("Id"); b.HasIndex("CookId"); + b.HasIndex("ProductId"); + b.ToTable("ProductCook"); }); @@ -458,20 +479,12 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.Order", b => { - b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware") - .WithMany("Orders") - .HasForeignKey("TablewareId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("CanteenDatabaseImplement.Models.Visitor", "Visitor") .WithMany("Orders") .HasForeignKey("VisitorId") .OnDelete(DeleteBehavior.NoAction) .IsRequired(); - b.Navigation("Tableware"); - b.Navigation("Visitor"); }); @@ -494,23 +507,23 @@ namespace CanteenDatabaseImplement.Migrations b.Navigation("Order"); }); - modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b => + modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b => { - b.HasOne("CanteenDatabaseImplement.Models.Dish", "Dish") - .WithMany("Orders") - .HasForeignKey("DishId") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); - b.HasOne("CanteenDatabaseImplement.Models.Order", "Order") - .WithMany("Dishes") + .WithMany("Tablewares") .HasForeignKey("OrderId") .OnDelete(DeleteBehavior.NoAction) .IsRequired(); - b.Navigation("Dish"); + b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware") + .WithMany("Orders") + .HasForeignKey("TablewareId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); b.Navigation("Order"); + + b.Navigation("Tableware"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => @@ -563,8 +576,6 @@ namespace CanteenDatabaseImplement.Migrations modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b => { - b.Navigation("Orders"); - b.Navigation("Products"); }); @@ -588,9 +599,9 @@ namespace CanteenDatabaseImplement.Migrations { b.Navigation("Cooks"); - b.Navigation("Dishes"); - b.Navigation("Lunches"); + + b.Navigation("Tablewares"); }); modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b => diff --git a/Canteen/CanteenDatabaseImplement/Models/Dish.cs b/Canteen/CanteenDatabaseImplement/Models/Dish.cs index 4eb74da..e83b7f6 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Dish.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Dish.cs @@ -31,7 +31,7 @@ namespace CanteenDatabaseImplement.Models if (_dishProducts == null) { _dishProducts = Products - .ToDictionary(recDP => recDP.DishId, recDP => (recDP.Product as IProductModel, recDP.CountProducts)); + .ToDictionary(recDP => recDP.ProductId, recDP => (recDP.Product as IProductModel, recDP.CountProducts)); } return _dishProducts; } @@ -39,8 +39,6 @@ namespace CanteenDatabaseImplement.Models [ForeignKey("DishId")] public virtual List Products { get; set; } = new(); - [ForeignKey("DishId")] - public virtual List Orders { get; set; } = new(); public virtual Manager Manager { get; set; } public static Dish Create(CanteenDatabase context, DishBindingModel model) @@ -63,7 +61,6 @@ namespace CanteenDatabaseImplement.Models { DishName = model.DishName; Price = model.Price; - ManagerId = model.ManagerId; } public DishViewModel GetViewModel => new() @@ -79,10 +76,10 @@ namespace CanteenDatabaseImplement.Models public void UpdateDishProduct(CanteenDatabase context, DishBindingModel model) { var dishProduct = context.DishProduct.Where(rec => rec.DishId == model.Id).ToList(); - if (dishProduct != null && (dishProduct.Count > 0)) + + if (dishProduct.Any()) { context.DishProduct.RemoveRange(dishProduct.Where(rec => !model.DishProducts.ContainsKey(rec.ProductId))); - context.SaveChanges(); foreach (var updateProduct in dishProduct) { updateProduct.CountProducts = model.DishProducts[updateProduct.ProductId].Item2; @@ -90,17 +87,23 @@ namespace CanteenDatabaseImplement.Models } context.SaveChanges(); } - var dish = context.Dishes.First(x => x.Id == Id); - foreach (var dp in model.DishProducts) + + var dish = context.Dishes.First(x => x.Id == model.Id); + + foreach (var dp in model.DishProducts.ToList()) { + var product = context.Products.First(x => x.Id == dp.Key); context.DishProduct.Add(new DishProduct { Dish = dish, - Product = context.Products.First(x => x.Id == dp.Key), + Product = product, CountProducts = dp.Value.Item2 }); - context.SaveChanges(); + model.DishProducts.Remove(dp.Key); } + + context.SaveChanges(); + _dishProducts = null; } } diff --git a/Canteen/CanteenDatabaseImplement/Models/Lunch.cs b/Canteen/CanteenDatabaseImplement/Models/Lunch.cs index 0870699..55d2ee0 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Lunch.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Lunch.cs @@ -41,6 +41,21 @@ namespace CanteenDatabaseImplement.Models } } + private Dictionary? _lunchOrders = null; + + [NotMapped] + public Dictionary LunchOrders + { + get + { + if (_lunchOrders == null) + { + _lunchOrders = Orders.ToDictionary(record => record.OrderId, record => (record.Order as IOrderModel, record.CountOrders)); + } + return _lunchOrders; + } + } + [ForeignKey("LunchId")] public virtual List Products { get; set; } = new(); [ForeignKey("LunchId")] @@ -62,6 +77,11 @@ namespace CanteenDatabaseImplement.Models { Product = context.Products.First(y => y.Id == x.Key), CountProducts = x.Value.Item2 + }).ToList(), + Orders = model.LunchOrders.Select(x => new LunchOrder + { + Order = context.Orders.First(y => y.Id == x.Key), + CountOrders = x.Value.Item2 }).ToList() }; } @@ -116,5 +136,35 @@ namespace CanteenDatabaseImplement.Models _lunchProducts = null; } + public void UpdateOrders(CanteenDatabase context, LunchBindingModel model) + { + var lunchOrders = context.LunchOrder.Where(record => record.LunchId == model.Id).ToList(); + if (lunchOrders != null && lunchOrders.Count > 0) + { + context.LunchOrder.RemoveRange(lunchOrders.Where(record => !model.LunchOrders.ContainsKey(record.OrderId))); + context.SaveChanges(); + + foreach (var updateOrder in lunchOrders) + { + updateOrder.CountOrders = model.LunchOrders[updateOrder.OrderId].Item2; + model.LunchOrders.Remove(updateOrder.OrderId); + } + context.SaveChanges(); + } + + var lunch = context.Lunches.First(x => x.Id == Id); + foreach (var pp in model.LunchOrders) + { + context.LunchOrder.Add(new LunchOrder + { + Lunch = lunch, + Order = context.Orders.First(x => x.Id == pp.Key), + CountOrders = pp.Value.Item2 + }); + context.SaveChanges(); + } + + _lunchOrders = null; + } } } diff --git a/Canteen/CanteenDatabaseImplement/Models/Order.cs b/Canteen/CanteenDatabaseImplement/Models/Order.cs index 5553409..c9c2309 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Order.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Order.cs @@ -17,35 +17,48 @@ namespace CanteenDatabaseImplement.Models public int Id { get; private set; } [Required] public int VisitorId { get; private set; } - public int? TablewareId { get; set; } - public int? CountTablewares { get; set; } [Required] public string Description { get; private set; } = string.Empty; public double? Sum { get; private set; } - private Dictionary? _orderDishes = null; + private Dictionary? _orderCooks = null; [NotMapped] - public Dictionary OrderDishes + public Dictionary OrderCooks { get { - if (_orderDishes == null) + if (_orderCooks == null) { - _orderDishes = Dishes - .ToDictionary(recOD => recOD.DishId, recOD => (recOD.Dish as IDishModel, recOD.CountDishes)); + _orderCooks = Cooks + .ToDictionary(recOD => recOD.CookId, recOD => recOD.Cook as ICookModel); } - return _orderDishes; + return _orderCooks; + } + } + + private Dictionary? _orderTablewares = null; + + [NotMapped] + public Dictionary OrderTablewares + { + get + { + if (_orderTablewares == null) + { + _orderTablewares = Tablewares + .ToDictionary(recOD => recOD.TablewareId, recOD => (recOD.Tableware as ITablewareModel, recOD.CountTablewares)); + } + return _orderTablewares; } } - [ForeignKey("OrderId")] - public virtual List Dishes { get; set; } = new(); [ForeignKey("OrderId")] public virtual List Lunches { get; set; } = new(); [ForeignKey("OrderId")] public virtual List Cooks { get; set; } = new(); - public virtual Tableware Tableware { get; set; } + [ForeignKey("OrderId")] + public virtual List Tablewares { get; set; } = new(); public virtual Visitor Visitor { get; set; } public static Order Create(OrderBindingModel model) @@ -69,7 +82,6 @@ namespace CanteenDatabaseImplement.Models { return; } - VisitorId = model.VisitorId; Description = model.Description; Sum = model.Sum; } @@ -80,35 +92,62 @@ namespace CanteenDatabaseImplement.Models VisitorId = VisitorId, Description = Description, Sum = Sum, - OrderDishes = OrderDishes + OrderCooks = OrderCooks, + OrderTablewares = OrderTablewares }; - public void UpdateOrderDish(CanteenDatabase context, OrderBindingModel model) + public void UpdateOrderCook(CanteenDatabase context, OrderBindingModel model) { - var orderDish = context.OrderDish.Where(rec => rec.DishId == model.Id).ToList(); - if (orderDish != null && (orderDish.Count > 0)) + var orderCook = context.OrderCook.Where(rec => rec.CookId == model.Id).ToList(); + if (orderCook != null && (orderCook.Count > 0)) { - context.OrderDish.RemoveRange(orderDish.Where(rec => !model.OrderDishes.ContainsKey(rec.DishId))); + context.OrderCook.RemoveRange(orderCook.Where(rec => !model.OrderCooks.ContainsKey(rec.CookId))); context.SaveChanges(); - foreach (var updateDish in orderDish) + foreach (var updateCook in orderCook) { - updateDish.CountDishes = model.OrderDishes[updateDish.DishId].Item2; - model.OrderDishes.Remove(updateDish.DishId); + model.OrderCooks.Remove(updateCook.CookId); } context.SaveChanges(); } var order = context.Orders.First(x => x.Id == Id); - foreach (var dp in model.OrderDishes) + foreach (var dp in model.OrderCooks) { - context.OrderDish.Add(new OrderDish + context.OrderCook.Add(new OrderCook { Order = order, - Dish = context.Dishes.First(x => x.Id == dp.Key), - CountDishes = dp.Value.Item2 + Cook = context.Cooks.First(x => x.Id == dp.Key) }); context.SaveChanges(); } - _orderDishes = null; + _orderCooks = null; + } + public void UpdateOrderTablewares(CanteenDatabase context, OrderBindingModel model) + { + var orderTableware = context.OrderTableware.Where(rec => rec.TablewareId == model.Id).ToList(); + if (orderTableware != null && (orderTableware.Count > 0)) + { + context.OrderTableware.RemoveRange(orderTableware.Where(rec => !model.OrderTablewares.ContainsKey(rec.TablewareId))); + context.SaveChanges(); + foreach (var updateTableware in orderTableware) + { + updateTableware.CountTablewares = model.OrderTablewares[updateTableware.TablewareId].Item2; + model.OrderTablewares.Remove(updateTableware.TablewareId); + } + context.SaveChanges(); + } + var order = context.Orders.First(x => x.Id == Id); + foreach (var dp in model.OrderTablewares) + { + + context.OrderTableware.Add(new OrderTableware + { + Order = order, + Tableware = context.Tablewares.First(x => x.Id == dp.Key), + CountTablewares = dp.Value.Item2 + }); + context.SaveChanges(); + } + _orderTablewares = null; } } } diff --git a/Canteen/CanteenDatabaseImplement/Models/OrderDish.cs b/Canteen/CanteenDatabaseImplement/Models/OrderDish.cs deleted file mode 100644 index 3c078da..0000000 --- a/Canteen/CanteenDatabaseImplement/Models/OrderDish.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace CanteenDatabaseImplement.Models -{ - public class OrderDish - { - public int Id { get; set; } - [Required] - public int OrderId { get; set; } - - [Required] - public int DishId { get; set; } - - [Required] - public int CountDishes { get; set; } - - public virtual Order Order { get; set; } = new(); - - public virtual Dish Dish { get; set; } = new(); - - } -} \ No newline at end of file diff --git a/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs b/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs new file mode 100644 index 0000000..4272fdb --- /dev/null +++ b/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenDatabaseImplement.Models +{ + public class OrderTableware + { + public int Id { get; set; } + [Required] + public int OrderId { get; set; } + [Required] + public int TablewareId { get; set; } + [Required] + public int CountTablewares { get; set; } + public virtual Order Order { get; set; } = new(); + public virtual Tableware Tableware { get; set; } = new(); + } +} diff --git a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs index aa3b507..3786009 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs @@ -20,7 +20,7 @@ namespace CanteenDatabaseImplement.Models [Required] public string TablewareName { get; private set; } = string.Empty; [ForeignKey("TablewareId")] - public virtual List Orders { get; set; } = new(); + public virtual List Orders { get; set; } = new(); public virtual Visitor Visitor { get; set; } public static Tableware? Create(TablewareBindingModel model) { diff --git a/Canteen/CanteenManagerApp/Controllers/HomeController.cs b/Canteen/CanteenManagerApp/Controllers/HomeController.cs index 3bab88b..dffb78b 100644 --- a/Canteen/CanteenManagerApp/Controllers/HomeController.cs +++ b/Canteen/CanteenManagerApp/Controllers/HomeController.cs @@ -397,10 +397,12 @@ namespace CanteenManagerApp.Controllers { throw new Exception("Количество продукта должно быть больше 0"); } + ProductViewModel product = APIClient.GetRequest($"api/main/getproduct?id={selectedProduct}"); + APIClient.PostRequest("api/main/dishaddproducts", Tuple.Create ( - new DishSearchModel { Id = selectedDish }, - new ProductViewModel { Id = selectedProduct }, + new DishBindingModel { Id = selectedDish }, + new ProductViewModel { Id = selectedProduct, Price = product.Price }, count )); diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index 3593d99..af268f7 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -31,11 +31,11 @@ namespace CanteenRestApi.Controllers } [HttpGet] - public List? GetTablewareList() + public List? GetTablewareList(int visitorId) { try { - return _tableware.ReadList(null); + return _tableware.ReadList(new TablewareSearchModel { VisitorId = visitorId }); } catch (Exception ex) { @@ -43,7 +43,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void CreateTableware(TablewareBindingModel model) { @@ -57,7 +56,32 @@ namespace CanteenRestApi.Controllers throw; } } - + [HttpPost] + public void DeleteTableware(TablewareBindingModel model) + { + try + { + _tableware.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } + [HttpPost] + public void UpdateTableware(TablewareBindingModel model) + { + try + { + _tableware.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } [HttpGet] public List? GetCookList(int managerId) { @@ -71,7 +95,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void CookCreate(CookBindingModel model) { @@ -85,7 +108,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void CookDelete(CookBindingModel model) { @@ -99,7 +121,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void CookUpdate(CookBindingModel model) { @@ -113,7 +134,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpGet] public List? GetDishList(int managerId) { @@ -127,7 +147,19 @@ namespace CanteenRestApi.Controllers throw; } } - + [HttpGet] + public DishViewModel? GetDish(int Id) + { + try + { + return _dish.ReadElement(new DishSearchModel { Id = Id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } [HttpPost] public void DishCreate(DishBindingModel model) { @@ -154,7 +186,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void DishUpdate(DishBindingModel model) { @@ -169,11 +200,11 @@ namespace CanteenRestApi.Controllers } } [HttpPost] - public void DishAddProducts(Tuple model) + public void DishAddProducts(Tuple model) { try { - _dish.AddCooksToProduct(model.Item1, model.Item2, model.Item3); + _dish.AddProductsToDish(model.Item1, model.Item2, model.Item3); } catch (Exception ex) { @@ -181,7 +212,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpGet] public List? GetProductList(int managerId) { @@ -195,7 +225,19 @@ namespace CanteenRestApi.Controllers throw; } } - + [HttpGet] + public ProductViewModel? GetProduct(int Id) + { + try + { + return _product.ReadElement(new ProductSearchModel { Id = Id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during loading list of bouquets"); + throw; + } + } [HttpPost] public void ProductCreate(ProductBindingModel model) { @@ -222,7 +264,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void ProductUpdate(ProductBindingModel model) { @@ -236,7 +277,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpPost] public void ProductAddCooks(Tuple model) { @@ -250,7 +290,6 @@ namespace CanteenRestApi.Controllers throw; } } - [HttpGet] public GraphicViewModel[] GetGraphic() { diff --git a/Canteen/CanteenRestApi/Controllers/VisitorController.cs b/Canteen/CanteenRestApi/Controllers/VisitorController.cs new file mode 100644 index 0000000..5347326 --- /dev/null +++ b/Canteen/CanteenRestApi/Controllers/VisitorController.cs @@ -0,0 +1,68 @@ +using CanteenContracts.BindingModels; +using CanteenContracts.BusinessLogicsContracts; +using CanteenContracts.SearchModel; +using CanteenContracts.View; +using Microsoft.AspNetCore.Mvc; + +namespace CanteenRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class VisitorController : Controller + { + private readonly ILogger _logger; + private readonly IVisitorLogic _logic; + + public VisitorController(IVisitorLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public VisitorViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new VisitorSearchModel + { + Login = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during logging in"); + throw; + } + } + + [HttpPost] + public void Register(VisitorBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during registration"); + throw; + } + } + + [HttpPost] + public void UpdateData(VisitorBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during updating"); + throw; + } + } + } +} diff --git a/Canteen/CanteenRestApi/Program.cs b/Canteen/CanteenRestApi/Program.cs index 868c60d..5d96850 100644 --- a/Canteen/CanteenRestApi/Program.cs +++ b/Canteen/CanteenRestApi/Program.cs @@ -11,12 +11,14 @@ builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Canteen/CanteenVisitorApp/APIClient.cs b/Canteen/CanteenVisitorApp/APIClient.cs index 4ba006b..3fb1b19 100644 --- a/Canteen/CanteenVisitorApp/APIClient.cs +++ b/Canteen/CanteenVisitorApp/APIClient.cs @@ -8,6 +8,7 @@ namespace CanteenVisitorApp public static class APIClient { private static readonly HttpClient _client = new(); + public static VisitorViewModel? Visitor { get; set; } = null; public static void Connect(IConfiguration configuration) { _client.BaseAddress = new Uri(configuration["IPAddress"]); diff --git a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj index e6050c2..8abed74 100644 --- a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj +++ b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj @@ -20,7 +20,6 @@ - diff --git a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs index 2faae9b..62cbf13 100644 --- a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs +++ b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using CanteenContracts.View; using CanteenVisitorApp.Models; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; using System.Diagnostics; namespace CanteenVisitorApp.Controllers @@ -15,70 +16,254 @@ namespace CanteenVisitorApp.Controllers _logger = logger; } + [HttpGet] public IActionResult Index() { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + return View(); } + [HttpGet] + public IActionResult Enter() + { + return View(); + } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + + APIClient.Visitor = APIClient.GetRequest($"api/visitor/login?login={login}&password={password}"); + if (APIClient.Visitor == null) + { + throw new Exception("Неверный логин/пароль"); + } + + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Register() + { + return View(); + } + + [HttpPost] + public void Register(string login, string password, string fio, string phoneNumber) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + + APIClient.PostRequest("api/visitor/register", new VisitorBindingModel + { + FIO = fio, + Login = login, + Password = password, + PhoneNumber = phoneNumber + }); + + Response.Redirect("Enter"); + } + public IActionResult Privacy() { return View(); } - - public IActionResult Lunches() - { - - ViewBag.Cooks = APIClient.GetRequest>("api/main/getcooklist"); - ViewBag.Lunches = new List(); - return View(); - } - [HttpGet] public IActionResult Tablewares() { - ViewBag.Tablewares = APIClient.GetRequest>("api/main/gettablewarelist"); + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Tablewares = APIClient.GetRequest>($"api/main/gettablewarelist?visitorId={APIClient.Visitor.Id}"); return View(); } + [HttpGet] + public IActionResult CreateTableware() + { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpPost] + public void CreateTableware(string tablewarename) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + + + APIClient.PostRequest("api/main/createtableware", new TablewareBindingModel + { + VisitorId = APIClient.Visitor.Id, + TablewareName = tablewarename + }); + + Response.Redirect("Tablewares"); + } + + [HttpGet] + public IActionResult DeleteTableware() + { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Tablewares = APIClient.GetRequest>($"api/main/gettablewarelist?visitorId={APIClient.Visitor.Id}"); + return View(); + } + [HttpPost] + public void DeleteTableware(int id) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + if (id <= 0) + { + throw new Exception("Выберите пhb,jh"); + } + APIClient.PostRequest("api/main/DeleteTableware", new TablewareBindingModel + { + Id = id + }); + + Response.Redirect("Tablewares"); + } + [HttpGet] + public IActionResult UpdateTableware() + { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Tablewares = APIClient.GetRequest>($"api/main/gettablewarelist?visitorId={APIClient.Visitor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateTableware(int id, string tablewarename) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + APIClient.PostRequest("api/main/UpdateTableware", new TablewareBindingModel + { + Id = id, + VisitorId = APIClient.Visitor.Id, + TablewareName = tablewarename + }); + Response.Redirect("Tablewares"); + } [HttpGet] public IActionResult Orders() { - ViewBag.Orders = new List(); + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Orders = APIClient.GetRequest>($"api/main/getorderlist?visitorId={APIClient.Visitor.Id}"); return View(); } [HttpGet] public IActionResult CreateOrder() { - ViewBag.Dishes = new List(); - return View(); - } - - [HttpGet] - public IActionResult CreateLunch() - { - ViewBag.Products = new List(); + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } return View(); } [HttpPost] - public void CreateTableware(string TablewareName, int TablewareCount) + public void CreateOrder(string ordername) { - APIClient.PostRequest("api/main/CreateTableware", new TablewareBindingModel + if (APIClient.Visitor == null) { - VisitorId = 1, - TablewareName = TablewareName + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + + + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + VisitorId = APIClient.Visitor.Id, + OrderName = ordername }); - Response.Redirect("Tablewares"); + + Response.Redirect("Orders"); } [HttpGet] - public IActionResult CreateTableware() + public IActionResult DeleteOrder() { - ViewBag.Orders = new List(); + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Orders = APIClient.GetRequest>($"api/main/getorderlist?visitorId={APIClient.Visitor.Id}"); + return View(); + } + [HttpPost] + public void DeleteOrder(int id) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + if (id <= 0) + { + throw new Exception("Выберите пhb,jh"); + } + APIClient.PostRequest("api/main/DeleteOrder", new OrderBindingModel + { + Id = id + }); + + Response.Redirect("Orders"); + } + [HttpGet] + public IActionResult UpdateOrder() + { + if (APIClient.Visitor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Orders = APIClient.GetRequest>($"api/main/getorderlist?visitorId={APIClient.Visitor.Id}"); return View(); } + [HttpPost] + public void UpdateOrder(int id, string ordername) + { + if (APIClient.Visitor == null) + { + throw new Exception("Доступ возможен только авторизованным пользователям"); + } + APIClient.PostRequest("api/main/UpdateOrder", new OrderBindingModel + { + Id = id, + VisitorId = APIClient.Visitor.Id, + OrderName = ordername + }); + Response.Redirect("Orders"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Canteen/CanteenVisitorApp/Views/Home/CreateLunch.cshtml b/Canteen/CanteenVisitorApp/Views/Home/CreateLunch.cshtml index 2deb7d1..c3bb28f 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/CreateLunch.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/CreateLunch.cshtml @@ -1,6 +1,6 @@ - +@* @{ - ViewData["Title"] = "Lunch"; + ViewData["Title"] = "CreateLunch"; }

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

@@ -14,20 +14,13 @@
Название обеда:
- - -
-
-
-
Сумма:
-
- +
Продукты:
- +
@@ -36,4 +29,55 @@
- \ No newline at end of file +*@ +@{ + ViewData["Title"] = "CreateLunch"; +} +
+

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

+
+ +
+
+
Название обеда:
+
+ +
+
+
+
Продукты:
+
+ + + +
    +
    +
    +
    +
    +
    + +
    +
    +
    + + \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/CreateOrder.cshtml b/Canteen/CanteenVisitorApp/Views/Home/CreateOrder.cshtml index a372f8f..353ef5e 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/CreateOrder.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/CreateOrder.cshtml @@ -11,30 +11,12 @@ }
    -
    -
    Название заказа:
    -
    - -
    -
    Описание заказа:
    -
    -
    Сумма:
    -
    - -
    -
    -
    -
    Блюда:
    -
    - -
    -
    diff --git a/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml b/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml index f0feca5..eb66b9e 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml @@ -17,18 +17,6 @@
    -
    -
    Количество:
    -
    - -
    -
    -
    -
    Заказ:
    -
    - -
    -
    diff --git a/Canteen/CanteenVisitorApp/Views/Home/DeleteOrder.cshtml b/Canteen/CanteenVisitorApp/Views/Home/DeleteOrder.cshtml new file mode 100644 index 0000000..bbfb9af --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/DeleteOrder.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "DeleteOrder"; +} +
    +

    Удаление заказа

    +
    + + +
    +
    Выберите заказ
    +
    + +
    +
    +
    +
    +
    + +
    +
    + \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/DeleteTableware.cshtml b/Canteen/CanteenVisitorApp/Views/Home/DeleteTableware.cshtml new file mode 100644 index 0000000..7962f6a --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/DeleteTableware.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "DeleteTableware"; +} +
    +

    Удаление прибора

    +
    + +
    +
    +
    Выберите прибор
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/Enter.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..bda60a1 --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/Enter.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Enter"; +} +
    +

    Вход в приложение

    +
    +
    +
    +
    Логин:
    +
    +
    +
    +
    Пароль:
    +
    +
    +
    +
    +
    +
    +
    diff --git a/Canteen/CanteenVisitorApp/Views/Home/LunchAddProducts.cshtml b/Canteen/CanteenVisitorApp/Views/Home/LunchAddProducts.cshtml new file mode 100644 index 0000000..936b923 --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/LunchAddProducts.cshtml @@ -0,0 +1,48 @@ +@using CanteenContracts.View; +@{ + ViewData["Title"] = "LunchAddProducts"; +} +
    +

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

    +
    + +
    +
    +
    Обед:
    +
    + +
    +
    +
    +
    Продукт:
    +
    + +
    +
    +
    +
    Количество:
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/Orders.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Orders.cshtml index d08cb25..1e7a82a 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/Orders.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/Orders.cshtml @@ -5,27 +5,28 @@

    Список обедов

    - - - + + - + + - @foreach (var cook in ViewBag.Orders) + @foreach (var order in ViewBag.Orders) { - - - - - - + + + + + + + }
    НомерНомер посетителя Описание обеда СуммаНазвание прибораКоличество прибора
    @cook.Id@cook.VisitorId@cook.Description@cook.Sum
    @order.Id@order.Description@order.Sum@order.TablewareName@order.CountTablewares
    diff --git a/Canteen/CanteenVisitorApp/Views/Home/Register.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..7217092 --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/Register.cshtml @@ -0,0 +1,29 @@ +@{ + ViewData["Title"] = "Register"; +} +
    +

    Регистрация

    +
    +
    +
    +
    Логин:
    +
    +
    +
    +
    Пароль:
    +
    +
    +
    +
    ФИО:
    +
    +
    +
    Номер телефона:
    +
    +
    +
    +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml index 7aba725..c783553 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml @@ -5,13 +5,12 @@

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

    - - + + - @@ -20,7 +19,6 @@ { - } diff --git a/Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml b/Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml new file mode 100644 index 0000000..6f811ca --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml @@ -0,0 +1,23 @@ +@using Newtonsoft.Json; +@{ + ViewData["Title"] = "UpdateOrder"; +} +
    +

    Данные заказа

    +
    + +
    +
    Заказ:
    +
    +
    +
    +
    Прибор:
    +
    + +
    +
    +
    +
    +
    +
    + \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Home/UpdateTableware.cshtml b/Canteen/CanteenVisitorApp/Views/Home/UpdateTableware.cshtml new file mode 100644 index 0000000..7be07a8 --- /dev/null +++ b/Canteen/CanteenVisitorApp/Views/Home/UpdateTableware.cshtml @@ -0,0 +1,42 @@ +@using Newtonsoft.Json; +@{ + ViewData["Title"] = "UpdateTableware"; +} +
    +

    Данные прибора

    +
    + +
    +
    Прибор:
    +
    +
    +
    +
    Название прибора:
    +
    + +
    +
    +
    +
    +
    +
    +@* +*@ \ No newline at end of file diff --git a/Canteen/CanteenVisitorApp/Views/Shared/_Layout.cshtml b/Canteen/CanteenVisitorApp/Views/Shared/_Layout.cshtml index 3452b45..7a80813 100644 --- a/Canteen/CanteenVisitorApp/Views/Shared/_Layout.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Shared/_Layout.cshtml @@ -28,6 +28,12 @@ + +
    НомерНомер посетителя Название прибора
    @cook.Id@cook.VisitorId @cook.TablewareName