partly done crud
This commit is contained in:
parent
f411d90acb
commit
a15bdf9d95
@ -3,6 +3,7 @@ using CanteenContracts.BusinessLogicsContracts;
|
|||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.StoragesContracts;
|
using CanteenContracts.StoragesContracts;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -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);
|
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()
|
if (_dishStorage.Update(new()
|
||||||
{
|
{
|
||||||
Id = dish.Id,
|
Id = dish.Id,
|
||||||
DishName = dish.DishName,
|
DishName = dish.DishName,
|
||||||
ManagerId = dish.ManagerId,
|
ManagerId = dish.ManagerId,
|
||||||
DishProducts = dish.DishProducts
|
DishProducts = dish.DishProducts,
|
||||||
|
Price = allSum
|
||||||
|
|
||||||
}) == null)
|
}) == null)
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using CanteenContracts.SearchModels;
|
|||||||
using CanteenContracts.StoragesContracts;
|
using CanteenContracts.StoragesContracts;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
using CanteenDataModels.Enums;
|
using CanteenDataModels.Enums;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -204,5 +205,15 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Такая связь уже есть");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using CanteenContracts.SearchModel;
|
|||||||
using CanteenContracts.SearchModels;
|
using CanteenContracts.SearchModels;
|
||||||
using CanteenContracts.StoragesContracts;
|
using CanteenContracts.StoragesContracts;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -23,30 +24,15 @@ namespace CanteenBusinessLogic.BusinessLogics
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_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);
|
throw new NotImplementedException();
|
||||||
_logger.LogInformation("AddTableware. OrderId: {OrderId}. TablewareId: {TablewareId}", model.OrderId, model.TablewareId);
|
|
||||||
if (!_orderStorage.AddTableware(model))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("AddTableware operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(OrderBindingModel model)
|
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);
|
_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});
|
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.OrderId});
|
||||||
if (element != null && element.Id == model.OrderId && element.TablewareId == model.TablewareId)
|
//if (element != null && element.Id == model.OrderId && element.TablewareId == model.TablewareId)
|
||||||
{
|
//{
|
||||||
throw new InvalidOperationException("Такая связь уже есть");
|
// throw new InvalidOperationException("Такая связь уже есть");
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ namespace CanteenContracts.BindingModels
|
|||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
public Dictionary<int, (IProductModel, int)> LunchProducts { get; set; } = new Dictionary<int, (IProductModel, int)>();
|
public Dictionary<int, (IProductModel, int)> LunchProducts { get; set; } = new Dictionary<int, (IProductModel, int)>();
|
||||||
|
public Dictionary<int, (IOrderModel, int)> LunchOrders { get; set; } = new Dictionary<int, (IOrderModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ namespace CanteenContracts.BindingModels
|
|||||||
public double? Sum { get; set; }
|
public double? Sum { get; set; }
|
||||||
public int? TablewareId { get; set; }
|
public int? TablewareId { get; set; }
|
||||||
public int? CountTablewares { get; set; }
|
public int? CountTablewares { get; set; }
|
||||||
public Dictionary<int, (IDishModel, int)> OrderDishes { get; set; } = new ();
|
public Dictionary<int, ICookModel> OrderCooks { get; set; } = new ();
|
||||||
|
public Dictionary<int, (ITablewareModel, int)> OrderTablewares { get; set; } = new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using CanteenContracts.BindingModels;
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -16,6 +17,6 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
bool Create(DishBindingModel model);
|
bool Create(DishBindingModel model);
|
||||||
bool Update(DishBindingModel model);
|
bool Update(DishBindingModel model);
|
||||||
bool Delete(DishBindingModel model);
|
bool Delete(DishBindingModel model);
|
||||||
bool AddCooksToProduct(DishSearchModel model, ProductViewModel product, int count);
|
bool AddProductsToDish(DishBindingModel model, IProductModel product, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using CanteenContracts.BindingModels;
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -17,6 +18,7 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
bool Update(LunchBindingModel model);
|
bool Update(LunchBindingModel model);
|
||||||
bool Delete(LunchBindingModel model);
|
bool Delete(LunchBindingModel model);
|
||||||
bool Finish(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using CanteenContracts.BindingModels;
|
using CanteenContracts.BindingModels;
|
||||||
using CanteenContracts.SearchModel;
|
using CanteenContracts.SearchModel;
|
||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
|
using CanteenDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -16,7 +17,7 @@ namespace CanteenContracts.BusinessLogicsContracts
|
|||||||
bool Create(OrderBindingModel model);
|
bool Create(OrderBindingModel model);
|
||||||
bool Delete(OrderBindingModel model);
|
bool Delete(OrderBindingModel model);
|
||||||
bool Update(OrderBindingModel model);
|
bool Update(OrderBindingModel model);
|
||||||
bool AddCook(OrderCookBindingModel model);
|
bool AddTablewareToOrder(OrderTablewareBindingModel model, ITablewareModel tableware, int count);
|
||||||
bool AddTableware(OrderTablewareBindingModel model);
|
bool AddCooksToOrder(OrderSearchModel model, ICookModel cook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,5 @@ namespace CanteenContracts.StoragesContracts
|
|||||||
OrderViewModel? Insert(OrderBindingModel model);
|
OrderViewModel? Insert(OrderBindingModel model);
|
||||||
OrderViewModel? Update(OrderBindingModel model);
|
OrderViewModel? Update(OrderBindingModel model);
|
||||||
OrderViewModel? Delete(OrderBindingModel model);
|
OrderViewModel? Delete(OrderBindingModel model);
|
||||||
bool AddCook(OrderCookBindingModel model);
|
|
||||||
bool AddTableware(OrderTablewareBindingModel model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,10 @@ namespace CanteenContracts.View
|
|||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
[DisplayName("Сумма")]
|
[DisplayName("Сумма")]
|
||||||
public double? Sum { get; set; }
|
public double? Sum { get; set; }
|
||||||
public Dictionary<int, (IDishModel, int)> OrderDishes { get; set; } = new Dictionary<int, (IDishModel, int)>();
|
public Dictionary<int, ICookModel> OrderCooks { get; set; } = new Dictionary<int, ICookModel>();
|
||||||
|
public Dictionary<int, (ITablewareModel, int)> OrderTablewares { get; set; } = new Dictionary<int, (ITablewareModel, int)>();
|
||||||
[DisplayName("ID заказа")]
|
[DisplayName("ID заказа")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int? TablewareId { get; set; }
|
|
||||||
public int? CountTablewares { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,9 @@ namespace CanteenDataModels.Models
|
|||||||
public interface IOrderModel : IId
|
public interface IOrderModel : IId
|
||||||
{
|
{
|
||||||
int VisitorId { get; }
|
int VisitorId { get; }
|
||||||
int? TablewareId { get; }
|
|
||||||
int? CountTablewares { get; }
|
|
||||||
string Description { get; }
|
string Description { get; }
|
||||||
double? Sum { get; }
|
double? Sum { get; }
|
||||||
Dictionary<int, (IDishModel, int)> OrderDishes { get; }
|
Dictionary<int, ICookModel> OrderCooks { get; }
|
||||||
|
Dictionary<int, (ITablewareModel, int)> OrderTablewares { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,12 @@ namespace CanteenDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<DishProduct>()
|
|
||||||
.HasKey(dp => new { dp.DishId, dp.ProductId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<DishProduct>()
|
modelBuilder.Entity<DishProduct>()
|
||||||
.HasOne(dp => dp.Dish)
|
.HasOne(dp => dp.Dish)
|
||||||
.WithMany(d => d.Products)
|
.WithMany(d => d.Products)
|
||||||
@ -32,8 +29,6 @@ namespace CanteenDatabaseImplement
|
|||||||
.HasForeignKey(dp => dp.ProductId)
|
.HasForeignKey(dp => dp.ProductId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
//=====================================
|
//=====================================
|
||||||
modelBuilder.Entity<LunchOrder>()
|
|
||||||
.HasKey(dp => new { dp.LunchId, dp.OrderId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<LunchOrder>()
|
modelBuilder.Entity<LunchOrder>()
|
||||||
.HasOne(dp => dp.Lunch)
|
.HasOne(dp => dp.Lunch)
|
||||||
@ -47,8 +42,6 @@ namespace CanteenDatabaseImplement
|
|||||||
.HasForeignKey(dp => dp.OrderId)
|
.HasForeignKey(dp => dp.OrderId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
//=====================================
|
//=====================================
|
||||||
modelBuilder.Entity<LunchProduct>()
|
|
||||||
.HasKey(dp => new { dp.LunchId, dp.ProductId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<LunchProduct>()
|
modelBuilder.Entity<LunchProduct>()
|
||||||
.HasOne(dp => dp.Lunch)
|
.HasOne(dp => dp.Lunch)
|
||||||
@ -62,8 +55,6 @@ namespace CanteenDatabaseImplement
|
|||||||
.HasForeignKey(dp => dp.ProductId)
|
.HasForeignKey(dp => dp.ProductId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
//=====================================
|
//=====================================
|
||||||
modelBuilder.Entity<OrderCook>()
|
|
||||||
.HasKey(dp => new { dp.OrderId, dp.CookId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<OrderCook>()
|
modelBuilder.Entity<OrderCook>()
|
||||||
.HasOne(dp => dp.Order)
|
.HasOne(dp => dp.Order)
|
||||||
@ -77,23 +68,19 @@ namespace CanteenDatabaseImplement
|
|||||||
.HasForeignKey(dp => dp.CookId)
|
.HasForeignKey(dp => dp.CookId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
//=====================================
|
//=====================================
|
||||||
modelBuilder.Entity<OrderDish>()
|
|
||||||
.HasKey(dp => new { dp.OrderId, dp.DishId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<OrderDish>()
|
modelBuilder.Entity<OrderTableware>()
|
||||||
.HasOne(dp => dp.Order)
|
.HasOne(dp => dp.Order)
|
||||||
.WithMany(d => d.Dishes)
|
.WithMany(d => d.Tablewares)
|
||||||
.HasForeignKey(dp => dp.OrderId)
|
.HasForeignKey(dp => dp.OrderId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
|
|
||||||
modelBuilder.Entity<OrderDish>()
|
modelBuilder.Entity<OrderTableware>()
|
||||||
.HasOne(dp => dp.Dish)
|
.HasOne(dp => dp.Tableware)
|
||||||
.WithMany(p => p.Orders)
|
.WithMany(p => p.Orders)
|
||||||
.HasForeignKey(dp => dp.DishId)
|
.HasForeignKey(dp => dp.TablewareId)
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
//=====================================
|
//=====================================
|
||||||
modelBuilder.Entity<ProductCook>()
|
|
||||||
.HasKey(dp => new { dp.ProductId, dp.CookId });
|
|
||||||
|
|
||||||
modelBuilder.Entity<ProductCook>()
|
modelBuilder.Entity<ProductCook>()
|
||||||
.HasOne(dp => dp.Product)
|
.HasOne(dp => dp.Product)
|
||||||
@ -125,7 +112,7 @@ namespace CanteenDatabaseImplement
|
|||||||
public virtual DbSet<Product> Products { set; get; }
|
public virtual DbSet<Product> Products { set; get; }
|
||||||
public virtual DbSet<ProductCook> ProductCook { set; get; }
|
public virtual DbSet<ProductCook> ProductCook { set; get; }
|
||||||
public virtual DbSet<LunchProduct> LunchProduct { set; get; }
|
public virtual DbSet<LunchProduct> LunchProduct { set; get; }
|
||||||
public virtual DbSet<OrderDish> OrderDish { set; get; }
|
public virtual DbSet<OrderTableware> OrderTableware { set; get; }
|
||||||
public virtual DbSet<DishProduct> DishProduct { set; get; }
|
public virtual DbSet<DishProduct> DishProduct { set; get; }
|
||||||
public virtual DbSet<Tableware> Tablewares { set; get; }
|
public virtual DbSet<Tableware> Tablewares { set; get; }
|
||||||
public virtual DbSet<Visitor> Visitors { set; get; }
|
public virtual DbSet<Visitor> Visitors { set; get; }
|
||||||
|
@ -99,8 +99,7 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
dish.Update(model);
|
dish.Update(model);
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
if (model.DishProducts != null)
|
dish.UpdateDishProduct(context, model);
|
||||||
dish.UpdateDishProduct(context, model);
|
|
||||||
context.Database.CommitTransaction();
|
context.Database.CommitTransaction();
|
||||||
|
|
||||||
return dish.GetViewModel;
|
return dish.GetViewModel;
|
||||||
|
@ -60,7 +60,6 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
(model.VisitorId.HasValue && model.VisitorId == x.VisitorId))
|
(model.VisitorId.HasValue && model.VisitorId == x.VisitorId))
|
||||||
.Select(x => x.GetViewModel).ToList();
|
.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LunchViewModel> GetFullList()
|
public List<LunchViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new CanteenDatabase();
|
using var context = new CanteenDatabase();
|
||||||
@ -69,7 +68,6 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
.ThenInclude(x => x.Product)
|
.ThenInclude(x => x.Product)
|
||||||
.Select(x => x.GetViewModel).ToList();
|
.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LunchViewModel? Insert(LunchBindingModel model)
|
public LunchViewModel? Insert(LunchBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new CanteenDatabase();
|
using var context = new CanteenDatabase();
|
||||||
@ -99,7 +97,6 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LunchViewModel? Update(LunchBindingModel model)
|
public LunchViewModel? Update(LunchBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new CanteenDatabase();
|
using var context = new CanteenDatabase();
|
||||||
@ -118,6 +115,10 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
lunch.Update(model);
|
lunch.Update(model);
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
if (model.LunchProducts != null)
|
||||||
|
lunch.UpdateProducts(context, model);
|
||||||
|
if (model.LunchOrders != null)
|
||||||
|
lunch.UpdateOrders(context, model);
|
||||||
context.Database.CommitTransaction();
|
context.Database.CommitTransaction();
|
||||||
|
|
||||||
return lunch.GetViewModel;
|
return lunch.GetViewModel;
|
||||||
@ -129,7 +130,6 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LunchViewModel? Delete(LunchBindingModel model)
|
public LunchViewModel? Delete(LunchBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new CanteenDatabase();
|
using var context = new CanteenDatabase();
|
||||||
|
@ -115,58 +115,5 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
|
|
||||||
return client.GetViewModel;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace CanteenDatabaseImplement.Implements
|
|||||||
|
|
||||||
public List<TablewareViewModel> GetFilteredList(TablewareSearchModel model)
|
public List<TablewareViewModel> GetFilteredList(TablewareSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.TablewareName))
|
if (!model.VisitorId.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace CanteenDatabaseImplement.Migrations
|
namespace CanteenDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(CanteenDatabase))]
|
[DbContext(typeof(CanteenDatabase))]
|
||||||
[Migration("20230517172033_InitMigr")]
|
[Migration("20230518211530_Init")]
|
||||||
partial class InitMigr
|
partial class Init
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -78,19 +78,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountProducts")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
b.Property<int>("DishId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountProducts")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("DishId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("DishId", "ProductId");
|
|
||||||
|
|
||||||
b.HasIndex("ProductId");
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
@ -133,19 +138,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountOrders")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("LunchId")
|
b.Property<int>("LunchId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountOrders")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("LunchId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("LunchId", "OrderId");
|
|
||||||
|
|
||||||
b.HasIndex("OrderId");
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
@ -154,19 +164,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountProducts")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("LunchId")
|
b.Property<int>("LunchId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountProducts")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("LunchId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("LunchId", "ProductId");
|
|
||||||
|
|
||||||
b.HasIndex("ProductId");
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
@ -210,9 +225,6 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int?>("CountTablewares")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@ -220,17 +232,11 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
b.Property<double?>("Sum")
|
b.Property<double?>("Sum")
|
||||||
.HasColumnType("float");
|
.HasColumnType("float");
|
||||||
|
|
||||||
b.Property<int?>("TablewareId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("VisitorId")
|
b.Property<int>("VisitorId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("TablewareId");
|
|
||||||
|
|
||||||
b.HasIndex("VisitorId");
|
b.HasIndex("VisitorId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
@ -238,41 +244,51 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int>("CookId")
|
b.Property<int>("CookId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("OrderId", "CookId");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CookId");
|
b.HasIndex("CookId");
|
||||||
|
|
||||||
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
b.ToTable("OrderCook");
|
b.ToTable("OrderCook");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountTablewares")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
b.Property<int>("TablewareId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountDishes")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("OrderId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("OrderId", "DishId");
|
b.HasIndex("TablewareId");
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
b.ToTable("OrderTableware");
|
||||||
|
|
||||||
b.ToTable("OrderDish");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
||||||
@ -302,19 +318,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int>("CookId")
|
b.Property<int>("CookId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("ProductId", "CookId");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CookId");
|
b.HasIndex("CookId");
|
||||||
|
|
||||||
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
b.ToTable("ProductCook");
|
b.ToTable("ProductCook");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -461,20 +482,12 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Order", b =>
|
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")
|
b.HasOne("CanteenDatabaseImplement.Models.Visitor", "Visitor")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("VisitorId")
|
.HasForeignKey("VisitorId")
|
||||||
.OnDelete(DeleteBehavior.NoAction)
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Tableware");
|
|
||||||
|
|
||||||
b.Navigation("Visitor");
|
b.Navigation("Visitor");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -497,23 +510,23 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
b.Navigation("Order");
|
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")
|
b.HasOne("CanteenDatabaseImplement.Models.Order", "Order")
|
||||||
.WithMany("Dishes")
|
.WithMany("Tablewares")
|
||||||
.HasForeignKey("OrderId")
|
.HasForeignKey("OrderId")
|
||||||
.OnDelete(DeleteBehavior.NoAction)
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Dish");
|
b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("TablewareId")
|
||||||
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Order");
|
b.Navigation("Order");
|
||||||
|
|
||||||
|
b.Navigation("Tableware");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
||||||
@ -566,8 +579,6 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Orders");
|
|
||||||
|
|
||||||
b.Navigation("Products");
|
b.Navigation("Products");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -591,9 +602,9 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("Cooks");
|
b.Navigation("Cooks");
|
||||||
|
|
||||||
b.Navigation("Dishes");
|
|
||||||
|
|
||||||
b.Navigation("Lunches");
|
b.Navigation("Lunches");
|
||||||
|
|
||||||
|
b.Navigation("Tablewares");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace CanteenDatabaseImplement.Migrations
|
namespace CanteenDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitMigr : Migration
|
public partial class Init : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@ -130,6 +130,26 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
VisitorId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Sum = table.Column<double>(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(
|
migrationBuilder.CreateTable(
|
||||||
name: "Tablewares",
|
name: "Tablewares",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -154,14 +174,15 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "DishProduct",
|
name: "DishProduct",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
DishId = table.Column<int>(type: "int", nullable: false),
|
DishId = table.Column<int>(type: "int", nullable: false),
|
||||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||||
Id = table.Column<int>(type: "int", nullable: false),
|
|
||||||
CountProducts = table.Column<int>(type: "int", nullable: false)
|
CountProducts = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_DishProduct", x => new { x.DishId, x.ProductId });
|
table.PrimaryKey("PK_DishProduct", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_DishProduct_Dishes_DishId",
|
name: "FK_DishProduct_Dishes_DishId",
|
||||||
column: x => x.DishId,
|
column: x => x.DishId,
|
||||||
@ -178,13 +199,14 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "ProductCook",
|
name: "ProductCook",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
CookId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CookId = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_ProductCook", x => new { x.ProductId, x.CookId });
|
table.PrimaryKey("PK_ProductCook", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_ProductCook_Cooks_CookId",
|
name: "FK_ProductCook_Cooks_CookId",
|
||||||
column: x => x.CookId,
|
column: x => x.CookId,
|
||||||
@ -201,14 +223,15 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "LunchProduct",
|
name: "LunchProduct",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
LunchId = table.Column<int>(type: "int", nullable: false),
|
LunchId = table.Column<int>(type: "int", nullable: false),
|
||||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||||
Id = table.Column<int>(type: "int", nullable: false),
|
|
||||||
CountProducts = table.Column<int>(type: "int", nullable: false)
|
CountProducts = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_LunchProduct", x => new { x.LunchId, x.ProductId });
|
table.PrimaryKey("PK_LunchProduct", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_LunchProduct_Lunches_LunchId",
|
name: "FK_LunchProduct_Lunches_LunchId",
|
||||||
column: x => x.LunchId,
|
column: x => x.LunchId,
|
||||||
@ -222,45 +245,18 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Orders",
|
name: "LunchOrder",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
VisitorId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
TablewareId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
CountTablewares = table.Column<int>(type: "int", nullable: true),
|
|
||||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Sum = table.Column<double>(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<int>(type: "int", nullable: false),
|
LunchId = table.Column<int>(type: "int", nullable: false),
|
||||||
OrderId = table.Column<int>(type: "int", nullable: false),
|
OrderId = table.Column<int>(type: "int", nullable: false),
|
||||||
Id = table.Column<int>(type: "int", nullable: false),
|
|
||||||
CountOrders = table.Column<int>(type: "int", nullable: false)
|
CountOrders = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_LunchOrder", x => new { x.LunchId, x.OrderId });
|
table.PrimaryKey("PK_LunchOrder", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_LunchOrder_Lunches_LunchId",
|
name: "FK_LunchOrder_Lunches_LunchId",
|
||||||
column: x => x.LunchId,
|
column: x => x.LunchId,
|
||||||
@ -277,13 +273,14 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "OrderCook",
|
name: "OrderCook",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
CookId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
OrderId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
CookId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
OrderId = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_OrderCook", x => new { x.OrderId, x.CookId });
|
table.PrimaryKey("PK_OrderCook", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_OrderCook_Cooks_CookId",
|
name: "FK_OrderCook_Cooks_CookId",
|
||||||
column: x => x.CookId,
|
column: x => x.CookId,
|
||||||
@ -297,27 +294,28 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "OrderDish",
|
name: "OrderTableware",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
OrderId = table.Column<int>(type: "int", nullable: false),
|
OrderId = table.Column<int>(type: "int", nullable: false),
|
||||||
DishId = table.Column<int>(type: "int", nullable: false),
|
TablewareId = table.Column<int>(type: "int", nullable: false),
|
||||||
Id = table.Column<int>(type: "int", nullable: false),
|
CountTablewares = table.Column<int>(type: "int", nullable: false)
|
||||||
CountDishes = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_OrderDish", x => new { x.OrderId, x.DishId });
|
table.PrimaryKey("PK_OrderTableware", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_OrderDish_Dishes_DishId",
|
name: "FK_OrderTableware_Orders_OrderId",
|
||||||
column: x => x.DishId,
|
|
||||||
principalTable: "Dishes",
|
|
||||||
principalColumn: "Id");
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_OrderDish_Orders_OrderId",
|
|
||||||
column: x => x.OrderId,
|
column: x => x.OrderId,
|
||||||
principalTable: "Orders",
|
principalTable: "Orders",
|
||||||
principalColumn: "Id");
|
principalColumn: "Id");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_OrderTableware_Tablewares_TablewareId",
|
||||||
|
column: x => x.TablewareId,
|
||||||
|
principalTable: "Tablewares",
|
||||||
|
principalColumn: "Id");
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -330,6 +328,11 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
table: "Dishes",
|
table: "Dishes",
|
||||||
column: "ManagerId");
|
column: "ManagerId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DishProduct_DishId",
|
||||||
|
table: "DishProduct",
|
||||||
|
column: "DishId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_DishProduct_ProductId",
|
name: "IX_DishProduct_ProductId",
|
||||||
table: "DishProduct",
|
table: "DishProduct",
|
||||||
@ -340,11 +343,21 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
table: "Lunches",
|
table: "Lunches",
|
||||||
column: "VisitorId");
|
column: "VisitorId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LunchOrder_LunchId",
|
||||||
|
table: "LunchOrder",
|
||||||
|
column: "LunchId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_LunchOrder_OrderId",
|
name: "IX_LunchOrder_OrderId",
|
||||||
table: "LunchOrder",
|
table: "LunchOrder",
|
||||||
column: "OrderId");
|
column: "OrderId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LunchProduct_LunchId",
|
||||||
|
table: "LunchProduct",
|
||||||
|
column: "LunchId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_LunchProduct_ProductId",
|
name: "IX_LunchProduct_ProductId",
|
||||||
table: "LunchProduct",
|
table: "LunchProduct",
|
||||||
@ -356,25 +369,35 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
column: "CookId");
|
column: "CookId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_OrderDish_DishId",
|
name: "IX_OrderCook_OrderId",
|
||||||
table: "OrderDish",
|
table: "OrderCook",
|
||||||
column: "DishId");
|
column: "OrderId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_TablewareId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "TablewareId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Orders_VisitorId",
|
name: "IX_Orders_VisitorId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
column: "VisitorId");
|
column: "VisitorId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_OrderTableware_OrderId",
|
||||||
|
table: "OrderTableware",
|
||||||
|
column: "OrderId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_OrderTableware_TablewareId",
|
||||||
|
table: "OrderTableware",
|
||||||
|
column: "TablewareId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_ProductCook_CookId",
|
name: "IX_ProductCook_CookId",
|
||||||
table: "ProductCook",
|
table: "ProductCook",
|
||||||
column: "CookId");
|
column: "CookId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ProductCook_ProductId",
|
||||||
|
table: "ProductCook",
|
||||||
|
column: "ProductId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Products_ManagerId",
|
name: "IX_Products_ManagerId",
|
||||||
table: "Products",
|
table: "Products",
|
||||||
@ -402,20 +425,23 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "OrderCook");
|
name: "OrderCook");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "OrderDish");
|
name: "OrderTableware");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "ProductCook");
|
name: "ProductCook");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Lunches");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Dishes");
|
name: "Dishes");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Lunches");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Orders");
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Tablewares");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Cooks");
|
name: "Cooks");
|
||||||
|
|
||||||
@ -423,13 +449,10 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
name: "Products");
|
name: "Products");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Tablewares");
|
name: "Visitors");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Managers");
|
name: "Managers");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Visitors");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -75,19 +75,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.DishProduct", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountProducts")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
b.Property<int>("DishId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountProducts")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("DishId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("DishId", "ProductId");
|
|
||||||
|
|
||||||
b.HasIndex("ProductId");
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
@ -130,19 +135,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchOrder", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountOrders")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("LunchId")
|
b.Property<int>("LunchId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountOrders")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("LunchId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("LunchId", "OrderId");
|
|
||||||
|
|
||||||
b.HasIndex("OrderId");
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
@ -151,19 +161,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.LunchProduct", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountProducts")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("LunchId")
|
b.Property<int>("LunchId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountProducts")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("LunchId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("LunchId", "ProductId");
|
|
||||||
|
|
||||||
b.HasIndex("ProductId");
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
@ -207,9 +222,6 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int?>("CountTablewares")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@ -217,17 +229,11 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
b.Property<double?>("Sum")
|
b.Property<double?>("Sum")
|
||||||
.HasColumnType("float");
|
.HasColumnType("float");
|
||||||
|
|
||||||
b.Property<int?>("TablewareId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("VisitorId")
|
b.Property<int>("VisitorId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("TablewareId");
|
|
||||||
|
|
||||||
b.HasIndex("VisitorId");
|
b.HasIndex("VisitorId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
@ -235,41 +241,51 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderCook", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int>("CookId")
|
b.Property<int>("CookId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("OrderId", "CookId");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CookId");
|
b.HasIndex("CookId");
|
||||||
|
|
||||||
|
b.HasIndex("OrderId");
|
||||||
|
|
||||||
b.ToTable("OrderCook");
|
b.ToTable("OrderCook");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderDish", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.OrderTableware", b =>
|
||||||
{
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CountTablewares")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("OrderId")
|
b.Property<int>("OrderId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
b.Property<int>("TablewareId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CountDishes")
|
b.HasKey("Id");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.HasIndex("OrderId");
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("OrderId", "DishId");
|
b.HasIndex("TablewareId");
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
b.ToTable("OrderTableware");
|
||||||
|
|
||||||
b.ToTable("OrderDish");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
||||||
@ -299,19 +315,24 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.ProductCook", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("ProductId")
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<int>("CookId")
|
b.Property<int>("CookId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Id")
|
b.Property<int>("ProductId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("ProductId", "CookId");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CookId");
|
b.HasIndex("CookId");
|
||||||
|
|
||||||
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
b.ToTable("ProductCook");
|
b.ToTable("ProductCook");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -458,20 +479,12 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Order", b =>
|
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")
|
b.HasOne("CanteenDatabaseImplement.Models.Visitor", "Visitor")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("VisitorId")
|
.HasForeignKey("VisitorId")
|
||||||
.OnDelete(DeleteBehavior.NoAction)
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Tableware");
|
|
||||||
|
|
||||||
b.Navigation("Visitor");
|
b.Navigation("Visitor");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -494,23 +507,23 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
b.Navigation("Order");
|
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")
|
b.HasOne("CanteenDatabaseImplement.Models.Order", "Order")
|
||||||
.WithMany("Dishes")
|
.WithMany("Tablewares")
|
||||||
.HasForeignKey("OrderId")
|
.HasForeignKey("OrderId")
|
||||||
.OnDelete(DeleteBehavior.NoAction)
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Dish");
|
b.HasOne("CanteenDatabaseImplement.Models.Tableware", "Tableware")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("TablewareId")
|
||||||
|
.OnDelete(DeleteBehavior.NoAction)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Order");
|
b.Navigation("Order");
|
||||||
|
|
||||||
|
b.Navigation("Tableware");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
||||||
@ -563,8 +576,6 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Dish", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Orders");
|
|
||||||
|
|
||||||
b.Navigation("Products");
|
b.Navigation("Products");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -588,9 +599,9 @@ namespace CanteenDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("Cooks");
|
b.Navigation("Cooks");
|
||||||
|
|
||||||
b.Navigation("Dishes");
|
|
||||||
|
|
||||||
b.Navigation("Lunches");
|
b.Navigation("Lunches");
|
||||||
|
|
||||||
|
b.Navigation("Tablewares");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
modelBuilder.Entity("CanteenDatabaseImplement.Models.Product", b =>
|
||||||
|
@ -31,7 +31,7 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
if (_dishProducts == null)
|
if (_dishProducts == null)
|
||||||
{
|
{
|
||||||
_dishProducts = Products
|
_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;
|
return _dishProducts;
|
||||||
}
|
}
|
||||||
@ -39,8 +39,6 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
|
|
||||||
[ForeignKey("DishId")]
|
[ForeignKey("DishId")]
|
||||||
public virtual List<DishProduct> Products { get; set; } = new();
|
public virtual List<DishProduct> Products { get; set; } = new();
|
||||||
[ForeignKey("DishId")]
|
|
||||||
public virtual List<OrderDish> Orders { get; set; } = new();
|
|
||||||
public virtual Manager Manager { get; set; }
|
public virtual Manager Manager { get; set; }
|
||||||
|
|
||||||
public static Dish Create(CanteenDatabase context, DishBindingModel model)
|
public static Dish Create(CanteenDatabase context, DishBindingModel model)
|
||||||
@ -63,7 +61,6 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
DishName = model.DishName;
|
DishName = model.DishName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
ManagerId = model.ManagerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DishViewModel GetViewModel => new()
|
public DishViewModel GetViewModel => new()
|
||||||
@ -79,10 +76,10 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
public void UpdateDishProduct(CanteenDatabase context, DishBindingModel model)
|
public void UpdateDishProduct(CanteenDatabase context, DishBindingModel model)
|
||||||
{
|
{
|
||||||
var dishProduct = context.DishProduct.Where(rec => rec.DishId == model.Id).ToList();
|
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.DishProduct.RemoveRange(dishProduct.Where(rec => !model.DishProducts.ContainsKey(rec.ProductId)));
|
||||||
context.SaveChanges();
|
|
||||||
foreach (var updateProduct in dishProduct)
|
foreach (var updateProduct in dishProduct)
|
||||||
{
|
{
|
||||||
updateProduct.CountProducts = model.DishProducts[updateProduct.ProductId].Item2;
|
updateProduct.CountProducts = model.DishProducts[updateProduct.ProductId].Item2;
|
||||||
@ -90,17 +87,23 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
context.SaveChanges();
|
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
|
context.DishProduct.Add(new DishProduct
|
||||||
{
|
{
|
||||||
Dish = dish,
|
Dish = dish,
|
||||||
Product = context.Products.First(x => x.Id == dp.Key),
|
Product = product,
|
||||||
CountProducts = dp.Value.Item2
|
CountProducts = dp.Value.Item2
|
||||||
});
|
});
|
||||||
context.SaveChanges();
|
model.DishProducts.Remove(dp.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
_dishProducts = null;
|
_dishProducts = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,21 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IOrderModel, int)>? _lunchOrders = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IOrderModel, int)> LunchOrders
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_lunchOrders == null)
|
||||||
|
{
|
||||||
|
_lunchOrders = Orders.ToDictionary(record => record.OrderId, record => (record.Order as IOrderModel, record.CountOrders));
|
||||||
|
}
|
||||||
|
return _lunchOrders;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[ForeignKey("LunchId")]
|
[ForeignKey("LunchId")]
|
||||||
public virtual List<LunchProduct> Products { get; set; } = new();
|
public virtual List<LunchProduct> Products { get; set; } = new();
|
||||||
[ForeignKey("LunchId")]
|
[ForeignKey("LunchId")]
|
||||||
@ -62,6 +77,11 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Product = context.Products.First(y => y.Id == x.Key),
|
Product = context.Products.First(y => y.Id == x.Key),
|
||||||
CountProducts = x.Value.Item2
|
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()
|
}).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -116,5 +136,35 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
|
|
||||||
_lunchProducts = null;
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,35 +17,48 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int VisitorId { get; private set; }
|
public int VisitorId { get; private set; }
|
||||||
public int? TablewareId { get; set; }
|
|
||||||
public int? CountTablewares { get; set; }
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Description { get; private set; } = string.Empty;
|
public string Description { get; private set; } = string.Empty;
|
||||||
public double? Sum { get; private set; }
|
public double? Sum { get; private set; }
|
||||||
|
|
||||||
private Dictionary<int, (IDishModel, int)>? _orderDishes = null;
|
private Dictionary<int, ICookModel>? _orderCooks = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IDishModel, int)> OrderDishes
|
public Dictionary<int, ICookModel> OrderCooks
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_orderDishes == null)
|
if (_orderCooks == null)
|
||||||
{
|
{
|
||||||
_orderDishes = Dishes
|
_orderCooks = Cooks
|
||||||
.ToDictionary(recOD => recOD.DishId, recOD => (recOD.Dish as IDishModel, recOD.CountDishes));
|
.ToDictionary(recOD => recOD.CookId, recOD => recOD.Cook as ICookModel);
|
||||||
}
|
}
|
||||||
return _orderDishes;
|
return _orderCooks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (ITablewareModel, int)>? _orderTablewares = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (ITablewareModel, int)> 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<OrderDish> Dishes { get; set; } = new();
|
|
||||||
[ForeignKey("OrderId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<LunchOrder> Lunches { get; set; } = new();
|
public virtual List<LunchOrder> Lunches { get; set; } = new();
|
||||||
[ForeignKey("OrderId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<OrderCook> Cooks { get; set; } = new();
|
public virtual List<OrderCook> Cooks { get; set; } = new();
|
||||||
public virtual Tableware Tableware { get; set; }
|
[ForeignKey("OrderId")]
|
||||||
|
public virtual List<OrderTableware> Tablewares { get; set; } = new();
|
||||||
public virtual Visitor Visitor { get; set; }
|
public virtual Visitor Visitor { get; set; }
|
||||||
|
|
||||||
public static Order Create(OrderBindingModel model)
|
public static Order Create(OrderBindingModel model)
|
||||||
@ -69,7 +82,6 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VisitorId = model.VisitorId;
|
|
||||||
Description = model.Description;
|
Description = model.Description;
|
||||||
Sum = model.Sum;
|
Sum = model.Sum;
|
||||||
}
|
}
|
||||||
@ -80,35 +92,62 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
VisitorId = VisitorId,
|
VisitorId = VisitorId,
|
||||||
Description = Description,
|
Description = Description,
|
||||||
Sum = Sum,
|
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();
|
var orderCook = context.OrderCook.Where(rec => rec.CookId == model.Id).ToList();
|
||||||
if (orderDish != null && (orderDish.Count > 0))
|
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();
|
context.SaveChanges();
|
||||||
foreach (var updateDish in orderDish)
|
foreach (var updateCook in orderCook)
|
||||||
{
|
{
|
||||||
updateDish.CountDishes = model.OrderDishes[updateDish.DishId].Item2;
|
model.OrderCooks.Remove(updateCook.CookId);
|
||||||
model.OrderDishes.Remove(updateDish.DishId);
|
|
||||||
}
|
}
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var order = context.Orders.First(x => x.Id == Id);
|
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,
|
Order = order,
|
||||||
Dish = context.Dishes.First(x => x.Id == dp.Key),
|
Cook = context.Cooks.First(x => x.Id == dp.Key)
|
||||||
CountDishes = dp.Value.Item2
|
|
||||||
});
|
});
|
||||||
context.SaveChanges();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
22
Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs
Normal file
22
Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ namespace CanteenDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public string TablewareName { get; private set; } = string.Empty;
|
public string TablewareName { get; private set; } = string.Empty;
|
||||||
[ForeignKey("TablewareId")]
|
[ForeignKey("TablewareId")]
|
||||||
public virtual List<Order> Orders { get; set; } = new();
|
public virtual List<OrderTableware> Orders { get; set; } = new();
|
||||||
public virtual Visitor Visitor { get; set; }
|
public virtual Visitor Visitor { get; set; }
|
||||||
public static Tableware? Create(TablewareBindingModel model)
|
public static Tableware? Create(TablewareBindingModel model)
|
||||||
{
|
{
|
||||||
|
@ -397,10 +397,12 @@ namespace CanteenManagerApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Количество продукта должно быть больше 0");
|
throw new Exception("Количество продукта должно быть больше 0");
|
||||||
}
|
}
|
||||||
|
ProductViewModel product = APIClient.GetRequest<ProductViewModel>($"api/main/getproduct?id={selectedProduct}");
|
||||||
|
|
||||||
APIClient.PostRequest("api/main/dishaddproducts", Tuple.Create
|
APIClient.PostRequest("api/main/dishaddproducts", Tuple.Create
|
||||||
(
|
(
|
||||||
new DishSearchModel { Id = selectedDish },
|
new DishBindingModel { Id = selectedDish },
|
||||||
new ProductViewModel { Id = selectedProduct },
|
new ProductViewModel { Id = selectedProduct, Price = product.Price },
|
||||||
count
|
count
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ namespace CanteenRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<TablewareViewModel>? GetTablewareList()
|
public List<TablewareViewModel>? GetTablewareList(int visitorId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _tableware.ReadList(null);
|
return _tableware.ReadList(new TablewareSearchModel { VisitorId = visitorId });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void CreateTableware(TablewareBindingModel model)
|
public void CreateTableware(TablewareBindingModel model)
|
||||||
{
|
{
|
||||||
@ -57,7 +56,32 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
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]
|
[HttpGet]
|
||||||
public List<CookViewModel>? GetCookList(int managerId)
|
public List<CookViewModel>? GetCookList(int managerId)
|
||||||
{
|
{
|
||||||
@ -71,7 +95,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void CookCreate(CookBindingModel model)
|
public void CookCreate(CookBindingModel model)
|
||||||
{
|
{
|
||||||
@ -85,7 +108,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void CookDelete(CookBindingModel model)
|
public void CookDelete(CookBindingModel model)
|
||||||
{
|
{
|
||||||
@ -99,7 +121,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void CookUpdate(CookBindingModel model)
|
public void CookUpdate(CookBindingModel model)
|
||||||
{
|
{
|
||||||
@ -113,7 +134,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<DishViewModel>? GetDishList(int managerId)
|
public List<DishViewModel>? GetDishList(int managerId)
|
||||||
{
|
{
|
||||||
@ -127,7 +147,19 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
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]
|
[HttpPost]
|
||||||
public void DishCreate(DishBindingModel model)
|
public void DishCreate(DishBindingModel model)
|
||||||
{
|
{
|
||||||
@ -154,7 +186,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void DishUpdate(DishBindingModel model)
|
public void DishUpdate(DishBindingModel model)
|
||||||
{
|
{
|
||||||
@ -169,11 +200,11 @@ namespace CanteenRestApi.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void DishAddProducts(Tuple<DishSearchModel, ProductViewModel, int> model)
|
public void DishAddProducts(Tuple<DishBindingModel, ProductViewModel, int> model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_dish.AddCooksToProduct(model.Item1, model.Item2, model.Item3);
|
_dish.AddProductsToDish(model.Item1, model.Item2, model.Item3);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -181,7 +212,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<ProductViewModel>? GetProductList(int managerId)
|
public List<ProductViewModel>? GetProductList(int managerId)
|
||||||
{
|
{
|
||||||
@ -195,7 +225,19 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
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]
|
[HttpPost]
|
||||||
public void ProductCreate(ProductBindingModel model)
|
public void ProductCreate(ProductBindingModel model)
|
||||||
{
|
{
|
||||||
@ -222,7 +264,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ProductUpdate(ProductBindingModel model)
|
public void ProductUpdate(ProductBindingModel model)
|
||||||
{
|
{
|
||||||
@ -236,7 +277,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ProductAddCooks(Tuple<ProductSearchModel, CookViewModel> model)
|
public void ProductAddCooks(Tuple<ProductSearchModel, CookViewModel> model)
|
||||||
{
|
{
|
||||||
@ -250,7 +290,6 @@ namespace CanteenRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public GraphicViewModel[] GetGraphic()
|
public GraphicViewModel[] GetGraphic()
|
||||||
{
|
{
|
||||||
|
68
Canteen/CanteenRestApi/Controllers/VisitorController.cs
Normal file
68
Canteen/CanteenRestApi/Controllers/VisitorController.cs
Normal file
@ -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<VisitorController> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,12 +11,14 @@ builder.Logging.AddLog4Net("log4net.config");
|
|||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddTransient<IManagerStorage, ManagerStorage>();
|
builder.Services.AddTransient<IManagerStorage, ManagerStorage>();
|
||||||
|
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
|
||||||
builder.Services.AddTransient<ICookStorage, CookStorage>();
|
builder.Services.AddTransient<ICookStorage, CookStorage>();
|
||||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||||
builder.Services.AddTransient<IDishStorage, DishStorage>();
|
builder.Services.AddTransient<IDishStorage, DishStorage>();
|
||||||
builder.Services.AddTransient<ITablewareStorage, TablewareStorage>();
|
builder.Services.AddTransient<ITablewareStorage, TablewareStorage>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IManagerLogic, ManagerLogic>();
|
builder.Services.AddTransient<IManagerLogic, ManagerLogic>();
|
||||||
|
builder.Services.AddTransient<IVisitorLogic, VisitorLogic>();
|
||||||
builder.Services.AddTransient<ICookLogic, CookLogic>();
|
builder.Services.AddTransient<ICookLogic, CookLogic>();
|
||||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
builder.Services.AddTransient<IDishLogic, DishLogic>();
|
builder.Services.AddTransient<IDishLogic, DishLogic>();
|
||||||
|
@ -8,6 +8,7 @@ namespace CanteenVisitorApp
|
|||||||
public static class APIClient
|
public static class APIClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient _client = new();
|
private static readonly HttpClient _client = new();
|
||||||
|
public static VisitorViewModel? Visitor { get; set; } = null;
|
||||||
public static void Connect(IConfiguration configuration)
|
public static void Connect(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\CanteenBusinessLogic\CanteenBusinessLogic.csproj" />
|
<ProjectReference Include="..\CanteenBusinessLogic\CanteenBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\CanteenContracts\CanteenContracts.csproj" />
|
|
||||||
<ProjectReference Include="..\CanteenDatabaseImplement\CanteenDatabaseImplement.csproj" />
|
<ProjectReference Include="..\CanteenDatabaseImplement\CanteenDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" />
|
<ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using CanteenContracts.View;
|
using CanteenContracts.View;
|
||||||
using CanteenVisitorApp.Models;
|
using CanteenVisitorApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace CanteenVisitorApp.Controllers
|
namespace CanteenVisitorApp.Controllers
|
||||||
@ -15,70 +16,254 @@ namespace CanteenVisitorApp.Controllers
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
|
if (APIClient.Visitor == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
|
||||||
return View();
|
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<VisitorViewModel>($"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()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Lunches()
|
|
||||||
{
|
|
||||||
|
|
||||||
ViewBag.Cooks = APIClient.GetRequest<List<LunchViewModel>>("api/main/getcooklist");
|
|
||||||
ViewBag.Lunches = new List<LunchViewModel>();
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Tablewares()
|
public IActionResult Tablewares()
|
||||||
{
|
{
|
||||||
ViewBag.Tablewares = APIClient.GetRequest<List<TablewareViewModel>>("api/main/gettablewarelist");
|
if (APIClient.Visitor == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Tablewares = APIClient.GetRequest<List<TablewareViewModel>>($"api/main/gettablewarelist?visitorId={APIClient.Visitor.Id}");
|
||||||
return View();
|
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<List<TablewareViewModel>>($"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<List<TablewareViewModel>>($"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]
|
[HttpGet]
|
||||||
public IActionResult Orders()
|
public IActionResult Orders()
|
||||||
{
|
{
|
||||||
ViewBag.Orders = new List<OrderViewModel>();
|
if (APIClient.Visitor == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Orders = APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorderlist?visitorId={APIClient.Visitor.Id}");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult CreateOrder()
|
public IActionResult CreateOrder()
|
||||||
{
|
{
|
||||||
ViewBag.Dishes = new List<DishViewModel>();
|
if (APIClient.Visitor == null)
|
||||||
return View();
|
{
|
||||||
}
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
[HttpGet]
|
|
||||||
public IActionResult CreateLunch()
|
|
||||||
{
|
|
||||||
ViewBag.Products = new List<ProductViewModel>();
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[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,
|
throw new Exception("Доступ возможен только авторизованным пользователям");
|
||||||
TablewareName = TablewareName
|
}
|
||||||
|
|
||||||
|
|
||||||
|
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||||
|
{
|
||||||
|
VisitorId = APIClient.Visitor.Id,
|
||||||
|
OrderName = ordername
|
||||||
});
|
});
|
||||||
Response.Redirect("Tablewares");
|
|
||||||
|
Response.Redirect("Orders");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult CreateTableware()
|
public IActionResult DeleteOrder()
|
||||||
{
|
{
|
||||||
ViewBag.Orders = new List<OrderViewModel>();
|
if (APIClient.Visitor == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Orders = APIClient.GetRequest<List<OrderViewModel>>($"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<List<OrderViewModel>>($"api/main/getorderlist?visitorId={APIClient.Visitor.Id}");
|
||||||
return View();
|
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)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
@*
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Lunch";
|
ViewData["Title"] = "CreateLunch";
|
||||||
}
|
}
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="display-4">Добавление обеда</h2>
|
<h2 class="display-4">Добавление обеда</h2>
|
||||||
@ -14,20 +14,13 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Название обеда:</div>
|
<div class="col-4">Название обеда:</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" name="LunchName" id="LunchName" />
|
<input type="text" name="name" id="name" />
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Сумма:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<input type="text" name="Sum" id="Sum" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Продукты:</div>
|
<div class="col-4">Продукты:</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<select id="products" name="products" class="form-control" asp-items="@(new SelectList(@ViewBag.Products, "Id", "ProductName"))" multiple></select>
|
<select id="id" name="id" class="form-control" asp-items="@(new SelectList(@ViewBag.ProductList, "Id", "ProductName"))" multiple></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -36,4 +29,55 @@
|
|||||||
<input type="submit" value="Добавить" class="btn btn-primary" />
|
<input type="submit" value="Добавить" class="btn btn-primary" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form>*@
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "CreateLunch";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Добавление обеда</h2>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.row{
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Название обеда:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<input type="text" name="name" id="name" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Продукты:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="productId" name="productId" class="form-control" asp-items="@(new SelectList(@ViewBag.ProductList, "Id", "ProductName"))"></select>
|
||||||
|
<input type="number" name="count" id="count" />
|
||||||
|
<input type="button" value="Добавить продукт" class="btn btn-primary" onclick="addProduct()" />
|
||||||
|
<ul id="productList"></ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Создать" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var products = [];
|
||||||
|
|
||||||
|
function addProduct() {
|
||||||
|
var productId = document.getElementById("productId").value;
|
||||||
|
var productName = document.getElementById("productId").options[document.getElementById("productId").selectedIndex].text;
|
||||||
|
var count = document.getElementById("count").value;
|
||||||
|
|
||||||
|
var product = { productId: Number(productId), count: Number(count) };
|
||||||
|
products.push(product);
|
||||||
|
|
||||||
|
var listItem = document.createElement("li");
|
||||||
|
listItem.innerHTML = productName + " - " + count;
|
||||||
|
document.getElementById("productList").appendChild(listItem);
|
||||||
|
}
|
||||||
|
</script>
|
@ -11,30 +11,12 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Название заказа:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<input type="text" name="OrderName" id="OrderName" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Описание заказа:</div>
|
<div class="col-4">Описание заказа:</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" name="DescriptionOrder" id="DescriptionOrder" />
|
<input type="text" name="DescriptionOrder" id="DescriptionOrder" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Сумма:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<input type="text" name="Sum" id="Sum" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Блюда:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<select id="dishes" name="dishes" class="form-control" asp-items="@(new SelectList(@ViewBag.Dishes, "Id", "DishName"))" multiple></select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
@ -17,18 +17,6 @@
|
|||||||
<input type="text" name="TablewareName" id="TablewareName" />
|
<input type="text" name="TablewareName" id="TablewareName" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Количество:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<input type="number" name="TablewareCount" id="TablewareCount" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-4">Заказ:</div>
|
|
||||||
<div class="col-8">
|
|
||||||
<select id="dishes" name="dishes" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders, "Id"))"></select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
25
Canteen/CanteenVisitorApp/Views/Home/DeleteOrder.cshtml
Normal file
25
Canteen/CanteenVisitorApp/Views/Home/DeleteOrder.cshtml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "DeleteOrder";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Удаление заказа</h2>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.row {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Выберите заказ</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="id" name="id" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders, "Id"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Удалить" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
25
Canteen/CanteenVisitorApp/Views/Home/DeleteTableware.cshtml
Normal file
25
Canteen/CanteenVisitorApp/Views/Home/DeleteTableware.cshtml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "DeleteTableware";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Удаление прибора</h2>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.row {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Выберите прибор</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="id" name="id" class="form-control" asp-items="@(new SelectList(@ViewBag.Tablewares, "Id", "TablewareName"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Удалить" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
20
Canteen/CanteenVisitorApp/Views/Home/Enter.cshtml
Normal file
20
Canteen/CanteenVisitorApp/Views/Home/Enter.cshtml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Enter";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Вход в приложение</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Логин:</div>
|
||||||
|
<div class="col-8"><input type="text" name="login" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Пароль:</div>
|
||||||
|
<div class="col-8"><input type="password" name="password" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Вход" class="btn btnprimary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
48
Canteen/CanteenVisitorApp/Views/Home/LunchAddProducts.cshtml
Normal file
48
Canteen/CanteenVisitorApp/Views/Home/LunchAddProducts.cshtml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
@using CanteenContracts.View;
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "LunchAddProducts";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Привязка продукта к обеду</h2>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.row {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Обед:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="selectedLunch" name="selectedLunch">
|
||||||
|
@foreach (var Lunch in ViewBag.LunchList as List<LunchViewModel>)
|
||||||
|
{
|
||||||
|
<option value="@Lunch.Id">@Lunch.LunchName</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Продукт:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select name="selectedProduct">
|
||||||
|
@foreach (var product in ViewBag.ProductList as List<ProductViewModel>)
|
||||||
|
{
|
||||||
|
<option value="@product.Id">@product.ProductName</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Количество:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<input type="text" name="count" id="count" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Добавить" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -5,27 +5,28 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Список обедов</h2>
|
<h2>Список обедов</h2>
|
||||||
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateOrder", "Home")'">Добавить заказ</button>
|
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateOrder", "Home")'">Добавить заказ</button>
|
||||||
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateOrder", "Home")'">Удалить заказ</button>
|
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("DeleteOrder", "Home")'">Удалить заказ</button>
|
||||||
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateOrder", "Home")'">Обновить заказ</button>
|
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("UpdateOrder", "Home")'">Обновить заказ</button>
|
||||||
<button type="button" class="btn btn-success" onclick="location.href='@Url.Action("CreateOrder", "Home")'">Привязать повара</button>
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Номер</th>
|
<th>Номер</th>
|
||||||
<th>Номер посетителя</th>
|
|
||||||
<th>Описание обеда</th>
|
<th>Описание обеда</th>
|
||||||
<th>Сумма</th>
|
<th>Сумма</th>
|
||||||
|
<th>Название прибора</th>
|
||||||
|
<th>Количество прибора</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var cook in ViewBag.Orders)
|
@foreach (var order in ViewBag.Orders)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@cook.Id</td>
|
<td>@order.Id</td>
|
||||||
<td>@cook.VisitorId</td>
|
<td>@order.Description</td>
|
||||||
<td>@cook.Description</td>
|
<td>@order.Sum</td>
|
||||||
<td>@cook.Sum</td>
|
<td>@order.TablewareName</td>
|
||||||
</tr>
|
<td>@order.CountTablewares</td>
|
||||||
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
29
Canteen/CanteenVisitorApp/Views/Home/Register.cshtml
Normal file
29
Canteen/CanteenVisitorApp/Views/Home/Register.cshtml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Register";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Регистрация</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Логин:</div>
|
||||||
|
<div class="col-8"><input type="text" name="login" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Пароль:</div>
|
||||||
|
<div class="col-8"><input type="password" name="password" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">ФИО:</div><div class="col-8"><input type="text" name="fio" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Номер телефона:</div>
|
||||||
|
<div class="col-8"><input type="text" name="phoneNumber" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4">
|
||||||
|
<input type="submit" value="Регистрация" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -5,13 +5,12 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Список приборов</h2>
|
<h2>Список приборов</h2>
|
||||||
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateTableware", "Home")'">Добавить прибор</button>
|
<button type="button" class="btn btn-info" onclick="location.href='@Url.Action("CreateTableware", "Home")'">Добавить прибор</button>
|
||||||
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("CreateTableware", "Home")'">Удалить прибор</button>
|
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("DeleteTableware", "Home")'">Удалить прибор</button>
|
||||||
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("CreateTableware", "Home")'">Обновить прибор</button>
|
<button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("UpdateTableware", "Home")'">Обновить прибор</button>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Номер</th>
|
<th>Номер</th>
|
||||||
<th>Номер посетителя</th>
|
|
||||||
<th>Название прибора</th>
|
<th>Название прибора</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -20,7 +19,6 @@
|
|||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@cook.Id</td>
|
<td>@cook.Id</td>
|
||||||
<td>@cook.VisitorId</td>
|
|
||||||
<td>@cook.TablewareName</td>
|
<td>@cook.TablewareName</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
23
Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml
Normal file
23
Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
@using Newtonsoft.Json;
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "UpdateOrder";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Данные заказа</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Заказ:</div>
|
||||||
|
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Orders, "Id"))"></select></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Прибор:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="tablewareId" name="tablewareId" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Tablewares, "Id", "TablewareName"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
42
Canteen/CanteenVisitorApp/Views/Home/UpdateTableware.cshtml
Normal file
42
Canteen/CanteenVisitorApp/Views/Home/UpdateTableware.cshtml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
@using Newtonsoft.Json;
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "UpdateTableware";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Данные прибора</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Прибор:</div>
|
||||||
|
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Tablewares, "Id", "TablewareName"))"></select></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Название прибора:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<input type="text" name="TablewareName" id="TablewareName" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>@*
|
||||||
|
<script>
|
||||||
|
const tablewars = [];
|
||||||
|
|
||||||
|
function populateFields() {
|
||||||
|
ViewBag.Tablewares.forEach(value => {
|
||||||
|
tablewars.push(value);
|
||||||
|
});
|
||||||
|
var selectedTablewareId = document.getElementById("Id").value;
|
||||||
|
var selectedTableware = tablewares.find(function (tableware) {
|
||||||
|
return tableware.Id === selectedTablewareId;
|
||||||
|
});
|
||||||
|
//console.log(selectedCook.FIO);
|
||||||
|
if (selectedTableware) {
|
||||||
|
document.getElementsByName("TablewareName")[0].value = selectedTableware.TablewareName;
|
||||||
|
document.getElementsByName("TablewareCount")[0].value = selectedTableware.TablewareCount;
|
||||||
|
}
|
||||||
|
console.log(document.getElementsByName("TablewareName")[0].value);
|
||||||
|
}
|
||||||
|
</script>*@
|
@ -28,6 +28,12 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Tablewares">Приборы</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Tablewares">Приборы</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Войти</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user