diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs deleted file mode 100644 index 19c6d82..0000000 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CategoryProductLogic.cs +++ /dev/null @@ -1,89 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.BusinessLogicContracts; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.StorageContracts; -using ElectronicsShopContracts.ViewModels; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopBusinessLogic.BusinessLogic -{ - public class CategoryProductLogic : ICategoryProductLogic - { - private readonly ILogger _logger; - private readonly ICategoryProductStorage _storage; - - public CategoryProductLogic(ILogger logger, ICategoryProductStorage storage) { - _logger = logger; - _storage = storage; - } - - public bool Create(CategoryProductBindingModel model) - { - CheckModel(model); - if (_storage.Insert(model) == null) { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool Delete(CategoryProductBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation($"Delete. ID:{model.ID}"); - if (_storage.Delete(model) == null) { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public bool Update(CategoryProductBindingModel model) - { - CheckModel(model); - if (_storage.Update(model) == null) { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - - public List? ReadList(CategoryProductSearchModel? model) - { - _logger.LogInformation($"ReadList. ID:{model?.ID}"); - var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); - if (list == null) { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation($"ReadList. Count:{list.Count}"); - return list; - } - - private void CheckModel(CategoryProductBindingModel model, bool withParams = true) { - if (model == null) { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) { - return; - } - if (string.IsNullOrEmpty(model.Name)) { - throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name)); - } - _logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}"); - - var element = _storage.GetElement(new CategoryProductSearchModel - { - Name = model.Name - }); - if (element != null && element.Name != model.Name) { - throw new InvalidOperationException("Категория с таким названием уже есть"); - } - - } - } -} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs similarity index 66% rename from ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs rename to ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs index 1c8de57..f0f24ba 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/UserLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ClientLogic.cs @@ -12,18 +12,18 @@ using System.Threading.Tasks; namespace ElectronicsShopBusinessLogic.BusinessLogic { - internal class UserLogic : IUserLogic + internal class ClientLogic : IClientLogic { private readonly ILogger _logger; private readonly IClientStorage _storage; - public UserLogic(ILogger logger, IClientStorage storage) + public ClientLogic(ILogger logger, IClientStorage storage) { _logger = logger; _storage = storage; } - public bool Add(UserBindingModel model) + public bool Add(ClientBindingModel model) { CheckModel(model); if (_storage.Insert(model) == null) @@ -34,7 +34,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return true; } - public bool Update(UserBindingModel model) + public bool Update(ClientBindingModel model) { CheckModel(model); if (_storage.Update(model) == null) @@ -45,7 +45,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return true; } - public bool Delete(UserBindingModel model) + public bool Delete(ClientBindingModel model) { CheckModel(model, false); _logger.LogInformation($"Delete.ID:{model.ID}"); @@ -64,7 +64,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}"); + _logger.LogInformation($"ReadElement.Email:{model.Email}.ID:{model.ID}"); var element = _storage.GetElement(model); if (element == null) { @@ -89,7 +89,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return list; } - private void CheckModel(UserBindingModel model, bool withParams = true) + private void CheckModel(ClientBindingModel model, bool withParams = true) { if (model == null) { @@ -99,41 +99,27 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.Login)) - { - throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); - } - if (string.IsNullOrEmpty(model.FirstName)) - { - throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName)); - } - if (string.IsNullOrEmpty(model.LastName)) - { - throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName)); - } if (string.IsNullOrEmpty(model.Email)) { - throw new ArgumentNullException("Нет почты клиента", nameof(model.Email)); + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.ClientFIO)); } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); } - if (string.IsNullOrEmpty(model.PhoneNumber)) - { - throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber)); - } - _logger.LogInformation($"Client. ID:{model.ID}.RoleID:{model.RoleID}.FirstName:{model.FirstName}." + - $"LastName:{model.LastName}.Password:{model.Password}.PhoneNumber:{model.PhoneNumber}.Login:{model.Login}." + - $"Email:{model.Email}"); + _logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.ClientFIO}.Password:{model.Password}.Email:{model.Email}."); var element = _storage.GetElement(new ClientSearchModel { - Login = model.Login + Email= model.Email }); - if (element != null && element.Login != model.Login) + if (element != null && element.Email != model.Email) { - throw new InvalidOperationException("Клиент с таким логином уже есть"); + throw new InvalidOperationException("Клиент с такой почтой уже есть"); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs new file mode 100644 index 0000000..d9d9cca --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs @@ -0,0 +1,102 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.BusinessLogicContracts; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.StorageContracts; +using ElectronicsShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + + +namespace ElectronicsShopBusinessLogic.BusinessLogic +{ + public class CostItemLogic : ICostItemLogic + { + private readonly ILogger _logger; + private readonly ICostItemStorage _storage; + + public bool Create(CostItemBindingModel model) + { + CheckModel(model); + if (_storage.Insert(model) == null) + { + _logger.LogWarning("Add operation failed"); + return false; + } + return true; + } + + public bool Delete(CostItemBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation($"Delete.ID:{model.ID}"); + if (_storage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public CostItemViewModel? ReadElement(CostItemSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation($"ReadElement.Name:{model.Name}.ID:{model.ID}"); + var element = _storage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not fount"); + return null; + } + _logger.LogInformation($"ReadElement.find.ID:{element.ID}"); + return element; + } + + public List? ReadList(CostItemSearchModel model) + { + _logger.LogInformation($"ReadList. ClientID:{model?.ID}"); + var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ; + if (list == null) + { + _logger.LogWarning("ReadList. return null list"); + return null; + } + _logger.LogInformation($"ReadList.Count:{list.Count}"); + return list; + } + + public bool Update(CostItemBindingModel model) + { + CheckModel(model); + if (_storage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(CostItemBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}"); + var element = _storage.GetElement(new CostItemSearchModel { ID = model.ID }); + if (element != null && element.EmployeeID != model.EmployeeID) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } + } +} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs new file mode 100644 index 0000000..a2dfb21 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -0,0 +1,117 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.BusinessLogicContracts; +using ElectronicsShopContracts.SearchModels; +using ElectronicsShopContracts.StorageContracts; +using ElectronicsShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectronicsShopBusinessLogic.BusinessLogic +{ + public class EmployeeLogic : IEmployeeLogic + { + private readonly ILogger _logger; + private readonly IEmployeeStorage _storage; + + public bool Add(EmployeeBindingModel model) + { + CheckModel(model); + if (_storage.Insert(model) == null) + { + _logger.LogWarning("Add operation failed"); + return false; + } + return true; + } + + public bool Delete(EmployeeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation($"Delete.ID:{model.ID}"); + if (_storage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public EmployeeViewModel? ReadElemet(EmployeeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}"); + var element = _storage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not fount"); + return null; + } + _logger.LogInformation($"ReadElement.find.ID:{element.ID}"); + return element; + } + + public List? ReadList(EmployeeSearchModel model) + { + _logger.LogInformation($"ReadList. ClientID:{model?.ID}"); + var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ; + if (list == null) + { + _logger.LogWarning("ReadList. return null list"); + return null; + } + _logger.LogInformation($"ReadList.Count:{list.Count}"); + return list; + } + + public bool Update(EmployeeBindingModel model) + { + CheckModel(model); + if (_storage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(EmployeeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.EmployeeFIO)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.EmployeeFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + _logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.EmployeeFIO}.Password:{model.Password}.Email:{model.Login}."); + + var element = _storage.GetElement(new EmployeeSearchModel + { + Login = model.Login + }); + if (element != null && element.Login != model.Login) + { + throw new InvalidOperationException("Клиент с такой почтой уже есть"); + } + } + } + } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs index a0b818c..cfb20cc 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -25,29 +25,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - model.Status = OrderStatus.Принят; if (_storage.Insert(model) == null) { _logger.LogInformation("Insert operation failed"); return false; } return true; } - - public bool DeliveryOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Выдан); - } - - public bool FinishOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Готов); - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Выполняется); - } - public List? ReadList(OrderSearchModel? model) { _logger.LogInformation($"ReadList:ID:{model?.ID}"); @@ -73,37 +56,21 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic if (model.Sum <= 0) { throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." + - $"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplement}"); - } - private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) - { - CheckModel(model, false); - var viewModel = _storage.GetElement(new OrderSearchModel { ID = model.ID }); - if (viewModel == null) { - throw new ArgumentNullException(nameof(model)); - } - if (viewModel.OrderStatus + 1 != newOrderStatus) { - _logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed."); - return false; - } - model.Status = newOrderStatus; - if (model.Status == OrderStatus.Готов) { - model.DateImplement = DateTime.Now; - } - else { - model.DateImplement = viewModel.DateImplement; - } - if (_storage.Update(model) == null) { - _logger.LogWarning("Update operarion failed"); - return false; - } - return true; + _logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.DateCreate:{model.DateCreate}."); } public OrderViewModel? ReadElement(OrderSearchModel model) { - throw new NotImplementedException(); + if (model == null) throw new ArgumentNullException(nameof(model)); + _logger.LogInformation($"ReadElement. ID:{model.ID}"); + var element = _storage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. elementn not found"); + return null; + } + _logger.LogInformation($"ReadElement find. ID:{element.ID}"); + return element; } } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PayLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PayLogic.cs index bb97fde..5d3ec65 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PayLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PayLogic.cs @@ -15,17 +15,66 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic public bool CreatePay(PaymentBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_storage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public PaymentViewModel? ReadElement(PaymentSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation($"ReadElement.ProductID:{model.ProductID}.ID:{model.ID}"); + var element = _storage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not fount"); + return null; + } + _logger.LogInformation($"ReadElement.find.ID:{element.ID}"); + return element; } - + public List? ReadList(PaymentSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation($"ReadList. ClientID:{model?.ID}"); + /*var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ; + if (list == null) + { + _logger.LogWarning("ReadList. return null list"); + return null; + } + _logger.LogInformation($"ReadList.Count:{list.Count}");*/ + return null; + + } + + private void CheckModel(PaymentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SumPayment <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.SumPayment)); + } + _logger.LogInformation($"Payment. ID:{model.ID}.ProductID:{model.ProductID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}.PayOption{model.PayOption}"); + var element = _storage.GetElement(new PaymentSearchModel { ID = model.ID }); + if (element != null && element.PayOption != model.PayOption) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } } } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs index 6c43a3f..4db2864 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -3,6 +3,7 @@ using ElectronicsShopContracts.BusinessLogicContracts; using ElectronicsShopContracts.SearchModels; using ElectronicsShopContracts.StorageContracts; using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -95,8 +96,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic if (model.Price <= 0) { throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}" + - $".CategoryID:{model.CategoryID}"); + _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.CostItemID:{model.CostItemID}"); var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); if (element != null && element.ProductName != model.ProductName) { throw new InvalidOperationException("Продукт с таким названием уже есть"); diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportLogic.cs deleted file mode 100644 index 5b1c52a..0000000 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportLogic.cs +++ /dev/null @@ -1,38 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.BusinessLogicContracts; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.StorageContracts; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopBusinessLogic.BusinessLogic -{ - public class ReportLogic : IReportLogic - { - private readonly IOrderStorage _orderStorage; - private readonly IProductStorage _productStorag; - - public ReportLogic(IOrderStorage orderStorage, IProductStorage productStorag) { - _orderStorage = orderStorage; - _productStorag = productStorag; - } - - // Получение списка заказов за определенный период - public List GetOrders(ReportBindingModel model) { - return _orderStorage.GetFilteredList(new OrderSearchModel { - DateFrom = model.DateFrom, - DateTo = model.DateTo, - }).Select(x => new ReportOrdersViewModel { - ID = x.ID, - DateCreate = x.DateCreate, - Sum = x.Sum, - PaymeantOption = x.PaymeantOption.ToString(), - OrderStatus = x.Status.ToString(), - }).ToList(); - } - } -} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs deleted file mode 100644 index 0c6b3d4..0000000 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/RoleLogic.cs +++ /dev/null @@ -1,99 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.BusinessLogicContracts; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.StorageContracts; -using ElectronicsShopContracts.ViewModels; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopBusinessLogic.BusinessLogic -{ - public class RoleLogic : IRoleLogic - { - private readonly ILogger _logger; - private readonly IRoleStorage _storage; - - public RoleLogic(ILogger logger, IRoleStorage storage) - { - _logger = logger; - _storage = storage; - } - - public bool Create(RoleBindingModel model) - { - CheckModel(model); - if (_storage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool Delete(RoleBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation($"Delete. ID:{model.ID}"); - if (_storage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public bool Update(RoleBindingModel model) - { - CheckModel(model); - if (_storage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - - public List? ReadList(RoleSearchModel? model) - { - _logger.LogInformation($"ReadList. ID:{model?.ID}"); - var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation($"ReadList. Count:{list.Count}"); - return list; - } - - private void CheckModel(RoleBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.Name)) - { - throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name)); - } - _logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}"); - - var element = _storage.GetElement(new RoleSearchModel - { - Name = model.Name - }); - if (element != null && element.Name != model.Name) - { - throw new InvalidOperationException("Такая роль уже есть"); - } - - } - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs index 898f7d1..44b4d45 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/CostItemBindingModel.cs @@ -9,7 +9,7 @@ namespace ElectronicsShopContracts.BindingModels { public class CostItemBindingModel : ICostItemModel { public int ID { get; set; } - public int ClientID { get; set; } + public int EmployeeID { get; set; } public string Name { get; set; } = string.Empty; diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/PaymentBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/PaymentBindingModel.cs index 4868155..f53a7a7 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/PaymentBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/PaymentBindingModel.cs @@ -1,4 +1,5 @@ -using ElectronicsShopDataModels.Models; +using ElectronicsShopDataModels.Enums; +using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -9,14 +10,14 @@ namespace ElectronicsShopContracts.BindingModels { public class PaymentBindingModel : IPaymentModel { - public int ID { get; set; } + public int ID { get; set; } - public int ClientID { get; set; } + public int ProductID { get; set; } - public int ProductID { get; set; } + public int OrderID { get; set; } - public int OrderID { get; set; } + public double SumPayment { get; set; } - public double SumPayment { get; set; } + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; } } diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs index 856ef93..8dfd607 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ProductBindingModel.cs @@ -16,7 +16,5 @@ namespace ElectronicsShopContracts.BindingModels public string ProductName { get; set; } = string.Empty; public double Price { get; set; } - - public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; } } diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs index e3ac8da..b180421 100644 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs +++ b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IEmployeeStorage.cs @@ -18,5 +18,6 @@ namespace ElectronicsShopContracts.StorageContracts EmployeeViewModel? Insert(EmployeeBindingModel model); EmployeeViewModel? Update(EmployeeBindingModel model); EmployeeViewModel? Delete(EmployeeBindingModel model); + object GetElement(CostItemSearchModel costItemSearchModel); } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs index 20f6f4a..b8b52d7 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/CostItemViewModel.cs @@ -11,7 +11,7 @@ namespace ElectronicsShopContracts.ViewModels { public class CostItemViewModel : ICostItemModel { public int ID { get; set; } - public int ClientID { get; set; } + public int EmployeeID { get; set; } [DisplayName("Название статьи затрат")] public string Name { get; set; } = string.Empty; diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/PaymentViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/PaymentViewModel.cs index a57c66e..a1c0a06 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/PaymentViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/PaymentViewModel.cs @@ -1,4 +1,5 @@ -using ElectronicsShopDataModels.Models; +using ElectronicsShopDataModels.Enums; +using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -17,5 +18,8 @@ namespace ElectronicsShopContracts.ViewModels [DisplayName("Cумма оплаты продукта")] public double SumPayment { get; set; } - } + + [DisplayName("Статус оплаты")] + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; + } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs index f1d96cb..7ce3836 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ProductViewModel.cs @@ -20,7 +20,5 @@ namespace ElectronicsShopContracts.ViewModels [DisplayName("Стоимость продукта")] public double Price { get; set; } - [DisplayName("Статус оплаты")] - public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs index beb8278..dde2ea6 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs @@ -44,7 +44,6 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } - ID = model.ID; ClientFIO = model.ClientFIO; Password = model.Password; Email = model.Email; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs index 12b46ad..a17cfbf 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs @@ -15,7 +15,7 @@ namespace ElectronicsShopDataBaseImplement.Models { public int ID { get; set; } [ForeignKey("ClientID")] - public int ClientID { get; set; } + public int EmployeeID { get; set; } [Required] public string Name { get; set; }= string.Empty; [Required] @@ -30,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Models return new CostItem() { ID = model.ID, - ClientID = model.ClientID, + EmployeeID = model.EmployeeID, Name = model.Name, Price = model.Price, }; @@ -41,8 +41,7 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } - ID = model.ID; - ClientID = model.ClientID; + EmployeeID = model.EmployeeID; Name = model.Name; Price = model.Price; } @@ -50,7 +49,7 @@ namespace ElectronicsShopDataBaseImplement.Models public CostItemViewModel GetViewModel => new() { ID = ID, - ClientID = ClientID, + EmployeeID = EmployeeID, Name = Name, Price = Price, }; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs index 8b7acfb..a153476 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Employee.cs @@ -42,7 +42,6 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } - ID = model.ID; EmployeeFIO = model.EmployeeFIO; Login = model.Login; Password = model.Password; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs index f67a963..bb09d94 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs @@ -66,7 +66,6 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } - ID = model.ID; ClientID = model.ClientID; Sum = model.Sum; EmployeeID = model.EmployeeID; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Payment.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Payment.cs new file mode 100644 index 0000000..f8acdd6 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Payment.cs @@ -0,0 +1,64 @@ +using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Enums; +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 Payment : IPaymentModel + { + public int ID { get; set; } + [ForeignKey("ProductID")] + public int ProductID { get; set; } + [ForeignKey("OrderID")] + public int OrderID { get; set; } + [Required] + public double SumPayment { get; set; } + [Required] + public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; + public static Payment? Create(PaymentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Payment() + { + ID = model.ID, + ProductID = model.ProductID, + OrderID = model.OrderID, + SumPayment = model.SumPayment, + PayOption = model.PayOption, + }; + } + public void Update(PaymentBindingModel model) + { + if (model == null) + { + return; + } + ProductID = model.ProductID; + OrderID = model.OrderID; + SumPayment = model.SumPayment; + PayOption = model.PayOption; + } + + public PaymentViewModel GetViewModel => new() + { + ID = ID, + ProductID = ProductID, + OrderID = OrderID, + SumPayment = SumPayment, + PayOption = PayOption, + }; + + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs index a49baa2..94c9ac0 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs @@ -21,7 +21,6 @@ namespace ElectronicsShopDataBaseImplement.Models public double Price { get; set; } [ForeignKey("CostItemID")] public int CostItemID { get; set; } - public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно; public static Product? Create(ProductBindingModel? model) { @@ -35,7 +34,6 @@ namespace ElectronicsShopDataBaseImplement.Models ProductName = model.ProductName, Price = model.Price, CostItemID=model.CostItemID, - PayOption=model.PayOption }; } public void Update(ProductBindingModel model) @@ -44,11 +42,9 @@ namespace ElectronicsShopDataBaseImplement.Models { return; } - ID = model.ID; ProductName = model.ProductName; Price = model.Price; CostItemID = model.CostItemID; - PayOption = model.PayOption; } public ProductViewModel GetViewModel => new() @@ -57,7 +53,6 @@ namespace ElectronicsShopDataBaseImplement.Models ProductName = ProductName, Price = Price, CostItemID = CostItemID, - PayOption = PayOption }; } } diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs index a1ca2c7..5591102 100644 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs +++ b/ElectronicsShop/ElectronicsShopDataModels/Models/ICostItemModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ElectronicsShopDataModels.Models { public interface ICostItemModel : IID{ - int ClientID { get; } + int EmployeeID { get; } string Name { get; } double Price { get; } } diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/IPaymentModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/IPaymentModel.cs index b10d91e..6d11c0f 100644 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/IPaymentModel.cs +++ b/ElectronicsShop/ElectronicsShopDataModels/Models/IPaymentModel.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualBasic; +using ElectronicsShopDataModels.Enums; +using Microsoft.VisualBasic; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +13,7 @@ namespace ElectronicsShopDataModels.Models int ProductID { get; } int OrderID { get; } double SumPayment { get; } + PaymeantOption PayOption { get; } } } diff --git a/ElectronicsShop/ElectronicsShopDataModels/Models/IProductModel.cs b/ElectronicsShop/ElectronicsShopDataModels/Models/IProductModel.cs index c441eb8..fdff174 100644 --- a/ElectronicsShop/ElectronicsShopDataModels/Models/IProductModel.cs +++ b/ElectronicsShop/ElectronicsShopDataModels/Models/IProductModel.cs @@ -12,6 +12,6 @@ namespace ElectronicsShopDataModels.Models string ProductName { get; } double Price { get; } int CostItemID { get; } - PaymeantOption PayOption { get; } + } }