Реализовал логику для заказов
This commit is contained in:
parent
3136067777
commit
4b21cfb004
@ -1,4 +1,5 @@
|
||||
using InternetShopContracts.DataSearchModels;
|
||||
using InternetShopContracts.DataBindingModels;
|
||||
using InternetShopContracts.DataSearchModels;
|
||||
using InternetShopContracts.DataViewModels;
|
||||
|
||||
namespace InternetShopContracts.StorageContracts
|
||||
@ -8,8 +9,8 @@ namespace InternetShopContracts.StorageContracts
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderSearchModel model);
|
||||
OrderViewModel? Update(OrderSearchModel model);
|
||||
OrderViewModel? Delete(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using InternetShopContracts.DataSearchModels;
|
||||
using InternetShopContracts.DataBindingModels;
|
||||
using InternetShopContracts.DataSearchModels;
|
||||
using InternetShopContracts.DataViewModels;
|
||||
|
||||
namespace InternetShopContracts.StorageContracts
|
||||
@ -8,8 +9,8 @@ namespace InternetShopContracts.StorageContracts
|
||||
List<ProductViewModel> GetFullList();
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductSearchModel model);
|
||||
ProductViewModel? Update(ProductSearchModel model);
|
||||
ProductViewModel? Delete(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -17,27 +17,85 @@ namespace InternetShopLogics.Logics
|
||||
|
||||
public bool Create(OrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(OrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
return _orderStorage.GetElement(model);
|
||||
}
|
||||
|
||||
public List<OrderViewModel> ReadList(OrderSearchModel? model = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
List<OrderViewModel>? list = null;
|
||||
if (model == null)
|
||||
{
|
||||
list = _orderStorage.GetFullList();
|
||||
}
|
||||
else
|
||||
{
|
||||
list = _orderStorage.GetFilteredList(model);
|
||||
}
|
||||
if (list == null)
|
||||
{
|
||||
return new List<OrderViewModel>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(OrderBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool checkParams = true)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
if (!checkParams) return;
|
||||
if (string.IsNullOrEmpty(model.CustomerFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фио заказчика", nameof(model.CustomerFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.CustomerEmail))
|
||||
{
|
||||
throw new ArgumentNullException("Нет email заказчика", nameof(model.CustomerEmail));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ImagePath))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фото заказа", nameof(model.ImagePath));
|
||||
}
|
||||
if (model.ProductNames == null)
|
||||
{
|
||||
throw new ArgumentNullException("Список товаров не инициализирован", nameof(model.ProductNames));
|
||||
}
|
||||
else if (model.ProductNames.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Список товаров пуст", nameof(model.ProductNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user