Business logic 0.2
This commit is contained in:
parent
02d78da38f
commit
134f7d6cef
@ -1,6 +1,7 @@
|
|||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||||
using ElectronicsShopContracts.SearchModels;
|
using ElectronicsShopContracts.SearchModels;
|
||||||
|
using ElectronicsShopContracts.StorageContracts;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
@ -14,18 +15,17 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public class CategoryProductLogic : ICategoryProductLogic
|
public class CategoryProductLogic : ICategoryProductLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//private readonly ICategoryProductStorage _storage;
|
private readonly ICategoryProductStorage _storage;
|
||||||
|
|
||||||
// todo нет интерфейса хранилища
|
public CategoryProductLogic(ILogger<CategoryProductLogic> logger, ICategoryProductStorage storage) {
|
||||||
public CategoryProductLogic(ILogger<CategoryProductLogic> logger) {
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(CategoryProductBindingModel model)
|
public bool Create(CategoryProductBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null) {
|
||||||
if (model == null) {
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -36,8 +36,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
_logger.LogInformation($"Delete. ID:{model.ID}");
|
_logger.LogInformation($"Delete. ID:{model.ID}");
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null) {
|
||||||
if (model == null) {
|
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -46,8 +45,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public bool Update(CategoryProductBindingModel model)
|
public bool Update(CategoryProductBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null) {
|
||||||
if (model == null) {
|
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -57,16 +55,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model)
|
public List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
||||||
// todo model == null _CategoryProductStorage.GetFullList() : _CategoryProductStorage.GetFilteredList(model);
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||||
var list = model;
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// todo $"ReadList. Count:{list.count}"
|
_logger.LogInformation($"ReadList. Count:{list.Count}");
|
||||||
_logger.LogInformation("ReadList. Count:{Count}");
|
return list;
|
||||||
// todo return list;
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(CategoryProductBindingModel model, bool withParams = true) {
|
private void CheckModel(CategoryProductBindingModel model, bool withParams = true) {
|
||||||
@ -79,17 +74,16 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
if (string.IsNullOrEmpty(model.Name)) {
|
if (string.IsNullOrEmpty(model.Name)) {
|
||||||
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
|
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"CategoryProduct. Name:{model.Name}");
|
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
|
||||||
/*
|
|
||||||
var element = _ CategoryProductStorage.GetElement(new CategoryProductSearchModel
|
var element = _storage.GetElement(new CategoryProductSearchModel
|
||||||
{
|
{
|
||||||
Name = model.Name
|
Name = model.Name
|
||||||
});
|
});
|
||||||
if (element != null && element.Id != model.ID)
|
if (element != null && element.ID != model.ID) {
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Категория с таким названием уже есть");
|
throw new InvalidOperationException("Категория с таким названием уже есть");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,19 +16,17 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public class OrderLogic : IOrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//private readonly IOrderStorage _storage;
|
private readonly IOrderStorage _storage;
|
||||||
|
|
||||||
// todo нет интерфейса хранилища
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage storage) {
|
||||||
public OrderLogic(ILogger<OrderLogic> logger) {
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
//storage = _storage;
|
_storage = storage;
|
||||||
}
|
}
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
// todo _orderStorage.Insert(model) == null
|
if (_storage.Insert(model) == null) {
|
||||||
if (model == null) {
|
|
||||||
_logger.LogInformation("Insert operation failed");
|
_logger.LogInformation("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -53,16 +51,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"ReadList:ID:{model?.ID}");
|
_logger.LogInformation($"ReadList:ID:{model?.ID}");
|
||||||
// todo model == null? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
|
||||||
var list = model;
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// todo "$ReadList.Count:{list.count}"
|
_logger.LogInformation($"ReadList.Count:{list.Count}");
|
||||||
_logger.LogInformation("ReadList.Count:{Count}");
|
return list;
|
||||||
//todo return list
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true) {
|
private void CheckModel(OrderBindingModel model, bool withParams = true) {
|
||||||
@ -79,37 +74,27 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." +
|
_logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." +
|
||||||
$"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplemet}");
|
$"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplement}");
|
||||||
}
|
}
|
||||||
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
|
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
//todo
|
var viewModel = _storage.GetElement(new OrderSearchModel { ID = model.ID });
|
||||||
var viewModel = model; // model == _orderStorage.GetElement(new OrderSearchModel { ID = model.ID });
|
if (viewModel == null) {
|
||||||
if (viewModel == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
if (viewModel.Status + 1 != newOrderStatus)
|
if (viewModel.Status + 1 != newOrderStatus) {
|
||||||
{
|
|
||||||
_logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed.");
|
_logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newOrderStatus;
|
model.Status = newOrderStatus;
|
||||||
if (model.Status == OrderStatus.Готов)
|
if (model.Status == OrderStatus.Готов) {
|
||||||
{
|
model.DateImplement = DateTime.Now;
|
||||||
//todo подключить бд
|
|
||||||
//model.DateImplement = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
model.DateImplement = viewModel.DateImplement;
|
||||||
// todo подключить бд
|
|
||||||
//model.DateImplement = viewModel.DateImplement;
|
|
||||||
}
|
}
|
||||||
// todo
|
if (_storage.Update(model) == null) {
|
||||||
// _orderStorage.Update(model) == null
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operarion failed");
|
_logger.LogWarning("Update operarion failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
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 ProductLogic : IProductLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IProductStorage _storage;
|
||||||
|
|
||||||
|
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage productStorage) {
|
||||||
|
_logger = logger;
|
||||||
|
_storage = productStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_storage.Insert(model) == null) {
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ProductBindingModel 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(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_storage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? ReadElement(ProductSearchModel? model)
|
||||||
|
{
|
||||||
|
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||||
|
_logger.LogInformation($"ReadElement. ProductName:{model.ProductName}. 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"ReadList. ProductName:{model?.ProductName}. 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(ProductBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||||
|
if (!withParams) return;
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName))
|
||||||
|
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
|
||||||
|
if (model.Price <= 0)
|
||||||
|
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
||||||
|
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.Count:{model.Count}" +
|
||||||
|
$".CategoryID:{model.CategoryID}");
|
||||||
|
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
|
||||||
|
if (element != null && element.ID != model.ID)
|
||||||
|
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||||
using ElectronicsShopContracts.SearchModels;
|
using ElectronicsShopContracts.SearchModels;
|
||||||
|
using ElectronicsShopContracts.StorageContracts;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
@ -14,19 +15,18 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public class RoleLogic : IRoleLogic
|
public class RoleLogic : IRoleLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//private readonly ICategoryProductStorage _storage;
|
private readonly IRoleStorage _storage;
|
||||||
|
|
||||||
// todo нет интерфейса хранилища
|
public RoleLogic(ILogger<RoleLogic> logger, IRoleStorage storage)
|
||||||
public RoleLogic(ILogger<RoleLogic> logger)
|
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(RoleBindingModel model)
|
public bool Create(RoleBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -38,8 +38,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
_logger.LogInformation($"Delete. ID:{model.ID}");
|
_logger.LogInformation($"Delete. ID:{model.ID}");
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -49,8 +48,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public bool Update(RoleBindingModel model)
|
public bool Update(RoleBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo _storage.Insert(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -61,17 +59,14 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
||||||
// todo model == null _RoleStorage.GetFullList() : _RoleStorage.GetFilteredList(model);
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||||
var list = model;
|
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// todo $"ReadList. Count:{list.count}"
|
_logger.LogInformation($"ReadList. Count:{list.Count}");
|
||||||
_logger.LogInformation("ReadList. Count:{Count}");
|
return list;
|
||||||
// todo return list;
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(RoleBindingModel model, bool withParams = true)
|
private void CheckModel(RoleBindingModel model, bool withParams = true)
|
||||||
@ -88,17 +83,17 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
|
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"CategoryProduct. Name:{model.Name}");
|
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
|
||||||
/*
|
|
||||||
var element = _RoleStorage.GetElement(new RoleSearchModel
|
var element = _storage.GetElement(new RoleSearchModel
|
||||||
{
|
{
|
||||||
Name = model.Name
|
Name = model.Name
|
||||||
});
|
});
|
||||||
if (element != null && element.Id != model.ID)
|
if (element != null && element.ID != model.ID)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Такая роль уже есть");
|
throw new InvalidOperationException("Такая роль уже есть");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||||
using ElectronicsShopContracts.SearchModels;
|
using ElectronicsShopContracts.SearchModels;
|
||||||
|
using ElectronicsShopContracts.StorageContracts;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
@ -14,20 +15,19 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
internal class UserLogic : IUserLogic
|
internal class UserLogic : IUserLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//private readonly IClientStorage _storage;
|
private readonly IUserStorage _storage;
|
||||||
|
|
||||||
// todo нет интерфейса хранилища
|
// todo нет интерфейса хранилища
|
||||||
public UserLogic(ILogger<UserLogic> logger)
|
public UserLogic(ILogger<UserLogic> logger, IUserStorage storage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
//storage = _storage;
|
_storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Add(UserBindingModel model)
|
public bool Add(UserBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo логика добавления в _clientStorage:_clientStorage.Insert(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Add operation failed");
|
_logger.LogWarning("Add operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -38,8 +38,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public bool Update(UserBindingModel model)
|
public bool Update(UserBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
// todo логика добавления в _clientStorage:_clientStorage.Update(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -51,8 +50,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
_logger.LogInformation($"Delete.ID:{model.ID}");
|
_logger.LogInformation($"Delete.ID:{model.ID}");
|
||||||
// todo логика добавления в _clientStorage:_clientStorage.Delete(model) == null
|
if (_storage.Insert(model) == null)
|
||||||
if (model == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failes");
|
_logger.LogWarning("Delete operation failes");
|
||||||
return false;
|
return false;
|
||||||
@ -68,33 +66,28 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}");
|
_logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}");
|
||||||
// todo element = _clientStorage.GetElement(model);
|
var element = _storage.GetElement(model);
|
||||||
var element = model;
|
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not fount");
|
_logger.LogWarning("ReadElement element not fount");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"ReadElement: find.ID:{element.ID}");
|
_logger.LogInformation($"ReadElement: find.ID:{element.ID}");
|
||||||
// todo retun element;
|
return element;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||||
{
|
{
|
||||||
|
|
||||||
_logger.LogInformation($"ReadList: ClientID:{model?.ID}");
|
_logger.LogInformation($"ReadList: ClientID:{model?.ID}");
|
||||||
// todo получение списка из хранилища, model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
|
||||||
var list = model;
|
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList: return null list");
|
_logger.LogWarning("ReadList: return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// toto ReadList:Count:{list.count},
|
_logger.LogInformation($"ReadList:Count:{list.Count}");
|
||||||
_logger.LogInformation("ReadList:Count:{Count}");
|
return list;
|
||||||
// todo return list;
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(UserBindingModel model, bool withParams = true)
|
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||||
@ -131,18 +124,19 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
|
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"Client. Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." +
|
_logger.LogInformation($"Client. ID:{model.ID}.RoleID:{model.RoleID}.FirstName:{model.FirstName}." +
|
||||||
$"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}");
|
$"LastName:{model.LastName}.Password:{model.Password}.PhoneNumber:{model.PhoneNumber}.Login:{model.Login}." +
|
||||||
/*
|
$"Email:{model.Email}");
|
||||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
|
||||||
|
var element = _storage.GetElement(new UserSearchModel
|
||||||
{
|
{
|
||||||
Login = model.Login
|
Login = model.Login
|
||||||
});
|
});
|
||||||
if (element != null && element.Id != model.ID)
|
if (element != null && element.ID != model.ID)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace ElectronicsShopContracts.BindingModels
|
|||||||
|
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
public DateTime? DateImplemet { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
|
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@ namespace ElectronicsShopContracts.StorageContracts
|
|||||||
public interface IProductStorage
|
public interface IProductStorage
|
||||||
{
|
{
|
||||||
List<ProductViewModel> GetFullList();
|
List<ProductViewModel> GetFullList();
|
||||||
List<ProductViewModel> GetFilteredList(OrderSearchModel model);
|
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||||
ProductViewModel? GetElement(OrderSearchModel model);
|
ProductViewModel? GetElement(ProductSearchModel model);
|
||||||
ProductViewModel? Insert(OrderBindingModel model);
|
ProductViewModel? Insert(ProductBindingModel model);
|
||||||
ProductViewModel? Update(OrderBindingModel model);
|
ProductViewModel? Update(ProductBindingModel model);
|
||||||
ProductViewModel? Delete(OrderBindingModel model);
|
ProductViewModel? Delete(ProductBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ namespace ElectronicsShopContracts.ViewModels
|
|||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
[DisplayName("Дата выполнения")]
|
[DisplayName("Дата выполнения")]
|
||||||
public DateTime? DateImplemet { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
|
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace ElectronicsShopDataModels.Models
|
|||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
PaymeantOption PaymeantOption { get; }
|
PaymeantOption PaymeantOption { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
DateTime? DateImplemet { get; }
|
DateTime? DateImplement { get; }
|
||||||
//список товаров в заказе
|
//список товаров в заказе
|
||||||
Dictionary<int, (IProductModel, int)> ProductList { get; }
|
Dictionary<int, (IProductModel, int)> ProductList { get; }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user