шо ты, плаки плаки?
This commit is contained in:
parent
c0b83e1d87
commit
c649d4db51
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterDataModels", "..\C
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterContracts", "..\CarCenterContracts\CarCenterContracts.csproj", "{4A207999-1093-4596-B779-7366629753D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterBusinessLogics", "..\CarCenterBusinessLogics\CarCenterBusinessLogics.csproj", "{6AD3202B-AE23-425B-B71C-07BC326F6EA6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{4A207999-1093-4596-B779-7366629753D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4A207999-1093-4596-B779-7366629753D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4A207999-1093-4596-B779-7366629753D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6AD3202B-AE23-425B-B71C-07BC326F6EA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6AD3202B-AE23-425B-B71C-07BC326F6EA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6AD3202B-AE23-425B-B71C-07BC326F6EA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6AD3202B-AE23-425B-B71C-07BC326F6EA6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
116
CarCenterBusinessLogics/AccountLogic.cs
Normal file
116
CarCenterBusinessLogics/AccountLogic.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using CarCenterContracts.BusinessLogicContracts;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
|
||||
namespace CarCenterBusinessLogics.BusinessLogics
|
||||
{
|
||||
public class AccountLogic : IAccountLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IAccountStorage _accountStorage;
|
||||
private readonly ICarLogic _CarStorage;
|
||||
|
||||
public AccountLogic(ILogger<AccountLogic> logger, IAccountStorage accountStorage, ICarLogic CarStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_accountStorage = accountStorage;
|
||||
_CarStorage = CarStorage;
|
||||
}
|
||||
public List<AccountViewModel> ReadList(AccountSearchModel? model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = model != null ? _accountStorage.GetFilteredList(model) : _accountStorage.GetFullList();
|
||||
_logger.LogDebug("Список полученных счетов: {@accounts}", results);
|
||||
_logger.LogInformation("Извлечение списка в количестве {Count} c счетовой по модели: {@AccountSearchModel}", results.Count, model);
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Произошла ошибка при попытки получить список по модели: {@AccountSearchModel}", model);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public AccountViewModel ReadElement(AccountSearchModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _accountStorage.GetElement(model);
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException($"Результат получения элемента с айди {model.Id} оказался нулевым");
|
||||
}
|
||||
_logger.LogInformation("Извлечение счета {@AccountViewModel} по модели: {@AccountSearchModel}", result, model);
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Произошла ошибка при попытки получить элемент по модели: {@AccountSearchModel}", model);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public bool Create(AccountBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
CheckModel(model);
|
||||
var result = _accountStorage.Insert(model);
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException($"Результат создания счета оказался нулевым");
|
||||
}
|
||||
_logger.LogInformation("Была создана сущность: {@AccountViewModel}", result);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Произошла ошибка при попытки создать элемент по модели: {@AccountBindingModel}", model);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
private void CheckModel(AccountBindingModel model, bool withParams = true)
|
||||
{
|
||||
const string txt = "Произошла ошибка на уровне проверки AccountBindingModel.";
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model), txt);
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Price < 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.Price), txt + "Оплаченная стоимость не может быть отрицательной");
|
||||
}
|
||||
}
|
||||
public bool GetAccountInfo(AccountSearchModel model,
|
||||
out double currentBalance,
|
||||
out double paidPrice)
|
||||
{
|
||||
try
|
||||
{
|
||||
var accounts = ReadList(model);
|
||||
paidPrice = 0;
|
||||
if (accounts == null || accounts.Count == 0)
|
||||
{
|
||||
currentBalance = 0;
|
||||
return true;
|
||||
}
|
||||
currentBalance = accounts.Sum(x => x.Price);
|
||||
_logger.LogInformation(
|
||||
"По автомобилю({Id}) и клиенту({Id}) получена полная стоимость {fullPrice} и оплаченная стоимость {paidPrice}",
|
||||
model.CarId, model.ClientId, currentBalance, paidPrice);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "При попытке получения счетов по {@searchModel} произошла ошибка", model);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
CarCenterBusinessLogics/CarCenterBusinessLogics.csproj
Normal file
9
CarCenterBusinessLogics/CarCenterBusinessLogics.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user