Реализовал логику доя товаров
This commit is contained in:
parent
4b21cfb004
commit
abd33d7f49
@ -11,6 +11,6 @@ namespace InternetShopContracts.StorageContracts
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(OrderBindingModel model);
|
||||
ProductViewModel? Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -2,34 +2,91 @@
|
||||
using InternetShopContracts.DataSearchModels;
|
||||
using InternetShopContracts.DataViewModels;
|
||||
using InternetShopContracts.LogicsContracts;
|
||||
using InternetShopContracts.StorageContracts;
|
||||
|
||||
namespace InternetShopLogics.Logics
|
||||
{
|
||||
public class ProductLogic : IProductLogic
|
||||
{
|
||||
private IProductStorage _productStorage;
|
||||
|
||||
public ProductLogic(IProductStorage productStorage)
|
||||
{
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
|
||||
public bool Create(ProductBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_productStorage.Insert(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ProductBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model, false);
|
||||
if (_productStorage.Delete(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
return _productStorage.GetElement(model);
|
||||
}
|
||||
|
||||
public List<ProductViewModel> ReadList(ProductSearchModel? model = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
List<ProductViewModel>? list = null;
|
||||
if (model == null)
|
||||
{
|
||||
list = _productStorage.GetFullList();
|
||||
}
|
||||
else
|
||||
{
|
||||
list = _productStorage.GetFilteredList(model);
|
||||
}
|
||||
if (list == null)
|
||||
{
|
||||
return new List<ProductViewModel>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ProductBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ProductBindingModel model, bool checkParams = true)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
if (!checkParams) return;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия товара", nameof(model.Name));
|
||||
}
|
||||
var item = _productStorage.GetElement(new ProductSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (item != null && item.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Товар с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user