From 741d60317ede1224517209b4f158c2656e818811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Sat, 25 May 2024 13:06:38 +0400 Subject: [PATCH] DatabaseImplement 214.0 --- .../BindingModels/ProductBindingModel.cs | 2 +- .../SearchModels/OrderSearchModel.cs | 1 + ...{ICostItemModel.cs => ICostItemStorage.cs} | 2 +- .../StorageContracts/IEmployeeStorage.cs | 2 +- .../ViewModels/ProductViewModel.cs | 2 +- .../DataBase.cs | 7 +- .../Implements/CategoryProductStorage.cs | 83 ----------------- .../{UserStorage.cs => ClientStorage.cs} | 30 +++--- .../{RoleStorage.cs => CostItemStorage.cs} | 33 +++---- .../Implements/EmployeeStorage.cs | 79 ++++++++++++++++ .../Implements/OrderStorage.cs | 11 +-- .../Models/CategoryProduct.cs | 57 ------------ .../Models/Client.cs | 60 ++++++++++++ .../Models/CostItem.cs | 59 ++++++++++++ .../Models/Employee.cs | 59 ++++++++++++ .../Models/Order.cs | 39 ++++---- .../{OrderProducts.cs => OrderProduct.cs} | 5 +- .../Models/Product.cs | 26 +++--- .../Models/Role.cs | 55 ----------- .../Models/User.cs | 91 ------------------- 20 files changed, 333 insertions(+), 370 deletions(-) rename ElectronicsShop/ElectronicsShopContracts/StorageContracts/{ICostItemModel.cs => ICostItemStorage.cs} (94%) delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs rename ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/{UserStorage.cs => ClientStorage.cs} (64%) rename ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/{RoleStorage.cs => CostItemStorage.cs} (60%) create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/EmployeeStorage.cs delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs rename ElectronicsShop/ElectronicsShopDataBaseImplement/Models/{OrderProducts.cs => OrderProduct.cs} (90%) delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Role.cs delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs index b878167..856ef93 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs @@ -17,6 +17,6 @@ namespace ElectronicsShopContracts.BindingModels public double Price { get; set; } - public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено; + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; } } diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/OrderSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/OrderSearchModel.cs index 380f995..eba74b6 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/OrderSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/OrderSearchModel.cs @@ -14,5 +14,6 @@ namespace ElectronicsShopContracts.SearchModels public int? ClientID { get; set; } public int? EmployeeID { get; set; } public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set;} } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemModel.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemStorage.cs similarity index 94% rename from ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemModel.cs rename to ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemStorage.cs index 50c9fcc..7b47d0d 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICostItemStorage.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; namespace ElectronicsShopContracts.StorageContracts { - public interface ICostItemModel { + public interface ICostItemStorage { List GetFullList(); List GetFillteredList(CostItemSearchModel model); diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs index 323d5e0..e3ac8da 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs @@ -14,7 +14,7 @@ namespace ElectronicsShopContracts.StorageContracts List GetFullList(); List GetFilteredList(EmployeeSearchModel model); - EmployeeViewModel? GetElement(ClientSearchModel model); + EmployeeViewModel? GetElement(EmployeeSearchModel model); EmployeeViewModel? Insert(EmployeeBindingModel model); EmployeeViewModel? Update(EmployeeBindingModel model); EmployeeViewModel? Delete(EmployeeBindingModel model); diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs index 4804ee8..f1d96cb 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs @@ -21,6 +21,6 @@ namespace ElectronicsShopContracts.ViewModels public double Price { get; set; } [DisplayName("Статус оплаты")] - public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено; + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index 0279743..ec2f1de 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -15,11 +15,12 @@ namespace ElectronicsShopDataBaseImplement } base.OnConfiguring(optionsBuilder); } - public virtual DbSet CategoryProducts { set; get; } - public virtual DbSet Users { set; get; } - public virtual DbSet Roles { set; get; } + public virtual DbSet Clients { set; get; } public virtual DbSet Products { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet OrderProducts { set; get; } + public virtual DbSet Employees { set; get; } + public virtual DbSet CostItems { set; get; } } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs deleted file mode 100644 index b33553a..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs +++ /dev/null @@ -1,83 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.StorageContracts; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataBaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Implements -{ - public class CategoryProductStorage : ICategoryProductStorage - { - public CategoryProductViewModel? Delete(CategoryProductBindingModel model) - { - using var context = new Database(); - var element = context.CategoryProducts.FirstOrDefault(rec => rec.ID == model.ID); - if (element != null) - { - context.CategoryProducts.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public CategoryProductViewModel? GetElement(CategoryProductSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) - { - return null; - } - using var context = new Database(); - return context.CategoryProducts.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; - } - - public List GetFilteredList(CategoryProductSearchModel model) - { - if (string.IsNullOrEmpty(model.Name)) - { - return new(); - } - using var context = new Database(); - return context.CategoryProducts.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); - } - - public List GetFullList() - { - using var context = new Database(); - return context.CategoryProducts.Select(x => x.GetViewModel).ToList(); - } - - public CategoryProductViewModel? Insert(CategoryProductBindingModel model) - { - var newComponent = CategoryProduct.Create(model); - if (newComponent == null) - { - return null; - } - using var context = new Database(); - context.CategoryProducts.Add(newComponent); - context.SaveChanges(); - return newComponent.GetViewModel; - } - - public CategoryProductViewModel? Update(CategoryProductBindingModel model) - { - using var context = new Database(); - var component = context.CategoryProducts.FirstOrDefault(x => x.ID == model.ID); - if (component == null) - { - return null; - } - component.Update(model); - context.SaveChanges(); - return component.GetViewModel; - } - } -} - diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/UserStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs similarity index 64% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/UserStorage.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs index 6118117..a139737 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/UserStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs @@ -11,15 +11,15 @@ using System.Threading.Tasks; namespace ElectronicsShopDataBaseImplement.Implements { - public class UserStorage : IClientStorage + public class ClientStorage : IClientStorage { - public ClientViewModel? Delete(UserBindingModel model) + public ClientViewModel? Delete(ClientBindingModel model) { using var context = new Database(); - var element = context.Users.FirstOrDefault(rec => rec.ID == model.ID); + var element = context.Clients.FirstOrDefault(rec => rec.ID == model.ID); if (element != null) { - context.Users.Remove(element); + context.Clients.Remove(element); context.SaveChanges(); return element.GetViewModel; } @@ -28,49 +28,49 @@ namespace ElectronicsShopDataBaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue) + if (string.IsNullOrEmpty(model.Email) && !model.ID.HasValue) { return null; } using var context = new Database(); - return context.Users.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login || + return context.Clients.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email || (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; } public List GetFilteredList(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Login)) + if (string.IsNullOrEmpty(model.Email)) { return new(); } using var context = new Database(); - return context.Users.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList(); + return context.Clients.Where(x => x.Email.Contains(model.Email)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new Database(); - return context.Users.Select(x => x.GetViewModel).ToList(); + return context.Clients.Select(x => x.GetViewModel).ToList(); } - public ClientViewModel? Insert(UserBindingModel model) + public ClientViewModel? Insert(ClientBindingModel model) { - var newComponent = User.Create(model); + var newComponent = Client.Create(model); if (newComponent == null) { return null; } using var context = new Database(); - context.Users.Add(newComponent); + context.Clients.Add(newComponent); context.SaveChanges(); return newComponent.GetViewModel; } - public ClientViewModel? Update(UserBindingModel model) + public ClientViewModel? Update(ClientBindingModel model) { using var context = new Database(); - var component = context.Users.FirstOrDefault(x => x.ID == model.ID); + var component = context.Clients.FirstOrDefault(x => x.ID == model.ID); if (component == null) { return null; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/RoleStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CostItemStorage.cs similarity index 60% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/RoleStorage.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CostItemStorage.cs index 9c6c4ad..6e1f5b1 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/RoleStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CostItemStorage.cs @@ -11,65 +11,66 @@ using System.Threading.Tasks; namespace ElectronicsShopDataBaseImplement.Implements { - public class RoleStorage: IRoleStorage + public class CostItemStorage : ICostItemStorage { - public RoleViewModel? Delete(RoleBindingModel model) + public CostItemViewModel? Delete(CostItemBindingModel model) { using var context = new Database(); - var element = context.Roles.FirstOrDefault(rec => rec.ID == model.ID); + var element = context.CostItems.FirstOrDefault(rec => rec.ID == model.ID); if (element != null) { - context.Roles.Remove(element); + context.CostItems.Remove(element); context.SaveChanges(); return element.GetViewModel; } return null; } - public RoleViewModel? GetElement(RoleSearchModel model) + public CostItemViewModel GetElement(CostItemSearchModel model) { if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; } using var context = new Database(); - return context.Roles.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; + return context.CostItems.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name || + (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; } - public List GetFilteredList(RoleSearchModel model) + public List GetFillteredList(CostItemSearchModel model) { if (string.IsNullOrEmpty(model.Name)) { return new(); } using var context = new Database(); - return context.Roles.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + return context.CostItems.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); } - public List GetFullList() + public List GetFullList() { using var context = new Database(); - return context.Roles.Select(x => x.GetViewModel).ToList(); + return context.CostItems.Select(x => x.GetViewModel).ToList(); } - public RoleViewModel? Insert(RoleBindingModel model) + public CostItemViewModel? Insert(CostItemBindingModel model) { - var newComponent = Role.Create(model); + var newComponent = CostItem.Create(model); if (newComponent == null) { return null; } using var context = new Database(); - context.Roles.Add(newComponent); + context.CostItems.Add(newComponent); context.SaveChanges(); return newComponent.GetViewModel; } - public RoleViewModel? Update(RoleBindingModel model) + public CostItemViewModel? Update(CostItemBindingModel model) { using var context = new Database(); - var component = context.Roles.FirstOrDefault(x => x.ID == model.ID); + var component = context.CostItems.FirstOrDefault(x => x.ID == model.ID); if (component == null) { return null; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/EmployeeStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..a84efcf --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,79 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.StorageContracts; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataBaseImplement.Models; + + +namespace ElectronicsShopDataBaseImplement.Implements +{ + public class EmployeeStorage : IEmployeeStorage + { + public EmployeeViewModel? Delete(EmployeeBindingModel model) + { + using var context = new Database(); + var element = context.Employees.FirstOrDefault(rec => rec.ID == model.ID); + if (element != null) + { + context.Employees.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public EmployeeViewModel? GetElement(EmployeeSearchModel model) + { + if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue) + { + return null; + } + using var context = new Database(); + return context.Employees.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Login) && x.EmployeeFIO == model.EmployeFIO || + (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; + } + + public List GetFilteredList(EmployeeSearchModel model) + { + if (string.IsNullOrEmpty(model.Login)) + { + return new(); + } + using var context = new Database(); + return context.Employees.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new Database(); + return context.Employees.Select(x => x.GetViewModel).ToList(); + } + + public EmployeeViewModel? Insert(EmployeeBindingModel model) + { + var newComponent = Employee.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new Database(); + context.Employees.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public EmployeeViewModel? Update(EmployeeBindingModel model) + { + using var context = new Database(); + var component = context.Employees.FirstOrDefault(x => x.ID == model.ID); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs index 69ced0d..a947f6b 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs @@ -4,12 +4,7 @@ using ElectronicsShopContracts.StorageContracts; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Migrations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ElectronicsShopDataBaseImplement.Implements { @@ -35,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Implements } using var context = new Database(); return context.Orders.FirstOrDefault(x => - (x.DateCreate == model.DateFrom && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; + (model.ID.HasValue && x.ID == model.ID))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) @@ -80,7 +75,7 @@ namespace ElectronicsShopDataBaseImplement.Implements { return null; } - component.Update(model); + component.Update(context ,model); context.SaveChanges(); return component.GetViewModel; } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs deleted file mode 100644 index 3d4bb3a..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs +++ /dev/null @@ -1,57 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataModels; -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Models -{ - public class CategoryProduct : ICategoryProductModel - { - public int ID { get; set; } - - [Required] - public string Name { get; set; } = string.Empty; - - public static CategoryProduct? Create(CategoryProductBindingModel? model) - { - if(model == null) - { - return null; - } - return new CategoryProduct() - { - ID = model.ID, - Name = model.Name - }; - } - public static CategoryProduct? Create(CategoryProductViewModel model) - { - return new CategoryProduct - { - ID = model.ID, - Name = model.Name - }; - } - public void Update(CategoryProductBindingModel model) - { - if(model == null) - { - return; - } - Name = model.Name; - } - - public CategoryProductViewModel GetViewModel => new() - { - ID = ID, - Name = Name - }; - - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs new file mode 100644 index 0000000..beb8278 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs @@ -0,0 +1,60 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopDataBaseImplement.Models +{ + public class Client : IClientModel + { + public int ID { get; set; } + [Required] + public string ClientFIO { get; set; }=string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public string Email { get; set; } = string.Empty; + + + public static Client? Create(ClientBindingModel model) + { + if(model == null) + { + return null; + } + return new Client() + { + ID = model.ID, + ClientFIO = model.ClientFIO, + Password = model.Password, + Email = model.Email + }; + } + + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ID = model.ID; + ClientFIO = model.ClientFIO; + Password = model.Password; + Email = model.Email; + } + public ClientViewModel GetViewModel => new() + { + ID = ID, + ClientFIO = ClientFIO, + Password = Password, + Email = Email + }; + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs new file mode 100644 index 0000000..12b46ad --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs @@ -0,0 +1,59 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopDataBaseImplement.Models +{ + public class CostItem : ICostItemModel + { + public int ID { get; set; } + [ForeignKey("ClientID")] + public int ClientID { get; set; } + [Required] + public string Name { get; set; }= string.Empty; + [Required] + public double Price { get; set; } + + public static CostItem? Create(CostItemBindingModel? model) + { + if (model == null) + { + return null; + } + return new CostItem() + { + ID = model.ID, + ClientID = model.ClientID, + Name = model.Name, + Price = model.Price, + }; + } + public void Update(CostItemBindingModel model) + { + if (model == null) + { + return; + } + ID = model.ID; + ClientID = model.ClientID; + Name = model.Name; + Price = model.Price; + } + + public CostItemViewModel GetViewModel => new() + { + ID = ID, + ClientID = ClientID, + Name = Name, + Price = Price, + }; + + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs new file mode 100644 index 0000000..8b7acfb --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs @@ -0,0 +1,59 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopDataBaseImplement.Models +{ + public class Employee : IEmployeeModel + { + public int ID { get; set; } + [Required] + public string EmployeeFIO { get; set; }=string.Empty; + [Required] + public string Login { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + + public static Employee? Create(EmployeeBindingModel? model) + { + if (model == null) + { + return null; + } + return new Employee() + { + ID = model.ID, + EmployeeFIO = model.EmployeeFIO, + Login = model.Login, + Password = model.Password, + }; + } + public void Update(EmployeeBindingModel model) + { + if (model == null) + { + return; + } + ID = model.ID; + EmployeeFIO = model.EmployeeFIO; + Login = model.Login; + Password = model.Password; + } + + public EmployeeViewModel GetViewModel => new() + { + ID = ID, + EmployeeFIO = EmployeeFIO, + Login = Login, + Password = Password, + }; + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs index 6945815..f67a963 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs @@ -20,15 +20,11 @@ namespace ElectronicsShopDataBaseImplement.Models public double Sum { get; set; } [ForeignKey("ClientID")] public int ClientID { get; set; } - [Required] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Required] - public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно; + [ForeignKey("EmployeeID")] + public int? EmployeeID { get; set; } [Required] public DateTime DateCreate { get; set; } = DateTime.Now; [Required] - public DateTime? DateImplement { get; set; } - [Required] public Dictionary ProductList { get; set; } = new(); [NotMapped] @@ -42,7 +38,7 @@ namespace ElectronicsShopDataBaseImplement.Models } } - public virtual List Products { get; set; } = new(); + public virtual List Products { get; set; } = new(); public static Order? Create(Database context ,OrderBindingModel? model) { @@ -55,17 +51,16 @@ namespace ElectronicsShopDataBaseImplement.Models ID = model.ID, ClientID=model.ClientID, Sum = model.Sum, - Status = model.Status, - PaymeantOption = model.PaymeantOption, + EmployeeID=model.EmployeeID, DateCreate = model.DateCreate, - Products = model.ProductList.Select(x => new OrderProducts + Products = model.ProductList.Select(x => new OrderProduct { _product = context.Products.First(y => y.ID == x.Key), Count = x.Value.Item2 }).ToList() }; } - public void Update(OrderBindingModel model) + public void Update(Database context,OrderBindingModel model) { if (model == null) { @@ -74,13 +69,13 @@ namespace ElectronicsShopDataBaseImplement.Models ID = model.ID; ClientID = model.ClientID; Sum = model.Sum; - PaymeantOption = model.PaymeantOption; - Status = model.Status; + EmployeeID = model.EmployeeID; DateCreate = model.DateCreate; - if (model.DateImplement != null) + Products = model.ProductList.Select(x => new OrderProduct { - DateImplement = model.DateImplement; - } + _product = context.Products.First(y => y.ID == x.Key), + Count = x.Value.Item2 + }).ToList(); //todo ProductList } @@ -89,11 +84,15 @@ namespace ElectronicsShopDataBaseImplement.Models ID = ID, ClientID = ClientID, Sum = Sum, - PaymeantOption = PaymeantOption, - Status = Status, + EmployeeID = EmployeeID, DateCreate = DateCreate, - DateImplement = DateImplement, - ProductList = ProductList + /* + ProductList = ProductList.Select(x => new OrderProducts + { + /_product = context.Products.First(y => y.ID == x.Key) + Count = x.Value.Item2 + }).ToList() + */ }; } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProduct.cs similarity index 90% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProduct.cs index 2365706..a6a1728 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProduct.cs @@ -8,10 +8,9 @@ using System.Threading.Tasks; namespace ElectronicsShopDataBaseImplement.Models { - public class OrderProducts + public class OrderProduct { - public int ID { get; set; } - + public int Id { get; set; } [ForeignKey("OrderID")] public int OrdersID { get; set; } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs index 414403a..a49baa2 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs @@ -1,5 +1,6 @@ using ElectronicsShopContracts.BindingModels; using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Enums; using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; @@ -18,8 +19,9 @@ namespace ElectronicsShopDataBaseImplement.Models public string ProductName { get; set; }=string.Empty; [Required] public double Price { get; set; } - [ForeignKey("CategoryID")] - public int CategoryID { get; set; } + [ForeignKey("CostItemID")] + public int CostItemID { get; set; } + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; public static Product? Create(ProductBindingModel? model) { @@ -32,17 +34,8 @@ namespace ElectronicsShopDataBaseImplement.Models ID = model.ID, ProductName = model.ProductName, Price = model.Price, - CategoryID = model.CategoryID - }; - } - public static Product? Create(ProductViewModel model) - { - return new Product - { - ID = model.ID, - ProductName = model.ProductName, - Price = model.Price, - CategoryID = model.CategoryID + CostItemID=model.CostItemID, + PayOption=model.PayOption }; } public void Update(ProductBindingModel model) @@ -51,9 +44,11 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } + ID = model.ID; ProductName = model.ProductName; Price = model.Price; - CategoryID = model.CategoryID; + CostItemID = model.CostItemID; + PayOption = model.PayOption; } public ProductViewModel GetViewModel => new() @@ -61,7 +56,8 @@ namespace ElectronicsShopDataBaseImplement.Models ID = ID, ProductName = ProductName, Price = Price, - CategoryID = CategoryID + CostItemID = CostItemID, + PayOption = PayOption }; } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Role.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Role.cs deleted file mode 100644 index 6f2e925..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Role.cs +++ /dev/null @@ -1,55 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Models -{ - public class Role : IRoleModel - { - public int ID { get; set; } - - [Required] - public string Name { get; set; } = string.Empty; - - public static Role? Create(RoleBindingModel? model) - { - if (model == null) - { - return null; - } - return new Role() - { - ID = model.ID, - Name = model.Name - }; - } - public static Role? Create(RoleViewModel model) - { - return new Role - { - ID = model.ID, - Name = model.Name - }; - } - public void Update(RoleBindingModel model) - { - if (model == null) - { - return; - } - Name = model.Name; - } - - public RoleViewModel GetViewModel => new() - { - ID = ID, - Name = Name - }; - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs deleted file mode 100644 index 07ab77b..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs +++ /dev/null @@ -1,91 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataModels; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Models -{ - public class User : IUserModel - { - public int ID { get; set; } - [Required] - public string FirstName { get; set; }=string.Empty; - [Required] - public string LastName {get; set; }=string.Empty; - [Required] - public string Password { get; set; } = string.Empty; - [Required] - public string PhoneNumber { get; set; } = string.Empty; - [Required] - public string Login { get; set; } = string.Empty; - [Required] - public string Email { get; set; } = string.Empty; - [ForeignKey("RoleID")] - public int RoleID { get; set; } - - public static User? Create(UserBindingModel model) - { - if(model == null) - { - return null; - } - return new User() - { - ID = model.ID, - FirstName = model.FirstName, - LastName = model.LastName, - Password = model.Password, - PhoneNumber = model.PhoneNumber, - Login = model.Login, - Email = model.Email, - RoleID = model.RoleID - }; - } - public static User Create(ClientViewModel model) - { - return new User - { - ID = model.ID, - FirstName = model.FirstName, - LastName = model.LastName, - Password = model.Password, - PhoneNumber = model.PhoneNumber, - Login = model.Login, - Email = model.Email, - RoleID = model.RoleID - }; - } - - public void Update(UserBindingModel model) - { - if (model == null) - { - return; - } - FirstName = model.FirstName; - LastName = model.LastName; - Password = model.Password; - PhoneNumber = model.PhoneNumber; - Login = model.Login; - Email = model.Email; - RoleID = model.RoleID; - } - public ClientViewModel GetViewModel => new() - { - ID = ID, - FirstName = FirstName, - LastName = LastName, - Password = Password, - PhoneNumber = PhoneNumber, - Login = Login, - Email = Email, - RoleID = RoleID - }; - } -}