diff --git a/Canteen/CanteenContracts/BindingModels/CookBindingModel.cs b/Canteen/CanteenContracts/BindingModels/CookBindingModel.cs index 81f3dcd..db0a85d 100644 --- a/Canteen/CanteenContracts/BindingModels/CookBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/CookBindingModel.cs @@ -17,8 +17,6 @@ namespace CanteenContracts.BindingModels public string Patronymic { get; set; } = string.Empty; - public string Position { get; set; } - - + public string Position { get; set; } = string.Empty; } } diff --git a/Canteen/CanteenDatabaseImplement/Models/ProductLunch.cs b/Canteen/CanteenContracts/BindingModels/CookLinkBindingModel.cs similarity index 54% rename from Canteen/CanteenDatabaseImplement/Models/ProductLunch.cs rename to Canteen/CanteenContracts/BindingModels/CookLinkBindingModel.cs index bef033b..4a5d95e 100644 --- a/Canteen/CanteenDatabaseImplement/Models/ProductLunch.cs +++ b/Canteen/CanteenContracts/BindingModels/CookLinkBindingModel.cs @@ -4,9 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CanteenDatabaseImplement.Models +namespace CanteenContracts.BindingModels { - public class ProductLunch + public class CookLinkBindingModel { + public int Id { get; set; } } } diff --git a/Canteen/CanteenContracts/BindingModels/DishBindingModel.cs b/Canteen/CanteenContracts/BindingModels/DishBindingModel.cs index e85be09..9e5e9bb 100644 --- a/Canteen/CanteenContracts/BindingModels/DishBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/DishBindingModel.cs @@ -13,6 +13,6 @@ namespace CanteenContracts.BindingModels public string DishName { get; set; } = string.Empty; public double Cost { get; set; } public int ManagerId { get; set; } - public Dictionary DishProducts { get; set; } = new(); + public Dictionary DishProducts { get; set; } = new(); } } diff --git a/Canteen/CanteenContracts/BindingModels/DishLinkBindingModel.cs b/Canteen/CanteenContracts/BindingModels/DishLinkBindingModel.cs new file mode 100644 index 0000000..9a60bf5 --- /dev/null +++ b/Canteen/CanteenContracts/BindingModels/DishLinkBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.BindingModels +{ + public class DishLinkBindingModel + { + public int Id { get; set; } + } +} diff --git a/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs b/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs index 6adbecd..4931f79 100644 --- a/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/LunchBindingModel.cs @@ -14,9 +14,7 @@ namespace CanteenContracts.BindingModels public int VisitorId { get; set; } public string LunchName { get; set; } = string.Empty; public double Cost { get; set; } - public DateTime DateCreate { get; set; } = DateTime.Now; - public Dictionary LunchProducts { get; set; } = new(); - public Dictionary LunchOrders { get; set; } = new(); + public Dictionary LunchProducts { get; set; } = new(); } diff --git a/Canteen/CanteenContracts/BindingModels/LunchLinkBindingModel.cs b/Canteen/CanteenContracts/BindingModels/LunchLinkBindingModel.cs new file mode 100644 index 0000000..cac8c5b --- /dev/null +++ b/Canteen/CanteenContracts/BindingModels/LunchLinkBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenContracts.BindingModels +{ + public class LunchLinkBindingModel + { + public int Id { get; set; } + } +} diff --git a/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs b/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs index 495ddd1..1218707 100644 --- a/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/OrderBindingModel.cs @@ -12,8 +12,8 @@ namespace CanteenContracts.BindingModels { public int Id { get; set; } public int VisitorId { get; set; } - public string Description { get; set; } = string.Empty; - + public double Sum { get; set; } + public DateTime DateCreate { get; } = DateTime.Now; } } diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs index bdcac32..eb7fdd9 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,9 +12,10 @@ namespace CanteenContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); - bool TakeOrderInWork(OrderBindingModel model); - bool FinishOrder(OrderBindingModel model); - bool DeliveryOrder(OrderBindingModel model); + bool AddLunch(LunchLinkBindingModel model); + bool AddDish(DishLinkBindingModel model); + bool AddCook(CookLinkBindingModel model); } } diff --git a/Canteen/CanteenContracts/CanteenContracts.csproj b/Canteen/CanteenContracts/CanteenContracts.csproj index 88142b5..cad237d 100644 --- a/Canteen/CanteenContracts/CanteenContracts.csproj +++ b/Canteen/CanteenContracts/CanteenContracts.csproj @@ -12,7 +12,6 @@ - diff --git a/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs b/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs index d1b107f..4ee4e5c 100644 --- a/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/CookSearchModel.cs @@ -9,6 +9,7 @@ namespace CanteenContracts.SearchModel public class CookSearchModel { public int? Id { get; set; } + public int? ManagerId { get; set; } public string? Name { get; set; } public string? Surname { get; set; } public string? Patronymic { get; set; } diff --git a/Canteen/CanteenContracts/SearchModels/DishSearchModel.cs b/Canteen/CanteenContracts/SearchModels/DishSearchModel.cs index a2d8b21..98911bb 100644 --- a/Canteen/CanteenContracts/SearchModels/DishSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/DishSearchModel.cs @@ -9,6 +9,7 @@ namespace CanteenContracts.SearchModel public class DishSearchModel { public int? Id { get; set; } + public int? ManagerId { get; set; } public string? DishName { get; set; } } } diff --git a/Canteen/CanteenContracts/SearchModels/LunchSearchModel.cs b/Canteen/CanteenContracts/SearchModels/LunchSearchModel.cs index f72c5e5..79c7d30 100644 --- a/Canteen/CanteenContracts/SearchModels/LunchSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/LunchSearchModel.cs @@ -9,6 +9,7 @@ namespace CanteenContracts.SearchModel public class LunchSearchModel { public int? Id { get; set; } + public int? VisitorId { get; set; } public string? LunchName { get; set; } } } diff --git a/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs b/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs index 0ee00b2..2822fb3 100644 --- a/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/OrderSearchModel.cs @@ -9,7 +9,7 @@ namespace CanteenContracts.SearchModel public class OrderSearchModel { public int? Id { get; set; } - public int? ClientId { get; set; } + public int? VisitorId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/Canteen/CanteenContracts/SearchModels/ProductSearchModel.cs b/Canteen/CanteenContracts/SearchModels/ProductSearchModel.cs index 0324480..79675c1 100644 --- a/Canteen/CanteenContracts/SearchModels/ProductSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/ProductSearchModel.cs @@ -9,6 +9,7 @@ namespace CanteenContracts.SearchModel public class ProductSearchModel { public int? Id { get; set; } + public int? ManagerId { get; set; } public string? ProductName { get; set; } } } diff --git a/Canteen/CanteenContracts/SearchModels/TablewareSearchModel.cs b/Canteen/CanteenContracts/SearchModels/TablewareSearchModel.cs index 3e9cf43..cff2fcc 100644 --- a/Canteen/CanteenContracts/SearchModels/TablewareSearchModel.cs +++ b/Canteen/CanteenContracts/SearchModels/TablewareSearchModel.cs @@ -9,6 +9,7 @@ namespace CanteenContracts.SearchModel public class TablewareSearchModel { public int? Id { get; set; } + public int? VisitorId { get; set; } public string? TablewareName { get; set; } } } diff --git a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs index fd097fc..3ac7c65 100644 --- a/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs +++ b/Canteen/CanteenContracts/StoragesContracts/IOrderStorage.cs @@ -17,5 +17,8 @@ namespace CanteenContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); + OrderViewModel? AddLunch(LunchLinkBindingModel model); + OrderViewModel? AddDish(DishLinkBindingModel model); + OrderViewModel? AddCook(CookLinkBindingModel model); } } diff --git a/Canteen/CanteenContracts/ViewModels/CookViewModel.cs b/Canteen/CanteenContracts/ViewModels/CookViewModel.cs index a8ec6bb..00c41bb 100644 --- a/Canteen/CanteenContracts/ViewModels/CookViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/CookViewModel.cs @@ -16,8 +16,6 @@ namespace CanteenContracts.View public string Surname { get; set; } = string.Empty; [DisplayName("Отчество")] public string? Patronymic { get; set; } = string.Empty; - [DisplayName("Дата рождения")] - public DateTime DateOfBirth { get; set; } [DisplayName("Должность")] public string Position { get; set; } = string.Empty; diff --git a/Canteen/CanteenContracts/ViewModels/DishViewModel.cs b/Canteen/CanteenContracts/ViewModels/DishViewModel.cs index f132125..f89c4ba 100644 --- a/Canteen/CanteenContracts/ViewModels/DishViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/DishViewModel.cs @@ -11,11 +11,11 @@ namespace CanteenContracts.View public class DishViewModel : IDishModel { public int Id { get; set; } - public int VisitorId { get; set; } - public int ProductId { get; set; } + public int ManagerId { get; set; } [DisplayName("Название блюда")] public string DishName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } + public Dictionary DishProducts { get; set; } = new(); } } diff --git a/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs b/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs index f954e8d..15256e3 100644 --- a/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/OrderViewModel.cs @@ -13,23 +13,13 @@ namespace CanteenContracts.View { [DisplayName("Номер")] public int Id { get; set; } - public int LunchId { get; set; } - - public int ClientId { get; set; } + public int VisitorId { get; set; } [DisplayName("ФИО посетителя")] - public string ClientFIO { get; set; } = string.Empty; - - [DisplayName("Обед")] - public string LunchName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } + public string VisitorFIO { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; [DisplayName("Сумма")] public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } } } diff --git a/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs b/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs index 1197931..80fe9a6 100644 --- a/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/ProductViewModel.cs @@ -10,15 +10,12 @@ namespace CanteenContracts.View { public class ProductViewModel : IProductModel { + public int Id { get; set; } + public int ManagerId { get; set; } [DisplayName("Название продукта")] public string ProductName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } - - public int ManagerId { get; set; } - public Dictionary ProductCooks { get; set; } = new(); - - public int Id { get; set; } } } diff --git a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs index 38fc433..2b2596e 100644 --- a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs @@ -10,13 +10,13 @@ namespace CanteenContracts.View { public class TablewareViewModel : ITablewareModel { + + public int Id { get; set; } + public int VisitorId { get; set; } + public int OrderId { get; set; } [DisplayName("Название прибора")] public string TablewareName { get; set; } = string.Empty; - public int ClientId { get; set; } - - public int OrderId { get; set; } - - public int Id { get; set; } + public int Count { get; set; } } } diff --git a/Canteen/CanteenContracts/ViewModels/VisitorViewModel.cs b/Canteen/CanteenContracts/ViewModels/VisitorViewModel.cs index 5728334..759cc69 100644 --- a/Canteen/CanteenContracts/ViewModels/VisitorViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/VisitorViewModel.cs @@ -10,6 +10,7 @@ namespace CanteenContracts.View { public class VisitorViewModel : IVisitorModel { + public int Id { get; set; } [DisplayName("ФИО посетителя")] public string FIO { get; set; } = string.Empty; [DisplayName("Логин")] @@ -18,9 +19,6 @@ namespace CanteenContracts.View public string Password { get; set; } = string.Empty; [DisplayName("Номер телефона")] public string PhoneNumber { get; set; } = string.Empty; - public int RoleId { get; set; } - - public int Id { get; set; } } } diff --git a/Canteen/CanteenDataModels/Models/ICookModel.cs b/Canteen/CanteenDataModels/Models/ICookModel.cs index 8bcf7a4..a9c900c 100644 --- a/Canteen/CanteenDataModels/Models/ICookModel.cs +++ b/Canteen/CanteenDataModels/Models/ICookModel.cs @@ -8,7 +8,6 @@ namespace CanteenDataModels.Models { public interface ICookModel : IId { - int Id { get; } int ManagerId { get; } string Name { get; } diff --git a/Canteen/CanteenDataModels/Models/IDishModel.cs b/Canteen/CanteenDataModels/Models/IDishModel.cs index 8ed67a3..ab385cf 100644 --- a/Canteen/CanteenDataModels/Models/IDishModel.cs +++ b/Canteen/CanteenDataModels/Models/IDishModel.cs @@ -8,10 +8,9 @@ namespace CanteenDataModels.Models { public interface IDishModel : IId { - int Id { get; } string DishName { get; } double Cost { get; } int ManagerId { get; } - Dictionary DishProducts { get; } + Dictionary DishProducts { get; } } } diff --git a/Canteen/CanteenDataModels/Models/ILunchModel.cs b/Canteen/CanteenDataModels/Models/ILunchModel.cs index a96d68f..6529699 100644 --- a/Canteen/CanteenDataModels/Models/ILunchModel.cs +++ b/Canteen/CanteenDataModels/Models/ILunchModel.cs @@ -8,12 +8,9 @@ namespace CanteenDataModels.Models { public interface ILunchModel : IId { - int Id { get; } int VisitorId { get; } string LunchName { get; } double Cost { get; } - DateTime DateCreate { get; } - Dictionary LunchProducts { get; } - Dictionary LunchOrders { get; } + Dictionary LunchProducts { get; } } } diff --git a/Canteen/CanteenDataModels/Models/IManagerModel.cs b/Canteen/CanteenDataModels/Models/IManagerModel.cs index 5157ba8..da8b43c 100644 --- a/Canteen/CanteenDataModels/Models/IManagerModel.cs +++ b/Canteen/CanteenDataModels/Models/IManagerModel.cs @@ -8,7 +8,6 @@ namespace CanteenDataModels.Models { public interface IManagerModel : IId { - int Id { get; } string FIO { get; } string Login { get; } diff --git a/Canteen/CanteenDataModels/Models/IOrderModel.cs b/Canteen/CanteenDataModels/Models/IOrderModel.cs index 47c7f96..29c0a17 100644 --- a/Canteen/CanteenDataModels/Models/IOrderModel.cs +++ b/Canteen/CanteenDataModels/Models/IOrderModel.cs @@ -9,9 +9,9 @@ namespace CanteenDataModels.Models { public interface IOrderModel : IId { - int Id { get; } int VisitorId { get; } - string Description { get; } + double Sum { get; } + DateTime DateCreate { get; } } } diff --git a/Canteen/CanteenDataModels/Models/ITablewareModel.cs b/Canteen/CanteenDataModels/Models/ITablewareModel.cs index 345f2a9..3c6bd35 100644 --- a/Canteen/CanteenDataModels/Models/ITablewareModel.cs +++ b/Canteen/CanteenDataModels/Models/ITablewareModel.cs @@ -8,8 +8,9 @@ namespace CanteenDataModels.Models { public interface ITablewareModel : IId { - string TablewareName { get; } - int ManagerId { get; } + int VisitorId { get; } int OrderId { get; } + string TablewareName { get; } + int Count { get; } } } diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index 42f8331..6548567 100644 --- a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs +++ b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs @@ -14,15 +14,16 @@ namespace CanteenDatabaseImplement base.OnConfiguring(optionsBuilder); } public virtual DbSet Cooks { set; get; } - public virtual DbSet OrderCooks { set; get; } + public virtual DbSet OrderCooks { set; get; } public virtual DbSet Dishes { set; get; } public virtual DbSet Lunches { set; get; } - public virtual DbSet OrderLunches { set; get; } + public virtual DbSet OrderLunches { set; get; } public virtual DbSet Managers { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Products { set; get; } public virtual DbSet ProductCooks { set; get; } - public virtual DbSet LunchProducts { set; get; } + public virtual DbSet LunchProducts { set; get; } + public virtual DbSet DishProducts { set; get; } public virtual DbSet Roles { set; get; } public virtual DbSet Tablewares { set; get; } public virtual DbSet Visitors { set; get; } diff --git a/Canteen/CanteenDatabaseImplement/Models/Cook.cs b/Canteen/CanteenDatabaseImplement/Models/Cook.cs index b8483a2..ad49cac 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Cook.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Cook.cs @@ -11,23 +11,19 @@ namespace CanteenDatabaseImplement.Models { public class Cook : ICookModel { + public int Id { get; private set; } + [Required] + public int ManagerId { get; private set; } [Required] public string Name { get; private set; } = string.Empty; [Required] public string Surname { get; private set; } = string.Empty; - public string? Patronymic { get; private set; } = string.Empty; [Required] - public DateTime DateOfBirth { get; private set; } - [Required] public string Position { get; private set; } = string.Empty; - [Required] - public int ManagerId { get; private set; } - - public int Id { get; private set; } [ForeignKey("CookId")] public virtual List Products{ get; set; } = new(); [ForeignKey("CookId")] - public virtual List Orders { get; set; } = new(); + public virtual List Orders { get; set; } = new(); } } diff --git a/Canteen/CanteenDatabaseImplement/Models/Dish.cs b/Canteen/CanteenDatabaseImplement/Models/Dish.cs index 483356d..67832bb 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Dish.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Dish.cs @@ -1,12 +1,93 @@ -using System; +using CanteenContracts.BindingModels; +using CanteenContracts.View; +using CanteenDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CanteenDatabaseImplement.Models { - public class Dish + public class Dish : IDishModel { + public int Id { get; private set; } + [Required] + public string DishName { get; private set; } = string.Empty; + [Required] + public double Cost { get; private set; } + [Required] + public int ManagerId { get; private set; } + private Dictionary? _dishProducts = null; + public Dictionary DishProduct + { + get + { + if (_dishProducts == null) + { + _dishProducts = Products + .ToDictionary(recPC => recPC.ProductId, recPC => (recPC.Product as IProductModel, recPC.CountProduct)); + } + return _dishProducts; + } + } + [ForeignKey("DishId")] + public virtual List Products { get; set; } = new(); + public static Dish? Create(CanteenDatabase context, DishBindingModel model) + { + return new Dish() + { + Id = model.Id, + DishName = model.DishName, + Cost = model.Cost, + Products = model.DishProducts.Select(x => new DishProduct + { + Product = context.Products.First(y => y.Id == x.Key) + }).ToList() + }; + } + + public void Update(DishBindingModel model) + { + DishName = model.DishName; + Cost = model.Cost; + } + + public DishViewModel GetViewModel => new() + { + Id = Id, + DishName = DishName, + Cost = Cost, + DishProducts = DishProduct, + ManagerId = ManagerId + }; + + public Dictionary DishProducts => throw new NotImplementedException(); + + public void UpdateProduct(CanteenDatabase context, DishBindingModel model) + { + var dishProducts = context.DishProducts.Where(record => record.ProductId == model.Id).ToList(); + if (dishProducts != null && dishProducts.Count > 0) + { + context.DishProducts.RemoveRange(dishProducts.Where(record => !model.DishProducts.ContainsKey(record.ProductId))); + context.SaveChanges(); + } + + var product = context.Products.First(x => x.Id == Id); + foreach (var pc in model.DishProducts) + { + context.DishProducts.Add(new DishProduct + { + Product = product, + Dish = context.Dishes.First(x => x.Id == pc.Key), + }); + context.SaveChanges(); + } + + _dishProducts = null; + } } } diff --git a/Canteen/CanteenDatabaseImplement/Models/DishProduct.cs b/Canteen/CanteenDatabaseImplement/Models/DishProduct.cs new file mode 100644 index 0000000..15e00c1 --- /dev/null +++ b/Canteen/CanteenDatabaseImplement/Models/DishProduct.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenDatabaseImplement.Models +{ + public class DishProduct + { + public int Id { get; set; } + [Required] + public int DishId { get; set; } + [Required] + public int ProductId { get; set; } + [Required] + public int CountProduct { get; set; } + public virtual Dish Dish { get; set; } = new(); + public virtual Product Product { get; set; } = new(); + } +} diff --git a/Canteen/CanteenDatabaseImplement/Models/Lunch.cs b/Canteen/CanteenDatabaseImplement/Models/Lunch.cs index c4ca0fc..518b14f 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Lunch.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Lunch.cs @@ -1,22 +1,89 @@ using CanteenDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using CanteenContracts.BindingModels; +using CanteenContracts.View; namespace CanteenDatabaseImplement.Models { public class Lunch : ILunchModel { - public string LunchName => throw new NotImplementedException(); + public int Id { get; private set; } + public int VisitorId { get; private set; } + public string LunchName { get; private set; } = string.Empty; + public double Cost { get; private set; } + private Dictionary? _lunchProducts = null; + public Dictionary LunchProducts + { + get + { + if (_lunchProducts == null) + { + _lunchProducts = Products + .ToDictionary(recPC => recPC.ProductId, recPC => (recPC.Product as IProductModel, recPC.CountProduct)); + } + return _lunchProducts; + } + } + [ForeignKey("LunchId")] + public virtual List Orders { get; set; } = new(); + public virtual List Products { get; set; } = new(); + public static Lunch? Create(CanteenDatabase context, LunchBindingModel model) + { + return new Lunch() + { + Id = model.Id, + VisitorId = model.VisitorId, + LunchName = model.LunchName, + Cost = model.Cost, + Products = model.LunchProducts.Select(x => new LunchProduct + { + Product = context.Products.First(y => y.Id == x.Key) + }).ToList() + }; + } - public double Cost => throw new NotImplementedException(); + public void Update(LunchBindingModel model) + { + LunchName = model.LunchName; + Cost = model.Cost; + } - public int VisitorId => throw new NotImplementedException(); + public LunchViewModel GetViewModel => new() + { + Id = Id, + VisitorId = VisitorId, + LunchName = LunchName, + Cost = Cost, + LunchProducts = LunchProducts + }; - public Dictionary LunchProducts => throw new NotImplementedException(); + public void UpdateProduct(CanteenDatabase context, LunchBindingModel model) + { + var lunchProducts = context.LunchProducts.Where(record => record.ProductId == model.Id).ToList(); + if (lunchProducts != null && lunchProducts.Count > 0) + { + context.LunchProducts.RemoveRange(lunchProducts.Where(record => !model.LunchProducts.ContainsKey(record.ProductId))); + context.SaveChanges(); + } - public int Id => throw new NotImplementedException(); + var product = context.Products.First(x => x.Id == Id); + foreach (var pc in model.LunchProducts) + { + context.LunchProducts.Add(new LunchProduct + { + Product = product, + Lunch = context.Lunches.First(x => x.Id == pc.Key), + }); + context.SaveChanges(); + } + + _lunchProducts = null; + } } } diff --git a/Canteen/CanteenDatabaseImplement/Models/LunchOrder.cs b/Canteen/CanteenDatabaseImplement/Models/LunchProduct.cs similarity index 85% rename from Canteen/CanteenDatabaseImplement/Models/LunchOrder.cs rename to Canteen/CanteenDatabaseImplement/Models/LunchProduct.cs index fe583c0..34b0380 100644 --- a/Canteen/CanteenDatabaseImplement/Models/LunchOrder.cs +++ b/Canteen/CanteenDatabaseImplement/Models/LunchProduct.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace CanteenDatabaseImplement.Models { - public class LunchOrder + public class LunchProduct { } } diff --git a/Canteen/CanteenDatabaseImplement/Models/Order.cs b/Canteen/CanteenDatabaseImplement/Models/Order.cs index 4171092..a7f0af8 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Order.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Order.cs @@ -2,6 +2,7 @@ using CanteenDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; @@ -11,20 +12,22 @@ namespace CanteenDatabaseImplement.Models { public class Order : IOrderModel { - public int ClientId { get; private set; } - - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } + [Required] + public int VisitorId { get; private set; } + [Required] + public string Description { get; private set; } = string.Empty; + [Required] + public double Sum { get; private set; } + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; [ForeignKey("OrderId")] - public virtual List LunchOrders { get; set; } = new(); + public virtual List OrderLunches { get; set; } = new(); [ForeignKey("OrderId")] - public virtual List CookOrders { get; set; } = new(); + public virtual List OrderCooks { get; set; } = new(); + [ForeignKey("OrderId")] + public virtual List OrderDishes { get; set; } = new(); + [ForeignKey("OrderId")] + public virtual List Orderablewares { get; set; } = new(); } } diff --git a/Canteen/CanteenDatabaseImplement/Models/CookOrder.cs b/Canteen/CanteenDatabaseImplement/Models/OrderCook.cs similarity index 94% rename from Canteen/CanteenDatabaseImplement/Models/CookOrder.cs rename to Canteen/CanteenDatabaseImplement/Models/OrderCook.cs index b2a0b07..876e89f 100644 --- a/Canteen/CanteenDatabaseImplement/Models/CookOrder.cs +++ b/Canteen/CanteenDatabaseImplement/Models/OrderCook.cs @@ -7,18 +7,14 @@ using System.Threading.Tasks; namespace CanteenDatabaseImplement.Models { - public class CookOrder + public class OrderCook { public int Id { get; set; } - [Required] public int CookId { get; set; } - [Required] public int OrderId { get; set; } - public virtual Order Order { get; set; } = new(); - public virtual Cook Cook { get; set; } = new(); } } diff --git a/Canteen/CanteenDatabaseImplement/Models/OrderLunch.cs b/Canteen/CanteenDatabaseImplement/Models/OrderLunch.cs new file mode 100644 index 0000000..a1057c1 --- /dev/null +++ b/Canteen/CanteenDatabaseImplement/Models/OrderLunch.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CanteenDatabaseImplement.Models +{ + public class OrderLunch + { + public int Id { get; set; } + [Required] + public int OrderId { get; set; } + [Required] + public int LunchId { get; set; } + [Required] + public int CountProduct { get; set; } + public virtual Order Order { get; set; } = new(); + public virtual Lunch Lunch { get; set; } = new(); + } +} diff --git a/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs b/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs new file mode 100644 index 0000000..c5e279e --- /dev/null +++ b/Canteen/CanteenDatabaseImplement/Models/OrderTableware.cs @@ -0,0 +1,23 @@ +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 Count { get; set; } + public virtual Order Order { get; set; } = new(); + public virtual Tableware Tableware { get; set; } = new(); + } + +} diff --git a/Canteen/CanteenDatabaseImplement/Models/Product.cs b/Canteen/CanteenDatabaseImplement/Models/Product.cs index 61ea8f4..ce0bff2 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Product.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Product.cs @@ -8,16 +8,14 @@ namespace CanteenDatabaseImplement.Models { public class Product : IProductModel { + public int Id { get; private set; } [Required] public string ProductName { get; private set; } = string.Empty; [Required] public double Cost { get; private set; } [Required] public int ManagerId { get; private set; } - private Dictionary? _productCooks = null; - - public int Id { get; private set; } [NotMapped] public Dictionary ProductCooks { @@ -32,9 +30,8 @@ namespace CanteenDatabaseImplement.Models } [ForeignKey("ProductId")] public virtual List Cooks { get; set; } = new(); - [ForeignKey("ProductId")] - public virtual List Lunches { get; set; } = new(); + public virtual List Dishes { get; set; } = new(); public static Product? Create(CanteenDatabase context, ProductBindingModel model) { return new Product() diff --git a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs index e5f79da..9602934 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs @@ -1,12 +1,26 @@ -using System; +using CanteenDataModels.Models; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CanteenDatabaseImplement.Models { - public class Tableware + public class Tableware : ITablewareModel { + public int Id { get; private set; } + [Required] + public int VisitorId { get; private set; } + [Required] + public int OrderId { get; private set; } + [Required] + public string TablewareName { get; private set; } = string.Empty; + [Required] + public int Count { get; private set; } + [ForeignKey("TablewareId")] + public virtual List Orders { get; set; } = new(); } }