Buisnes Logic
This commit is contained in:
parent
2119b1cc33
commit
d32632eb73
@ -20,5 +20,11 @@ namespace FurnitureContracts.BindingModels
|
||||
public string MasterName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateIssue => throw new NotImplementedException();
|
||||
|
||||
public DateTime DateDelivery => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureContracts.BusinessLogicsContracts
|
||||
{
|
||||
interface IFurnitureLogic
|
||||
public interface IFurnitureLogic
|
||||
{
|
||||
List<FurnitureViewModel>? ReadList(FurnitureSearchModel? model);
|
||||
FurnitureViewModel? ReadElement(FurnitureSearchModel model);
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureContracts.BusinessLogicsContracts
|
||||
{
|
||||
internal interface IHeadsetModuleLogic
|
||||
public interface IHeadsetModuleLogic
|
||||
{
|
||||
List<HeadsetModuleViewModel>? ReadList(HeadsetModuleSearchModel? model);
|
||||
HeadsetModuleViewModel? ReadElement(HeadsetModuleSearchModel model);
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureContracts.BusinessLogicsContracts
|
||||
{
|
||||
interface IMaterialLogic
|
||||
public interface IMaterialLogic
|
||||
{
|
||||
List<MaterialViewModel>? ReadList(MaterialSearchModel? model);
|
||||
MaterialViewModel? ReadElement(MaterialSearchModel model);
|
||||
|
@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FurnitureContracts.BindingModels;
|
||||
using FurnitureContracts.BusinessLogicsContracts;
|
||||
using FurnitureContracts.SearchModels;
|
||||
using FurnitureContracts.StoragesContracts;
|
||||
using FurnitureContracts.ViewModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FurnitureFactoryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class FurnitureLogic : IFurnitureLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFurnitureStorage _FurnitureStorage;
|
||||
public FurnitureLogic(ILogger<FurnitureLogic> logger, IFurnitureStorage FurnitureStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_FurnitureStorage = FurnitureStorage;
|
||||
}
|
||||
public List<FurnitureViewModel>? ReadList(FurnitureSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _FurnitureStorage.GetFullList() : _FurnitureStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public FurnitureViewModel? ReadElement(FurnitureSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _FurnitureStorage.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(FurnitureBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_FurnitureStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(FurnitureBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_FurnitureStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(FurnitureBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_FurnitureStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(FurnitureBindingModel 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.MasterId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неверно задан идентификатор поручителя", nameof(model.MasterId));
|
||||
}
|
||||
if (model.OrdersId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неверно задан идентификатор заказа", nameof(model.OrdersId));
|
||||
}
|
||||
_logger.LogInformation("Furniture. Titel:{Name}.ProductId{ProductId}.MasterId:{MasterId}. Id: {Id}", model.Name, model.OrdersId, model.MasterId, model.Id);
|
||||
var element = _FurnitureStorage.GetElement(new FurnitureSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
MasterId = model.MasterId
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Мебель с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using FurnitureContracts.BindingModels;
|
||||
using FurnitureContracts.BusinessLogicsContracts;
|
||||
using FurnitureContracts.SearchModels;
|
||||
using FurnitureContracts.StoragesContracts;
|
||||
using FurnitureContracts.ViewModel;
|
||||
using FurnitureFactoryDataBaseImplements.Implements;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FurnitureFactoryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class HeadsetModuleLogic : IHeadsetModuleLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHeadsetModuleStorage _HeadsetModuleStorage;
|
||||
public HeadsetModuleLogic(ILogger<HeadsetModuleLogic> logger, IHeadsetModuleStorage HeadsetModuleStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_HeadsetModuleStorage = HeadsetModuleStorage;
|
||||
}
|
||||
public List<HeadsetModuleViewModel>? ReadList(HeadsetModuleSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _HeadsetModuleStorage.GetFullList() : _HeadsetModuleStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public HeadsetModuleViewModel? ReadElement(HeadsetModuleSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _HeadsetModuleStorage.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(HeadsetModuleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_HeadsetModuleStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(HeadsetModuleBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_HeadsetModuleStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(HeadsetModuleBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_HeadsetModuleStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(HeadsetModuleBindingModel 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.MasterId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неверно задан идентификатор поручителя", nameof(model.MasterId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("HeadsetModule. Titel:{Name}.MasterId:{MasterId}. Id: {Id}", model.Name, model.MasterId, model.Id);
|
||||
var element = _HeadsetModuleStorage.GetElement(new HeadsetModuleSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
MasterId = model.MasterId
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Модуль с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
using FurnitureContracts.BindingModels;
|
||||
using FurnitureContracts.BusinessLogicsContracts;
|
||||
using FurnitureContracts.SearchModels;
|
||||
using FurnitureContracts.StoragesContracts;
|
||||
using FurnitureContracts.ViewModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureFactoryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MasterLogic : IMasterLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMasterStorage _MasterStorage;
|
||||
public MasterLogic(ILogger<MasterLogic> logger, IMasterStorage MasterStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_MasterStorage = MasterStorage;
|
||||
}
|
||||
public List<MasterViewModel>? ReadList(MasterSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Login:{Login}.Id:{ Id}", model?.Login, model?.Id);
|
||||
var list = model == null ? _MasterStorage.GetFullList() : _MasterStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public MasterViewModel? ReadElement(MasterSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Login:{Login}. Id:{ Id}", model.Login, model.Id);
|
||||
var element = _MasterStorage.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(MasterBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MasterStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MasterBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MasterStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MasterBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_MasterStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MasterBindingModel 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.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Не задано ФИО", nameof(model.Name));
|
||||
}
|
||||
_logger.LogInformation("Master. Name:{Name}.Email{Email}.Login{Login}.Password{Password} Id: {Id}", model.Name, model.Email, model.Login, model.Password, model.Id);
|
||||
var element = _MasterStorage.GetElement(new MasterSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Поручитель с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FurnitureContracts.BindingModels;
|
||||
using FurnitureContracts.BusinessLogicsContracts;
|
||||
using FurnitureContracts.SearchModels;
|
||||
using FurnitureContracts.StoragesContracts;
|
||||
using FurnitureContracts.ViewModel;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FurnitureFactoryBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MaterialLogic : IMaterialLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMaterialStorage _materialStorage;
|
||||
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage materialStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_materialStorage = materialStorage;
|
||||
}
|
||||
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public MaterialViewModel? ReadElement(MaterialSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
|
||||
var element = _materialStorage.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(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_materialStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_materialStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_materialStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MaterialBindingModel 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.Cost.ToString()))
|
||||
{
|
||||
throw new ArgumentNullException("Не задана цена", nameof(model.Cost));
|
||||
}
|
||||
if (model.MasterId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Неверно задан идентификатор поручителя", nameof(model.MasterId));
|
||||
}
|
||||
_logger.LogInformation("Material. Titel:{Name}.Cost{Cost}.MasterId:{MasterId}. Id: {Id}", model.Name, model.Cost, model.MasterId, model.Id);
|
||||
var element = _materialStorage.GetElement(new MaterialSearchModel
|
||||
{
|
||||
Name = model.Name,
|
||||
MasterId = model.MasterId
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Материалы с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user