Total dead
This commit is contained in:
parent
f931b8c14e
commit
8770645a82
@ -0,0 +1,119 @@
|
|||||||
|
using ElectronicsShopContracts.BindingModels;
|
||||||
|
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;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
//private readonly IOrderStorage _storage;
|
||||||
|
|
||||||
|
// todo нет интерфейса хранилища
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger) {
|
||||||
|
_logger = logger;
|
||||||
|
//storage = _storage;
|
||||||
|
}
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
// todo _orderStorage.Insert(model) == null
|
||||||
|
if (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<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"ReadList:ID:{model?.ID}");
|
||||||
|
// todo model == null? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
|
var list = model;
|
||||||
|
if (list == null) {
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// todo "$ReadList.Count:{list.count}"
|
||||||
|
_logger.LogInformation("ReadList.Count:{Count}");
|
||||||
|
//todo return list
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true) {
|
||||||
|
if (model == null) {
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty((model.ID).ToString())) {
|
||||||
|
throw new ArgumentNullException("Нет ID заказа", nameof(model.ID));
|
||||||
|
}
|
||||||
|
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.DateImplemet}");
|
||||||
|
}
|
||||||
|
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
//todo
|
||||||
|
var viewModel = model; // model == _orderStorage.GetElement(new OrderSearchModel { ID = model.ID });
|
||||||
|
if (viewModel == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (viewModel.Status + 1 != newOrderStatus)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = newOrderStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
//todo подключить бд
|
||||||
|
//model.DateImplement = DateTime.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// todo подключить бд
|
||||||
|
//model.DateImplement = viewModel.DateImplement;
|
||||||
|
}
|
||||||
|
// todo
|
||||||
|
// _orderStorage.Update(model) == null
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operarion failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
using ElectronicsShopContracts.BindingModels;
|
||||||
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||||
|
using ElectronicsShopContracts.SearchModels;
|
||||||
|
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 ICategoryProductStorage _storage;
|
||||||
|
|
||||||
|
// todo нет интерфейса хранилища
|
||||||
|
public RoleLogic(ILogger<RoleLogic> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
// todo _storage.Insert(model) == null
|
||||||
|
if (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}");
|
||||||
|
// todo _storage.Insert(model) == null
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
// todo _storage.Insert(model) == null
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
||||||
|
// todo model == null _RoleStorage.GetFullList() : _RoleStorage.GetFilteredList(model);
|
||||||
|
var list = model;
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// todo $"ReadList. Count:{list.count}"
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}");
|
||||||
|
// todo return list;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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. Name:{model.Name}");
|
||||||
|
/*
|
||||||
|
var element = _RoleStorage.GetElement(new RoleSearchModel
|
||||||
|
{
|
||||||
|
Name = model.Name
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.ID)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Такая роль уже есть");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ using ElectronicsShopContracts.ViewModels;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -13,13 +14,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||||
{
|
{
|
||||||
public class ClientLogic : IClientLogic
|
public class UserLogic : IClientLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
//private readonly IClientStorage _storage;
|
//private readonly IClientStorage _storage;
|
||||||
|
|
||||||
// todo нет интерфейса хранилища
|
// todo нет интерфейса хранилища
|
||||||
public ClientLogic(ILogger logger) {
|
public UserLogic(ILogger<UserLogic> logger) {
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
//storage = _storage;
|
//storage = _storage;
|
||||||
}
|
}
|
||||||
@ -69,7 +70,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
// todo element = _clientStorage.GetElement(model);
|
// todo element = _clientStorage.GetElement(model);
|
||||||
var element = 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.UserID}");
|
_logger.LogInformation($"ReadElement: find.ID:{element.UserID}");
|
||||||
@ -87,8 +88,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
_logger.LogWarning("ReadList: return null list");
|
_logger.LogWarning("ReadList: return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// toto ReadList. Count:{Count}, list.count
|
// toto ReadList:Count:{list.count},
|
||||||
_logger.LogInformation("ReadList: Count:{Count}");
|
_logger.LogInformation("ReadList:Count:{Count}");
|
||||||
// todo return list;
|
// todo return list;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -118,8 +119,18 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
if (string.IsNullOrEmpty(model.PhoneNumber)) {
|
if (string.IsNullOrEmpty(model.PhoneNumber)) {
|
||||||
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. Login:{model.Login}.FirstName:{model.FirstName}.LastName:{model.LastName}.Email:{model.Email}." +
|
||||||
$"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}");
|
$"Password:{model.Password}.PhoneNumber:{model.PhoneNumber}");
|
||||||
|
/*
|
||||||
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
|
{
|
||||||
|
Login = model.Login
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.ID)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user