client BusinessLogic, Contracts, DataModels

This commit is contained in:
ShabOl 2024-04-11 00:30:45 +04:00
parent d363e63eb8
commit 965db848b1
11 changed files with 218 additions and 0 deletions

View File

@ -0,0 +1,121 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopBusinessLogic.BusinessLogics
{
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. ClientFIO: {ClientFIO}. Id: {Id}", Model?.ClientFIO, 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);
ClientViewModel? Client = _clientStorage.GetElement(Model);
if (Client == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", Client.Id);
return Client;
}
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)
if (string.IsNullOrEmpty(Model.ClientFIO))
throw new ArgumentNullException("Нет ФИО клиента", nameof(Model.ClientFIO));
if (string.IsNullOrEmpty(Model.Email))
throw new ArgumentNullException("Нет Email клиента", nameof(Model.ClientFIO));
if (string.IsNullOrEmpty(Model.Password))
throw new ArgumentNullException("Нет пароля клиента", nameof(Model.ClientFIO));
_logger.LogInformation("Client. ClientFIO: {ClientFIO}." +
"Email: {Email}. Password: {Password}. Id: {Id} ", Model.ClientFIO, Model.Email, Model.Password, Model.Id);
ClientViewModel? Client = _clientStorage.GetElement(new ClientSearchModel
{
Email = Model.Email,
});
if (Client != null && Client.Id != Model.Id)
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}

View File

@ -0,0 +1,12 @@
using AutoWorkshopDataModels.Models;
namespace AutoWorkshopContracts.BindingModels
{
public class ClientBindingModel : IClientModel
{
public int Id { get; set; }
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -7,6 +7,7 @@ namespace AutoWorkshopContracts.BindingModels
{
public int Id { get; set; }
public int RepairId { get; set; }
public int ClientId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Undefined;

View File

@ -0,0 +1,19 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopContracts.BusinessLogicContracts
{
public interface IClientLogic
{
List<ClientViewModel>? ReadList(ClientSearchModel? Model);
ClientViewModel? ReadElement(ClientSearchModel Model);
bool Create(ClientBindingModel Model);
bool Update(ClientBindingModel Model);
bool Delete(ClientBindingModel Model);
}
}

View File

@ -0,0 +1,13 @@
namespace AutoWorkshopContracts.SearchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
public string? ClientFIO { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}
}

View File

@ -4,6 +4,8 @@
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }

View File

@ -0,0 +1,16 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopContracts.StoragesContracts
{
public interface IClientStorage
{
List<ClientViewModel> GetFullList();
List<ClientViewModel> GetFilteredList(ClientSearchModel Model);
ClientViewModel? GetElement(ClientSearchModel Model);
ClientViewModel? Insert(ClientBindingModel Model);
ClientViewModel? Update(ClientBindingModel Model);
ClientViewModel? Delete(ClientBindingModel Model);
}
}

View File

@ -0,0 +1,19 @@
using AutoWorkshopDataModels.Models;
using System.ComponentModel;
namespace AutoWorkshopContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
public int Id { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -13,7 +13,12 @@ namespace AutoWorkshopContracts.ViewModels
[DisplayName("Ремонт")]
public string RepairName { get; set; } = string.Empty;
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }

View File

@ -0,0 +1,9 @@
namespace AutoWorkshopDataModels.Models
{
public interface IClientModel : IId
{
string ClientFIO { get; }
string Email { get; }
string Password { get; }
}
}

View File

@ -5,6 +5,7 @@ namespace AutoWorkshopDataModels.Models
public interface IOrderModel : IId
{
int RepairId { get; }
int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }