2023-03-28 17:32:55 +04:00
|
|
|
|
using BeautySaloonContracts.BindingModels;
|
|
|
|
|
using BeautySaloonContracts.BusinessLogicsContracts;
|
|
|
|
|
using BeautySaloonContracts.SearchModels;
|
|
|
|
|
using BeautySaloonContracts.StoragesContracts;
|
|
|
|
|
using BeautySaloonContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace BeautySaloonBusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ServiceLogic : IServiceLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceStorage _serviceStorage;
|
|
|
|
|
public ServiceLogic(IServiceStorage serviceStorage)
|
|
|
|
|
{
|
|
|
|
|
_serviceStorage = serviceStorage;
|
|
|
|
|
}
|
|
|
|
|
public bool Create(ServiceBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_serviceStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Delete(ServiceBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
if (_serviceStorage.Delete(model) == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServiceViewModel? ReadElement(ServiceSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
var element = _serviceStorage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
var list = model == null ? _serviceStorage.GetFullList() :
|
|
|
|
|
_serviceStorage.GetFilteredList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 13:59:00 +04:00
|
|
|
|
public List<ReportViewModel>? ReadMostPopular()
|
|
|
|
|
{
|
|
|
|
|
var list = _serviceStorage.ReadMostPopular();
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 17:32:55 +04:00
|
|
|
|
public bool Update(ServiceBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_serviceStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(ServiceBindingModel 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));
|
|
|
|
|
}
|
|
|
|
|
var element = _serviceStorage.GetElement(new ServiceSearchModel
|
|
|
|
|
{
|
|
|
|
|
Name = model.Name
|
|
|
|
|
});
|
|
|
|
|
if (element != null && element.Id != model.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Услуга с таким названием уже есть");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|