diff --git a/ElectronicsShop/ElectronicsShop.sln b/ElectronicsShop/ElectronicsShop.sln index 36142e6..46ecf12 100644 --- a/ElectronicsShop/ElectronicsShop.sln +++ b/ElectronicsShop/ElectronicsShop.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronicsShopContracts", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopBusinessLogic", "ElectronicsShopBusinessLogic\ElectronicsShopBusinessLogic.csproj", "{0CCDB712-EE03-4050-AC4B-4315FF14ABD2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronicsShopDataBaseImplement", "ElectronicsShopDataBaseImplement\ElectronicsShopDataBaseImplement.csproj", "{03442D38-4C09-49D1-85F3-F8F563072F9B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {0CCDB712-EE03-4050-AC4B-4315FF14ABD2}.Release|Any CPU.Build.0 = Release|Any CPU + {03442D38-4C09-49D1-85F3-F8F563072F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03442D38-4C09-49D1-85F3-F8F563072F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03442D38-4C09-49D1-85F3-F8F563072F9B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs index 8798048..e009c5d 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs @@ -13,7 +13,7 @@ using System.Threading.Tasks; namespace ElectronicsShopBusinessLogic.BusinessLogic { - public class ClientLogic : IClientLogic + public class ClientLogic : IUserLogic { private readonly ILogger _logger; //private readonly IClientStorage _storage; @@ -24,7 +24,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic //storage = _storage; } - public bool Add(ClientBindingModel model) + public bool Add(UserBindingModel model) { CheckModel(model); // todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null @@ -35,7 +35,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return true; } - public bool Update(ClientBindingModel model) + public bool Update(UserBindingModel model) { CheckModel(model); // todo логика добавления в _clientStorage:_clientStorage.Update(model) == null @@ -47,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return true; } - public bool Delete(ClientBindingModel model) + public bool Delete(UserBindingModel model) { CheckModel(model, false); _logger.LogInformation($"Delete.ID:{model.UserID}"); @@ -60,7 +60,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic } - public ClientViewModel? ReadElemet(ClientSearchModel? model) + public UserViewModel? ReadElemet(UserSearchModel? model) { if (model == null) { throw new ArgumentNullException(nameof(model)); @@ -77,7 +77,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return null; } - public List? ReadList(ClientSearchModel? model) + public List? ReadList(UserSearchModel? model) { _logger.LogInformation($"ReadList: ClientID:{model?.UserID}"); @@ -93,7 +93,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return null; } - private void CheckModel(ClientBindingModel model, bool withParams = true) { + private void CheckModel(UserBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ShopAssistentBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ShopAssistentBindingModel.cs deleted file mode 100644 index dc90e28..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ShopAssistentBindingModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.BindingModels -{ - public class ShopAssistentBindingModel : IShopAssistentModel - { - //ID пользователя - public int UserID { get; set; } - //ID роли (сотрудник) - public int RoleID { get; set; } - - - public string FirstName { get; set; } = string.Empty; - - public string LastName { get; set; } = string.Empty; - - public string Login { get; set; } = string.Empty; - - public string Email { get; set; } = string.Empty; - - public string Password { get; set; } = string.Empty; - - public string PhoneNumber { get; set; } = string.Empty; - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ClientBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/UserBindingModel.cs similarity index 80% rename from ElectronicsShop/ElectronicsShopContracts/BindingModels/ClientBindingModel.cs rename to ElectronicsShop/ElectronicsShopContracts/BindingModels/UserBindingModel.cs index eaeea40..dabd5fa 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ClientBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/UserBindingModel.cs @@ -1,4 +1,5 @@ -using ElectronicsShopDataModels.Models; +using ElectronicsShopDataModels; +using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -7,10 +8,10 @@ using System.Threading.Tasks; namespace ElectronicsShopContracts.BindingModels { - public class ClientBindingModel : IClientModel + public class UserBindingModel : IUserModel { //ID пользователя - public int UserID { get; set; } + public int ID { get; set; } //ID роли (клиент) public int RoleID { get; set; } diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IClientLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IUserLogic.cs similarity index 52% rename from ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IClientLogic.cs rename to ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IUserLogic.cs index 10c577d..a735e43 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IUserLogic.cs @@ -9,13 +9,13 @@ using System.Threading.Tasks; namespace ElectronicsShopContracts.BusinessLogicContracts { - public interface IClientLogic + public interface IUserLogic { - List? ReadList(ClientSearchModel? model); - ClientViewModel? ReadElemet(ClientSearchModel? model); + List? ReadList(UserSearchModel? model); + UserViewModel? ReadElemet(UserSearchModel? model); - bool Add(ClientBindingModel model); - bool Update(ClientBindingModel model); - bool Delete(ClientBindingModel model); + bool Add(UserBindingModel model); + bool Update(UserBindingModel model); + bool Delete(UserBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/ShopAssistentLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/ShopAssistentLogic.cs deleted file mode 100644 index 0be1eb6..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/ShopAssistentLogic.cs +++ /dev/null @@ -1,21 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.BusinessLogicContracts -{ - public interface ShopAssistentLogic - { - List? ReadList(ShopAssistentSearchModel? model); - ShopAssistentViewModel? ReadElement(ShopAssistentSearchModel? model); - - bool Add(ShopAssistentBindingModel model); - bool Update(ShopAssistentBindingModel model); - bool Delete(ShopAssistentBindingModel model); - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs deleted file mode 100644 index 9c495e9..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ShopAssistentSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.SearchModels -{ - public class ShopAssistentSearchModel - { - public int? UserID { get; set; } - public string? Login { get; set; } - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/UserSearchModel.cs similarity index 74% rename from ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs rename to ElectronicsShop/ElectronicsShopContracts/SearchModels/UserSearchModel.cs index 206e3fd..32708e8 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/ClientSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/UserSearchModel.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace ElectronicsShopContracts.SearchModels { - public class ClientSearchModel + public class UserSearchModel { - public int? UserID { get; set; } + public int? ID { get; set; } public string? Login { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICategoryProductStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICategoryProductStorage.cs index 4bd0241..b8e3c1b 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICategoryProductStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/ICategoryProductStorage.cs @@ -12,10 +12,10 @@ namespace ElectronicsShopContracts.StorageContracts public interface ICategoryProductStorage { List GetFullList(); - List GetFilteredList(ClientSearchModel model); - CategoryProductViewModel? GetElement(ClientSearchModel model); - CategoryProductViewModel? Insert(ClientBindingModel model); - CategoryProductViewModel? Update(ClientBindingModel model); - CategoryProductViewModel? Delete(ClientBindingModel model); + List GetFilteredList(CategoryProductSearchModel model); + CategoryProductViewModel? GetElement(CategoryProductSearchModel model); + CategoryProductViewModel? Insert(CategoryProductBindingModel model); + CategoryProductViewModel? Update(CategoryProductBindingModel model); + CategoryProductViewModel? Delete(CategoryProductBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IClientStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IClientStorage.cs deleted file mode 100644 index e890ea4..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IClientStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.StorageContracts -{ - public interface IClientStorage - { - List GetFullList(); - List GetFilteredList(ClientSearchModel model); - ClientViewModel? GetElement(ClientSearchModel model); - ClientViewModel? Insert(ClientBindingModel model); - ClientViewModel? Update(ClientBindingModel model); - ClientViewModel? Delete(ClientBindingModel model); - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IOrderStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IOrderStorage.cs index 0f4b0cd..e4223fa 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IOrderStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IOrderStorage.cs @@ -12,10 +12,10 @@ namespace ElectronicsShopContracts.StorageContracts public interface IOrderStorage { List GetFullList(); - List GetFilteredList(ClientSearchModel model); - OrderViewModel? GetElement(ClientSearchModel model); - OrderViewModel? Insert(ClientBindingModel model); - OrderViewModel? Update(ClientBindingModel model); - OrderViewModel? Delete(ClientBindingModel model); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IProductStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IProductStorage.cs index cef81a4..3616e74 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IProductStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IProductStorage.cs @@ -12,10 +12,10 @@ namespace ElectronicsShopContracts.StorageContracts public interface IProductStorage { List GetFullList(); - List GetFilteredList(ClientSearchModel model); - ProductViewModel? GetElement(ClientSearchModel model); - ProductViewModel? Insert(ClientBindingModel model); - ProductViewModel? Update(ClientBindingModel model); - ProductViewModel? Delete(ClientBindingModel model); + List GetFilteredList(OrderSearchModel model); + ProductViewModel? GetElement(OrderSearchModel model); + ProductViewModel? Insert(OrderBindingModel model); + ProductViewModel? Update(OrderBindingModel model); + ProductViewModel? Delete(OrderBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IRoleStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IRoleStorage.cs index fad07f8..7785eb4 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IRoleStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IRoleStorage.cs @@ -12,10 +12,10 @@ namespace ElectronicsShopContracts.StorageContracts public interface IRoleStorage { List GetFullList(); - List GetFilteredList(ClientSearchModel model); - RoleViewModel? GetElement(ClientSearchModel model); - RoleViewModel? Insert(ClientBindingModel model); - RoleViewModel? Update(ClientBindingModel model); - RoleViewModel? Delete(ClientBindingModel model); + List GetFilteredList(RoleSearchModel model); + RoleViewModel? GetElement(RoleSearchModel model); + RoleViewModel? Insert(RoleBindingModel model); + RoleViewModel? Update(RoleBindingModel model); + RoleViewModel? Delete(RoleBindingModel model); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IShopAssistentStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IShopAssistentStorage.cs deleted file mode 100644 index e0f4416..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IShopAssistentStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.StorageContracts -{ - public interface IShopAssistentStorage - { - List GetFullList(); - List GetFilteredList(ClientSearchModel model); - ShopAssistentViewModel? GetElement(ClientSearchModel model); - ShopAssistentViewModel? Insert(ClientBindingModel model); - ShopAssistentViewModel? Update(ClientBindingModel model); - ShopAssistentViewModel? Delete(ClientBindingModel model); - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IUserStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IUserStorage.cs new file mode 100644 index 0000000..4161916 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IUserStorage.cs @@ -0,0 +1,21 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopContracts.StorageContracts +{ + public interface IUserStorage + { + List GetFullList(); + List GetFilteredList(UserSearchModel model); + UserViewModel? GetElement(UserSearchModel model); + UserViewModel? Insert(UserBindingModel model); + UserViewModel? Update(UserBindingModel model); + UserViewModel? Delete(UserBindingModel model); + } +} diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ShopAssistentViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ShopAssistentViewModel.cs deleted file mode 100644 index 64f2514..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ShopAssistentViewModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.ViewModels -{ - public class ShopAssistentViewModel : IShopAssistentModel - { - //ID пользователя - public int UserID { get; set; } - //ID роли (сотрудник) - public int RoleID { get; set; } - - - [DisplayName("Имя")] - public string FirstName { get; set; } = string.Empty; - - [DisplayName("Фамилия")] - public string LastName { get; set; } = string.Empty; - - [DisplayName("Логин")] - public string Login { get; set; } = string.Empty; - - [DisplayName("Почта")] - public string Email { get; set; } = string.Empty; - - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - - [DisplayName("Номер телефона")] - public string PhoneNumber { get; set; } = string.Empty; - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ClientViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/UserViewModel.cs similarity index 85% rename from ElectronicsShop/ElectronicsShopContracts/ViewModels/ClientViewModel.cs rename to ElectronicsShop/ElectronicsShopContracts/ViewModels/UserViewModel.cs index ab82e13..366c955 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ClientViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/UserViewModel.cs @@ -1,4 +1,5 @@ -using ElectronicsShopDataModels.Models; +using ElectronicsShopDataModels; +using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,15 +9,14 @@ using System.Threading.Tasks; namespace ElectronicsShopContracts.ViewModels { - public class ClientViewModel : IClientModel + public class UserViewModel : IUserModel { //ID пользователя - public int UserID { get; set; } + public int ID { get; set; } //ID роли (клиент) public int RoleID { get; set; } - [DisplayName("Имя")] public string FirstName { get; set; } = string.Empty; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs new file mode 100644 index 0000000..7e3bb96 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; + +namespace ElectronicsShopDataBaseImplement +{ + public class DataBase + { + public class Database : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder + optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=ZooDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet CategoryProducts { set; get; } + public virtual DbSet Users { set; get; } + public virtual DbSet Routes { set; get; } + public virtual DbSet RoutePreserves { set; get; } + public virtual DbSet Preserves { set; get; } + + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/ElectronicsShopDataBaseImplement.csproj b/ElectronicsShop/ElectronicsShopDataBaseImplement/ElectronicsShopDataBaseImplement.csproj new file mode 100644 index 0000000..ae965cf --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/ElectronicsShopDataBaseImplement.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs new file mode 100644 index 0000000..c8604d4 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/CategoryProductStorage.cs @@ -0,0 +1,63 @@ +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; +using static ElectronicsShopDataBaseImplement.DataBase; + +namespace ElectronicsShopDataBaseImplement.Implements +{ + public class CategoryProductStorage : ICategoryProductStorage + { + List ICategoryProductStorage.GetFullList() + { + using var context = new Database(); + return context.CategoryProducts.Select(x => x.GetViewModel).ToList(); + } + List ICategoryProductStorage.GetFilteredList(CategoryProductSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + using var context = new Database(); + return context.CategoryProducts.Where(x => x.CategoryProducts.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + } + CategoryProductViewModel? ICategoryProductStorage.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; + } + CategoryProductViewModel? ICategoryProductStorage.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; + } + + CategoryProductViewModel? ICategoryProductStorage.Update(CategoryProductBindingModel model) + { + throw new NotImplementedException(); + } + CategoryProductViewModel? ICategoryProductStorage.Delete(CategoryProductBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs new file mode 100644 index 0000000..66be802 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CategoryProduct.cs @@ -0,0 +1,58 @@ +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; private 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; + } + model.ID = ID; + model.Name = Name; + } + + public CategoryProduct GetViewModel => new() + { + ID = ID, + Name = Name + }; + + } +} diff --git a/ElectronicsShop/ElectronicsShopDataModels/IUser.cs b/ElectronicsShop/ElectronicsShopDataModels/IUserModel.cs similarity index 87% rename from ElectronicsShop/ElectronicsShopDataModels/IUser.cs rename to ElectronicsShop/ElectronicsShopDataModels/IUserModel.cs index c717d8f..ae58001 100644 --- a/ElectronicsShop/ElectronicsShopDataModels/IUser.cs +++ b/ElectronicsShop/ElectronicsShopDataModels/IUserModel.cs @@ -6,14 +6,17 @@ using System.Threading.Tasks; namespace ElectronicsShopDataModels { - public interface IUser + public interface IUserModel : IID { + //ID role + int RoleID { get; } + + string FirstName { get; } string LastName { get; } - string Login { get; } - string Email { get; } string Password { get; } string PhoneNumber { get; } - int RoleID { get; } + string Login { get; } + string Email { get; } } } diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/IClientModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/IClientModel.cs deleted file mode 100644 index bf06926..0000000 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/IClientModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataModels.Models -{ - public interface IClientModel : IUser - { - int UserID { get; } - } -} diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/IShopAssistentModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/IShopAssistentModel.cs deleted file mode 100644 index bbdbf9d..0000000 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/IShopAssistentModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataModels.Models -{ - public interface IShopAssistentModel : IUser - { - int UserID { get; } - } -}