Бизнес логика + отчёты
This commit is contained in:
parent
d192a45112
commit
b3ba001d80
@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDataModels", "CarC
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDatabaseImplement", "CarCenterDatabaseImplement\CarCenterDatabaseImplement.csproj", "{84503674-1555-4ED9-89C4-385C76F6B89C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterView", "CarCenterView\CarCenterView.csproj", "{A9F57191-CEAF-4164-87A5-73C2C9245D75}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterView", "CarCenterView\CarCenterView.csproj", "{A9F57191-CEAF-4164-87A5-73C2C9245D75}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterBusinessLogic", "CarCenterBusinessLogic\CarCenterBusinessLogic.csproj", "{398B3328-DCC8-4D51-95AB-913D3FDECCF4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{A9F57191-CEAF-4164-87A5-73C2C9245D75}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
123
CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs
Normal file
123
CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BossLogic : IBossLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBossStorage _BossStorage;
|
||||
|
||||
public BossLogic(ILogger<BossLogic> logger, IBossStorage BossStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_BossStorage = BossStorage;
|
||||
}
|
||||
public List<BossViewModel>? ReadList(BossSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _BossStorage.GetFullList() : _BossStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public BossViewModel? ReadElement(BossSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}. Login: { Login}", model.Id, model.Login);
|
||||
var element = _BossStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}. Login: { Login}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(BossBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_BossStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BossBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_BossStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(BossBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_BossStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BossBindingModel 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));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фамилии начальника!", nameof(model.Surname));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина начальника!", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля начальника!", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Boss. Surname:{Surname}. Name:{Name}. Login:{Login}. Password:{Password}. Id:{Id}", model.Surname, model.Name, model.Login, model.Password, model.Id);
|
||||
var element = _BossStorage.GetElement(new BossSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Начальник с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs
Normal file
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.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 CarLogic : ICarLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICarStorage _CarStorage;
|
||||
|
||||
public CarLogic(ILogger<CarLogic> logger, ICarStorage CarStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_CarStorage = CarStorage;
|
||||
}
|
||||
|
||||
public List<CarViewModel>? ReadList(CarSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _CarStorage.GetFullList() : _CarStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public CarViewModel? ReadElement(CarSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _CarStorage.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(CarBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CarStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(CarBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CarStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CarBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_CarStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CarBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия машины!", nameof(model.Name));
|
||||
}
|
||||
if (model.EmployeeId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Неверный ID сотрудника");
|
||||
}
|
||||
_logger.LogInformation("Car. Name:{Name}. EmployeeId:{EmployeeId}. Id:{Id}", model.Name, model.EmployeeId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ConfigurationLogic : IConfigurationLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationStorage _ConfigurationStorage;
|
||||
public ConfigurationLogic(ILogger<ConfigurationLogic> logger, IConfigurationStorage ConfigurationStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_ConfigurationStorage = ConfigurationStorage;
|
||||
}
|
||||
public List<ConfigurationViewModel>? ReadList(ConfigurationSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _ConfigurationStorage.GetFullList() : _ConfigurationStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ConfigurationViewModel? ReadElement(ConfigurationSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _ConfigurationStorage.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(ConfigurationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ConfigurationStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ConfigurationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ConfigurationStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ConfigurationBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_ConfigurationStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ConfigurationBindingModel 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));
|
||||
}
|
||||
if (model.BossId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id начальника меньше нуля!");
|
||||
}
|
||||
_logger.LogInformation("Configuration. Name:{ Name}. BossId: { BossId}. Id: { Id}", model.Name, model.BossId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
126
CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs
Normal file
126
CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs
Normal file
@ -0,0 +1,126 @@
|
||||
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 EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeStorage _EmployeeStorage;
|
||||
|
||||
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage EmployeeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_EmployeeStorage = EmployeeStorage;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", 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. Id:{Id}", 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.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени сотрудника", nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фамилии сотрудника", nameof(model.Surname));
|
||||
}
|
||||
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. Surname:{Surname}. Name:{Name}. Login:{Login}. Password:{Password}. Id:{Id}", model.Surname, model.Name, model.Login, model.Password, model.Id);
|
||||
var element = _EmployeeStorage.GetElement(new EmployeeSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Сотрудник с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
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 CarCenterusinessLogic.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. 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. 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.TypeOfJobId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Неверный ID вида работы");
|
||||
}
|
||||
if (model.EmployeeId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Неверный ID сотрудника");
|
||||
}
|
||||
_logger.LogInformation("Presale. PresaleDate:{PresaleDate}. TypeOfJobId:{TypeOfJobId}. EmployeeId:{EmployeeId}. Id:{Id}", model.PresaleDate, model.TypeOfJobId, model.EmployeeId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
112
CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs
Normal file
112
CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReceiptLogic : IReceiptLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReceiptStorage _ReceiptStorage;
|
||||
public ReceiptLogic(ILogger<ReceiptLogic> logger, IReceiptStorage ReceiptStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_ReceiptStorage = ReceiptStorage;
|
||||
}
|
||||
public ReceiptViewModel? ReadElement(ReceiptSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _ReceiptStorage.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<ReceiptViewModel>? ReadList(ReceiptSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _ReceiptStorage.GetFullList() : _ReceiptStorage.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(ReceiptBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ReceiptStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ReceiptBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_ReceiptStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ReceiptBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ReceiptStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ReceiptBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.BossId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id начальника меньше нуля!");
|
||||
}
|
||||
if(model.ConfigurationId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id комплектации меньше нуля!");
|
||||
}
|
||||
if (model.Sum < 0) {
|
||||
throw new InvalidOperationException("Сумма поступления неверная!");
|
||||
}
|
||||
_logger.LogInformation("Id: {Id}. Sum:{ Sum}. BossId: { BossId}. ConfigurationId: {ConfigurationId}.", model.Id, model.Sum, model.BossId, model.ConfigurationId);
|
||||
}
|
||||
}
|
||||
}
|
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
110
CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogic : IReportLogic
|
||||
{
|
||||
private readonly ISaleStorage _saleStorage;
|
||||
private readonly ICarStorage _carStorage;
|
||||
private readonly IReceiptStorage _receiptStorage;
|
||||
private readonly IConfigurationStorage _configurationStorage;
|
||||
public ReportLogic(ISaleStorage saleStorage, ICarStorage carStorage, IReceiptStorage receiptStorage)
|
||||
{
|
||||
_saleStorage = saleStorage;
|
||||
_carStorage = carStorage;
|
||||
_receiptStorage = receiptStorage;
|
||||
}
|
||||
|
||||
|
||||
public List<ReportSaleReceiptViewModel> GetSaleReceipt(ReportBindingModel model)
|
||||
{
|
||||
var sales = _saleStorage.GetFilteredList(new SaleSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||
var configurations = _configurationStorage.GetFullList();
|
||||
var receipts = _receiptStorage.GetFullList();
|
||||
var list = new List<ReportSaleReceiptViewModel>();
|
||||
|
||||
foreach (var sale in sales)
|
||||
{
|
||||
var record = new ReportSaleReceiptViewModel
|
||||
{
|
||||
SaleId = sale.Id,
|
||||
SaleDate = sale.SaleDateTime,
|
||||
Receipts = new List<(int, float)>()
|
||||
};
|
||||
var car = _carStorage.GetElement(new CarSearchModel { Id = sale.Id });
|
||||
if (car == null)
|
||||
{
|
||||
throw new InvalidOperationException("Машина не была найден!");
|
||||
}
|
||||
var foundConfigurationsId = new List<int>();
|
||||
foreach (var configuration in configurations)
|
||||
{
|
||||
if (car.ConfigurationCars.ContainsKey(configuration.Id)) foundConfigurationsId.Add(configuration.Id);
|
||||
}
|
||||
foreach (var receipt in receipts)
|
||||
{
|
||||
foreach (var configurationId in foundConfigurationsId)
|
||||
{
|
||||
if (receipt.ConfigurationId == configurationId)
|
||||
{
|
||||
record.Receipts.Add(new(receipt.Id,receipt.Sum));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
list.Add(record);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ReportCarReceiptViewModel> GetCarReceipt(ReportBindingModel model)
|
||||
{
|
||||
var receipts = _receiptStorage.GetFilteredList(new ReceiptSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||
var list = new List<ReportCarReceiptViewModel>();
|
||||
var cars = _carStorage.GetFullList();
|
||||
foreach (var receipt in receipts)
|
||||
{
|
||||
var record = new ReportCarReceiptViewModel
|
||||
{
|
||||
ReceiptId = receipt.Id,
|
||||
ReceiptDate = receipt.ReceiptDate,
|
||||
Cars = new List<(int CarId, string CarDate)>(),
|
||||
};
|
||||
foreach (var car in cars)
|
||||
{
|
||||
if (car.ConfigurationCars.ContainsKey(receipt.ConfigurationId)) record.Cars.Add(new(car.Id, car.Name.ToString()));
|
||||
}
|
||||
list.Add(record);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void SaveCarReceiptToExcel(List<CarBindingModel> cars)
|
||||
{
|
||||
// Создание файла
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveCarReceiptToWord(List<CarBindingModel> cars)
|
||||
{
|
||||
// Создание файла
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveSaleReceiptToPDF(ReportBindingModel model)
|
||||
{
|
||||
// Создание файла
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.cs
Normal file
106
CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.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 SaleLogic : ISaleLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISaleStorage _SaleStorage;
|
||||
|
||||
public SaleLogic(ILogger<SaleLogic> logger, ISaleStorage SaleStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_SaleStorage = SaleStorage;
|
||||
}
|
||||
|
||||
public List<SaleViewModel>? ReadList(SaleSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _SaleStorage.GetFullList() : _SaleStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public SaleViewModel? ReadElement(SaleSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _SaleStorage.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(SaleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_SaleStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(SaleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_SaleStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(SaleBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_SaleStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(SaleBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Sum < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Сумма не может быть отрицательной");
|
||||
}
|
||||
_logger.LogInformation("Sale. SaleDateTime:{SaleDateTime}. Sum:{Sum}. CarId:{CarId}. ReceiptId:{ReceiptId}. ConfigurationId:{ConfigurationId}. Id:{Id}", model.SaleDateTime, model.Sum, model.CarId, model.ReceiptId, model.ConfigurationId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
|
||||
namespace CarCenterBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class TypeOfJobLogic : ITypeOfJobLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ITypeOfJobStorage _TypeOfJobStorage;
|
||||
public TypeOfJobLogic(ILogger<TypeOfJobLogic> logger, ITypeOfJobStorage TypeOfJobStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_TypeOfJobStorage = TypeOfJobStorage;
|
||||
}
|
||||
public List<TypeOfJobViewModel>? ReadList(TypeOfJobSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _TypeOfJobStorage.GetFullList() : _TypeOfJobStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public TypeOfJobViewModel? ReadElement(TypeOfJobSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _TypeOfJobStorage.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(TypeOfJobBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_TypeOfJobStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(TypeOfJobBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_TypeOfJobStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(TypeOfJobBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_TypeOfJobStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(TypeOfJobBindingModel 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));
|
||||
}
|
||||
if (model.BossId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id начальника меньше нуля!");
|
||||
}
|
||||
_logger.LogInformation("TypeOfJob. Name:{ Name}. BossId: { BossId}. Id: { Id}", model.Name, model.BossId, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -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="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarCenterContracts\CarCenterContracts.csproj" />
|
||||
<ProjectReference Include="..\CarCenterDataModels\CarCenterDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogic
|
||||
{
|
||||
void SaveCarReceiptToWord(List<CarBindingModel> cars);
|
||||
void SaveCarReceiptToExcel(List<CarBindingModel> cars);
|
||||
void SaveSaleReceiptToPDF(ReportBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterContracts.ViewModels
|
||||
{
|
||||
public class ReportCarReceiptViewModel
|
||||
{
|
||||
public int ReceiptId { get; set; }
|
||||
public DateTime ReceiptDate { get; set; }
|
||||
public List<(int CarId, string Num)> Cars { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarCenterContracts.ViewModels
|
||||
{
|
||||
public class ReportSaleReceiptViewModel
|
||||
{
|
||||
public int SaleId { get; set; }
|
||||
public DateTime SaleDate { get; set; }
|
||||
public List<(int ReceiptId, float Sum)> Receipts { get; set; } = new();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user