Создание и заполнение FurnitureFactoryBusinessLogic BusinessLogic

This commit is contained in:
FLARJ 2023-04-07 19:17:49 +04:00
parent a11c708c7b
commit 9e908c8406
13 changed files with 506 additions and 8 deletions

View File

@ -4,6 +4,7 @@ namespace FurnitureContracts.BindingModels
{ {
public class HeadsetBindingModel : IHeadsetModel public class HeadsetBindingModel : IHeadsetModel
{ {
public string Title { get; set; } = string.Empty;
public string Size { get; set; } = string.Empty; public string Size { get; set; } = string.Empty;
public int Cost { get; set; } public int Cost { get; set; }
public int Id { get; set; } public int Id { get; set; }

View File

@ -8,6 +8,7 @@ namespace FurnitureContracts.SearchModels
{ {
public class HeadsetModuleSearchModel public class HeadsetModuleSearchModel
{ {
public string? Title { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
} }

View File

@ -8,6 +8,7 @@ namespace FurnitureContracts.SearchModels
{ {
public class HeadsetSearchModel public class HeadsetSearchModel
{ {
public string? Title { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
public int? ManagerId { get; set; } public int? ManagerId { get; set; }
public string? Size { get; set; } public string? Size { get; set; }

View File

@ -10,6 +10,8 @@ namespace FurnitureContracts.ViewModel
{ {
public class HeadsetViewModel : IHeadsetModel public class HeadsetViewModel : IHeadsetModel
{ {
[DisplayName("Название")]
public string? Title { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public int Cost { get; set; } public int Cost { get; set; }

View File

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureFactoryDataModels"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureContracts", "FurnitureContracts\FurnitureContracts.csproj", "{E269E4B8-5EAD-4BB2-A8BA-44FE9D202FB6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureContracts", "FurnitureContracts\FurnitureContracts.csproj", "{E269E4B8-5EAD-4BB2-A8BA-44FE9D202FB6}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryDataBaseImplement", "FurnitureFactoryDataBaseImplement\FurnitureFactoryDataBaseImplement.csproj", "{833913DB-1F3F-4700-A200-90759788B1A9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureFactoryDataBaseImplement", "FurnitureFactoryDataBaseImplement\FurnitureFactoryDataBaseImplement.csproj", "{833913DB-1F3F-4700-A200-90759788B1A9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryBusinessLogic", "FurnitureFactoryBusinessLogic\FurnitureFactoryBusinessLogic.csproj", "{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{833913DB-1F3F-4700-A200-90759788B1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {833913DB-1F3F-4700-A200-90759788B1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.Build.0 = Release|Any CPU {833913DB-1F3F-4700-A200-90759788B1A9}.Release|Any CPU.Build.0 = Release|Any CPU
{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3CBBE95-E306-4A68-AC26-1E11FA7FB1F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using FurnitureContracts.BindingModels;
using FurnitureContracts.BusinessLogicsContracts;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplements.Implements;
namespace FurnitureFactoryBusinessLogic.BusinessLogic
{
internal class HeadsetLogic
{
private readonly ILogger _logger;
private readonly IHeadsetStorage _headsetStorage;
public HeadsetLogic(ILogger<HeadsetLogic> logger, IHeadsetStorage headsetStorage)
{
_logger = logger;
_headsetStorage = headsetStorage;
}
public List<HeadsetViewModel>? ReadList(HeadsetSearchModel? model)
{
_logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, model?.Id);
var list = model == null ? _headsetStorage.GetFullList() : _headsetStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public HeadsetViewModel? ReadElement(HeadsetSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id);
var element = _headsetStorage.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(HeadsetBindingModel model)
{
CheckModel(model);
if (_headsetStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(HeadsetBindingModel model)
{
CheckModel(model);
if (_headsetStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(HeadsetBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_headsetStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(HeadsetBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Title))
{
throw new ArgumentNullException("Не задано название", nameof(model.Title));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Неверно задана цена", nameof(model.Cost));
}
if (string.IsNullOrEmpty(model.Size))
{
throw new ArgumentNullException("Не задан размер", nameof(model.Size));
}
if (model.ManagerId <= 0)
{
throw new ArgumentNullException("Неверно задан идентификатор менеджера", nameof(model.ManagerId));
}
if (model.HeadsetModuleId <= 0)
{
throw new ArgumentNullException("Неверно задан идентификатор гарнитура", nameof(model.HeadsetModuleId));
}
_logger.LogInformation("Headset. Title:{Title}.Size{Size}.Cost{Cost}.StudentId:{StudentId}.TaskId{TaskId} Id: {Id}", model.Title, model.Size, model.Cost, model.ManagerId, model.HeadsetModuleId, model.Id);
var element = _headsetStorage.GetElement(new HeadsetSearchModel
{
Title = model.Title,
ManagerId = model.ManagerId
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Гарнитур с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,119 @@
using Microsoft.Extensions.Logging;
using FurnitureContracts.BindingModels;
using FurnitureContracts.BusinessLogicsContracts;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplements.Implements;
namespace FurnitureFactoryBusinessLogic.BusinessLogic
{
internal class ManagerLogic
{
private readonly ILogger _logger;
private readonly IManagerStorage _managerStorage;
public ManagerLogic(ILogger<ManagerLogic> logger, IManagerStorage managerStorage)
{
_logger = logger;
_managerStorage = managerStorage;
}
public List<ManagerViewModel>? ReadList(ManagerSearchModel? model)
{
_logger.LogInformation("ReadList. Login:{Login}.Id:{ Id}", model?.Login, model?.Id);
var list = model == null ? _managerStorage.GetFullList() : _managerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ManagerViewModel? ReadElement(ManagerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Login:{Login}. Id:{ Id}", model.Login, model.Id);
var element = _managerStorage.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(ManagerBindingModel model)
{
CheckModel(model);
if (_managerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ManagerBindingModel model)
{
CheckModel(model);
if (_managerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ManagerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_managerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ManagerBindingModel 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));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Не задана почта", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.UserName))
{
throw new ArgumentNullException("Не задано ФИО", nameof(model.UserName));
}
_logger.LogInformation("Student. Name:{Name}. Email{Email}.Login{Login} .Password{Password} Id: {Id}", model.UserName, model.Email, model.Login, model.Password, model.Id);
var element = _managerStorage.GetElement(new ManagerSearchModel
{
Login = model.Login
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Школьник с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,116 @@
using Microsoft.Extensions.Logging;
using FurnitureContracts.BindingModels;
using FurnitureContracts.BusinessLogicsContracts;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplements.Implements;
namespace FurnitureFactoryBusinessLogic.BusinessLogic
{
internal class OrderLogic
{
private readonly ILogger _logger;
private readonly IOrdersStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrdersStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrdersViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Title:{Title}.Id:{ Id}", model?.Title, 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;
}
public OrdersViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Title:{Title}. Id:{ Id}", model.Title, model.Id);
var element = _orderStorage.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(OrdersBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(OrdersBindingModel model)
{
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(OrdersBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_orderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(OrdersBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Title))
{
throw new ArgumentNullException("Не задано название", nameof(model.Title));
}
if (string.IsNullOrEmpty(model.Status))
{
throw new ArgumentNullException("Не задано описание", nameof(model.Status));
}
if (model.ManagerId <= 0)
{
throw new ArgumentNullException("Неверно задан идентификатор школьника", nameof(model.ManagerId));
}
_logger.LogInformation("Product. Titel:{Title}.Status{Status}.ManagerId:{ManagerId}. Id: {Id}", model.Title, model.Status, model.ManagerId, model.Id);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Title = model.Title,
ManagerId = model.ManagerId
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Изделие с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using FurnitureContracts.BindingModels;
using FurnitureContracts.BusinessLogicsContracts;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplements.Implements;
namespace FurnitureFactoryBusinessLogic.BusinessLogic
{
internal class SalesSalonLogic
{
private readonly ILogger _logger;
private readonly ISalesSalonsStorage _salesSalonStorage;
public SalesSalonLogic(ILogger<SalesSalonLogic> logger, ISalesSalonsStorage salesSalonStorage)
{
_logger = logger;
_salesSalonStorage = salesSalonStorage;
}
public List<SalesSalonsViewModel>? ReadList(SalesSalonsSearchModel? model)
{
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
var list = model == null ? _salesSalonStorage.GetFullList() : _salesSalonStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public SalesSalonsViewModel? ReadElement(SalesSalonsSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
var element = _salesSalonStorage.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(SalesSalonsBindingModel model)
{
CheckModel(model);
if (_salesSalonStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(SalesSalonsBindingModel model)
{
CheckModel(model);
if (_salesSalonStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(SalesSalonsBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_salesSalonStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(SalesSalonsBindingModel 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.Address))
{
throw new ArgumentNullException("Не задан адресс", nameof(model.Address));
}
if (model.ManagerId <= 0)
{
throw new ArgumentNullException("Неверно задан идентификатор менеджера", nameof(model.ManagerId));
}
_logger.LogInformation("Interest. Name:{Name}.Address{Address}.ManagerId:{ManagerId}. Id: {Id}", model.Name, model.Address, model.ManagerId, model.Id);
var element = _salesSalonStorage.GetElement(new SalesSalonsSearchModel
{
Name = model.Name,
ManagerId = model.ManagerId
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Салон с таким названием уже есть");
}
}
}
}

View File

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

View File

@ -6,4 +6,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FurnitureContracts\FurnitureContracts.csproj" />
<ProjectReference Include="..\FurnitureFactoryDataBaseImplement\FurnitureFactoryDataBaseImplement.csproj" />
<ProjectReference Include="..\FurnitureFactoryDataModels\FurnitureFactoryDataModels.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -14,6 +14,9 @@ namespace FurnitureFactoryDataBaseImplement.Models
{ {
public class Headset public class Headset
{ {
[Required]
public string Title { get; set; } = string.Empty;
[Required] [Required]
public string Size { get; set; } = string.Empty; public string Size { get; set; } = string.Empty;
[Required] [Required]
@ -48,6 +51,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
return new Headset() return new Headset()
{ {
Id = model.Id, Id = model.Id,
Title = model.Title,
Size = model.Size, Size = model.Size,
HeadsetModuleId = model.HeadsetModuleId, HeadsetModuleId = model.HeadsetModuleId,
ManagerId = model.ManagerId, ManagerId = model.ManagerId,
@ -67,6 +71,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
public HeadsetViewModel GetViewModel => new() public HeadsetViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
Title = Title,
Size = Size, Size = Size,
Cost = Cost, Cost = Cost,
HeadsetModuleId = HeadsetModuleId, HeadsetModuleId = HeadsetModuleId,

View File

@ -8,6 +8,7 @@ namespace FurnitureFactoryDataModels.Models
{ {
public interface IHeadsetModel : IId public interface IHeadsetModel : IId
{ {
string Title { get; }
int Cost { get;} int Cost { get;}
string Size { get; } string Size { get; }
public Dictionary<int, ISalesSalonsModel> HeadsetSalesSalons { get; } public Dictionary<int, ISalesSalonsModel> HeadsetSalesSalons { get; }