бизнесссс

сумасшедшие люди и не догадываются, что они сумасшедшие — поэтому они и сумасшедшие
This commit is contained in:
Artur 2024-04-30 23:22:50 +04:00
parent 943e1705de
commit 50bbc9c873
8 changed files with 569 additions and 2 deletions

View File

@ -0,0 +1,138 @@
using CarCentreContracts.BindingModels;
using CarCentreContracts.BusinessLogicsContracts;
using CarCentreContracts.SearchModels;
using CarCentreContracts.StorageContracts;
using CarCentreContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCentreBusinessLogic.BusinessLogic
{
public class AutoLogic : IAutoLogic
{
private readonly ILogger _logger;
private readonly IAutoStorage _WorkStorage;
public AutoLogic(ILogger<AutoLogic> logger, IAutoStorage WorkStorage)
{
_logger = logger;
_WorkStorage = WorkStorage;
}
public List<AutoViewModel>? ReadList(AutoSearchModel? model)
{
_logger.LogInformation("ReadList. AutoName:{WorkName}. Id:{ Id}", model?.AutoName, model?.Id);
var list = model == null ? _WorkStorage.GetFullList() : _WorkStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public AutoViewModel? ReadElement(AutoSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. AutoName:{WorkName}.Id:{ Id}", model.AutoName, model.Id);
var element = _WorkStorage.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(WorkBindingModel model)
{
CheckModel(model);
if (_WorkStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(WorkBindingModel model)
{
CheckModel(model);
if (_WorkStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(WorkBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_WorkStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(WorkBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.AutoPrice <= 0)
{
throw new ArgumentNullException("Cтоимости посещения работаа должна быть больше 0",
nameof(model.AutoPrice));
}
_logger.LogInformation("Auto. AutoName:{AutoName}.AutoPrice:{AutoPrice} Id: { Id}", model.AutoName, model.AutoPrice, model.Id);
var element = _WorkStorage.GetElement(new AutoSearchModel
{
AutoName = model.AutoName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("работа с таким названием уже есть");
}
}
List<AutoViewModel>? IAutoLogic.ReadList(AutoSearchModel? model)
{
throw new NotImplementedException();
}
AutoViewModel? IAutoLogic.ReadElement(AutoSearchModel model)
{
throw new NotImplementedException();
}
bool IAutoLogic.Create(WorkBindingModel model)
{
throw new NotImplementedException();
}
bool IAutoLogic.Update(WorkBindingModel model)
{
throw new NotImplementedException();
}
bool IAutoLogic.Delete(WorkBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,124 @@
using CarCentreContracts.BindingModels;
using CarCentreContracts.BusinessLogicsContracts;
using CarCentreContracts.SearchModels;
using CarCentreContracts.StorageContracts;
using CarCentreContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCentreBusinessLogic.BusinessLogic
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. ClientId:{Id}", model?.Id);
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientFio:{ClientFio}.Id:{ Id}", model.ClientFIO, model.Id);
var element = _clientStorage.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(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет ФИО пользователя", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.EMail))
{
throw new ArgumentNullException("Нет почты пользователя", nameof(model.EMail));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
_logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Password:{Password}.Id:{Id}",
model.ClientFIO, model.EMail, model.Password, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
ClientFIO = model.ClientFIO
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с таким именем уже есть");
}
}
}
}

View File

@ -0,0 +1,117 @@
using CarCentreContracts.BindingModels;
using CarCentreContracts.BusinessLogicsContracts;
using CarCentreContracts.SearchModels;
using CarCentreContracts.StorageContracts;
using CarCentreContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCentreBusinessLogic.BusinessLogic
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(Microsoft.Extensions.Logging.ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeFIO:{EmployeeFIO}. Id:{ Id}", model?.EmployeeFIO, model?.Id);
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. EmployeeFIO:{EmployeeFIO}.Id:{ Id}", model.EmployeeFIO, model.Id);
var element = _employeeStorage.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(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_employeeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина сотрудника",
nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
}
_logger.LogInformation("Employee. EmployeeFIO:{EmployeeFIO}.Login:{ Login}.Password:{Password} Id: { Id}", model.EmployeeFIO, model.Login, model.Password, model.Id);
var element = _employeeStorage.GetElement(new EmployeeSearchModel
{
EmployeeFIO = model.EmployeeFIO
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Сотрудник с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,62 @@
using CarCentreContracts.BindingModels;
using CarCentreContracts.BusinessLogicsContracts;
using CarCentreContracts.SearchModels;
using CarCentreContracts.StorageContracts;
using CarCentreContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCentreBusinessLogic.BusinessLogic
{
public class PaymentLogic : IPaymentLogic
{
private readonly ILogger _logger;
private readonly IPaymentStorage _paymentStorage;
public PaymentLogic(ILogger<PaymentLogic> logger, IPaymentStorage paymentStorage)
{
_logger = logger;
_paymentStorage = paymentStorage;
}
public bool Create(PaymentBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(PaymentBindingModel model)
{
throw new NotImplementedException();
}
public PaymentViewModel? ReadElement(PaymentSearchModel model)
{
throw new NotImplementedException();
}
public List<PaymentViewModel>? ReadList(PaymentSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(PaymentBindingModel model)
{
throw new NotImplementedException();
}
private void CheckModel(RequestBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Request. Id: {Id}", model.Id);
}
}
}

View File

@ -0,0 +1,95 @@
using CarCentreContracts.BindingModels;
using CarCentreContracts.BusinessLogicsContracts;
using CarCentreContracts.SearchModels;
using CarCentreContracts.StorageContracts;
using CarCentreContracts.ViewModels;
using CarCentreDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarCentreBusinessLogic.BusinessLogic
{
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. RequestName:{RequestName}. Id:{ Id}", model?.RequestName, 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 bool Create(RequestBindingModel model)
{
CheckModel(model);
if (_RequestStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool CheckRequestPay(RequestBindingModel model, RequestStatus status)
{
CheckModel(model);
var element = _RequestStorage.GetElement(new RequestSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
model.Status = status;
if (model.Status == RequestStatus.Неоплачен) model.DateFinish = DateTime.Now;
_RequestStorage.Update(model);
return true;
}
public bool RequestWasPaid(RequestBindingModel model)
{
return CheckRequestPay(model, RequestStatus.Оплачен);
}
private void CheckModel(RequestBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.RequestName))
{
throw new ArgumentNullException("Нет названия сделки",
nameof(model.RequestName));
}
if (model.RequestPrice <= 0)
{
throw new ArgumentNullException("Стоимость сделки должна быть >0", nameof(model.RequestPrice));
}
_logger.LogInformation("Request. RequestName:{RequestName}.RequestPrice:{ RequestPrice} Id: { Id}", model.RequestName, model.RequestPrice, model.Id);
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarCentreContracts\CarCentreContracts.csproj" />
<ProjectReference Include="..\CarCentreDataModels\CarCentreDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace CarCentreBusinessLogic
{
public class Class1
{
}
}

View File

@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreDataModels", "CarCentreDataModels\CarCentreDataModels.csproj", "{44ABE0E6-CF7F-4401-8264-CA9278EEE541}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCentreDataModels", "CarCentreDataModels\CarCentreDataModels.csproj", "{44ABE0E6-CF7F-4401-8264-CA9278EEE541}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreContracts", "CarCentreContracts\CarCentreContracts.csproj", "{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCentreContracts", "CarCentreContracts\CarCentreContracts.csproj", "{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreBusinessLogic", "CarCentreBusinessLogic\CarCentreBusinessLogic.csproj", "{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Release|Any CPU.Build.0 = Release|Any CPU
{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE