Создана бизнес логика для сущностей
This commit is contained in:
parent
45beb79552
commit
1342035a29
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmDataModels", "LawFir
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmContracts", "LawFirmContracts\LawFirmContracts.csproj", "{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
122
LawFirm/LawFirmBusinessLogic/BusinessLogics/BlankLogic.cs
Normal file
122
LawFirm/LawFirmBusinessLogic/BusinessLogics/BlankLogic.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BlankLogic : IBlankLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBlankStorage _blankStorage;
|
||||
|
||||
public BlankLogic (ILogger<BlankLogic> logger, IBlankStorage blankStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_blankStorage = blankStorage;
|
||||
}
|
||||
|
||||
public bool Create(BlankBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_blankStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BlankBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_blankStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public BlankViewModel? ReadElement(BlankSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. BlankName:{BlankName}.Id:{ Id}", model.BlankName, model.Id);
|
||||
var element = _blankStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
|
||||
}
|
||||
|
||||
public List<BlankViewModel>? ReadList(BlankSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. BlankName:{BlankName}.Id:{ Id}", model?.BlankName, model?.Id);
|
||||
var list = model == null ? _blankStorage.GetFullList() : _blankStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(BlankBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_blankStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BlankBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.BlankName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия бланка", nameof(model.BlankName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена бланка должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Blank. BlankName:{BlankName}.Cost:{ Cost}. Id: { Id}", model.BlankName, model.Cost, model.Id);
|
||||
var element = _blankStorage.GetElement(new BlankSearchModel
|
||||
{
|
||||
BlankName = model.BlankName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Бланк с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
119
LawFirm/LawFirmBusinessLogic/BusinessLogics/DocumentLogic.cs
Normal file
119
LawFirm/LawFirmBusinessLogic/BusinessLogics/DocumentLogic.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class DocumentLogic : IDocumentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDocumentStorage _documentStorage;
|
||||
|
||||
public DocumentLogic(ILogger<DocumentLogic> logger, IDocumentStorage documentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_documentStorage = documentStorage;
|
||||
}
|
||||
|
||||
public bool Create(DocumentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_documentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(DocumentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_documentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DocumentViewModel? ReadElement(DocumentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. DocumentName:{DocumentName}.Id:{ Id}", model.DocumentName, model.Id);
|
||||
var element = _documentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<DocumentViewModel>? ReadList(DocumentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DocumentName:{DocumentName}.Id:{ Id}", model?.DocumentName, model?.Id);
|
||||
var list = model == null ? _documentStorage.GetFullList() : _documentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(DocumentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_documentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(DocumentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.DocumentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия документа", nameof(model.DocumentName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость документа должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Document. DocumentName:{DocumentName}.Price:{ Price}. Id: { Id}", model.DocumentName, model.Price, model.Id);
|
||||
var element = _documentStorage.GetElement(new DocumentSearchModel
|
||||
{
|
||||
DocumentName = model.DocumentName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Документ с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
116
LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
internal class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = newStatus;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("Order. OrderID:{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;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.DocumentId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.DocumentId));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество документов в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.DocumentId);
|
||||
}
|
||||
}
|
||||
}
|
9
LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj
Normal file
9
LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user