Добавление логики + её фикс и изменение модели поиска заказа
This commit is contained in:
parent
929ebbc849
commit
2a7c592202
@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id);
|
||||
_logger.LogInformation("ReadElement. BundlingId:Id:{ Id}", model.Id);
|
||||
var element = _bundlingStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id);
|
||||
_logger.LogInformation("ReadElement. FeatureId:Id:{ Id}", model.Id);
|
||||
var element = _fatureStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
|
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. OrderId:Id:{ Id}", model.Id);
|
||||
var element = _orderStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_orderStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.BuyerFCS == string.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("Нет покупателя", nameof(model.BuyerFCS));
|
||||
}
|
||||
if(model.Sum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Сумма меньше нуля",nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. Order:Id:{ Id}.Sum:{ Sum}", model.Id, model.Sum);
|
||||
}
|
||||
}
|
||||
}
|
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs
Normal file
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class PresaleLogic : IPresaleLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPresaleStorage _presaleStorage;
|
||||
public PresaleLogic(ILogger<PresaleLogic> logger, IPresaleStorage presaleStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_presaleStorage = presaleStorage;
|
||||
}
|
||||
|
||||
public List<PresaleViewModel>? ReadList(PresaleSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. PresaleId:Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _presaleStorage.GetFullList() : _presaleStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public PresaleViewModel? ReadElement(PresaleSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. PresaleId:Id:{ Id}", model.Id);
|
||||
var element = _presaleStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(PresaleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_presaleStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(PresaleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_presaleStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PresaleBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_presaleStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(PresaleBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Description == string.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("Нет описания", nameof(model.Description));
|
||||
}
|
||||
if (model.DueTill < DateTime.Now)
|
||||
{
|
||||
throw new InvalidOperationException("Срок выполнения раньше текущего времени");
|
||||
}
|
||||
_logger.LogInformation("Presale. Presale:Id:{ Id}.Price:{ Price}", model.Id, model.Description);
|
||||
}
|
||||
}
|
||||
}
|
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/RequestLogic.cs
Normal file
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/RequestLogic.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class RequestLogic : IRequestLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
public RequestLogic(ILogger<RequestLogic> logger, IRequestStorage requestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestStorage = requestStorage;
|
||||
}
|
||||
|
||||
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. RequestId:Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public RequestViewModel? ReadElement(RequestSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. RequestId:Id:{ Id}", model.Id);
|
||||
var element = _requestStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_requestStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(RequestBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Description == string.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("Нет описания", nameof(model.Description));
|
||||
}
|
||||
_logger.LogInformation("Request. Request:Id:{ Id}.Description:{ Description}", model.Id, model.Description);
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id);
|
||||
_logger.LogInformation("ReadElement. StorekeeperId:Id:{ Id}", model.Id);
|
||||
var element = _storekeeperStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
@ -100,7 +100,7 @@ namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет телефона", nameof(model.PhoneNumber));
|
||||
}
|
||||
_logger.LogInformation("Storekeeper. Storekeeper:Id:{ Id}.Price:{ Price}", model.Id, model.PhoneNumber);
|
||||
_logger.LogInformation("Storekeeper. Storekeeper:Id:{ Id}.PhoneNumber:{ PhoneNumber}", model.Id, model.PhoneNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/WorkerLogic.cs
Normal file
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/WorkerLogic.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkerLogic : IWorkerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWorkerStorage _workerStorage;
|
||||
public WorkerLogic(ILogger<WorkerLogic> logger, IWorkerStorage workerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_workerStorage = workerStorage;
|
||||
}
|
||||
|
||||
public List<WorkerViewModel>? ReadList(WorkerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. WorkerId:Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public WorkerViewModel? ReadElement(WorkerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentId:Id:{ Id}", model.Id);
|
||||
var element = _workerStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(WorkerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(WorkerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(WorkerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_workerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(WorkerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.PhoneNumber <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Нет телефона", nameof(model.PhoneNumber));
|
||||
}
|
||||
_logger.LogInformation("Worker. Worker:Id:{ Id}.PhoneNumber:{ PhoneNumber}", model.Id, model.PhoneNumber);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,5 @@ namespace CarCenterContracts.SearchModels
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? BuyerFCS { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user