плаки плаки или нормалдаки

This commit is contained in:
ChaZIR 2024-04-30 14:41:37 +04:00
parent 006d72ab85
commit a147d23353
6 changed files with 503 additions and 6 deletions

View File

@ -3,10 +3,135 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TravelCompanyContracts.BusinessLogicsContracts.Contractor;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor
{
internal class ContractorLogic
public class ContractorLogic : IContractorLogic
{
private readonly ILogger _logger;
private readonly IContractorStorage _contractorStorage;
public ContractorLogic(ILogger<ContractorLogic> logger, IContractorStorage contractorStorage)
{
_logger = logger;
_contractorStorage = contractorStorage;
}
public List<ContractorViewModel>? ReadList(ContractorSearchModel? model)
{
_logger.LogInformation("ReadList. Surname: {Surname}. Name: {Name}. Patronymic: {Patronymic}. Id: {Id} ", model?.Surname, model?.Name, model?.Patronymic, model?.Id);
var list = (model == null) ? _contractorStorage.GetFullList() : _contractorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ContractorViewModel? ReadElement(ContractorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. User id: {Id}, User email: {Email}, User mobile phone: {MobilePhone}, User password: {Password}", model?.Id, model?.Email, model?.MobilePhone, model?.Password);
var element = _contractorStorage.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(ContractorBindingModel model)
{
CheckModel(model);
if (_contractorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ContractorBindingModel model)
{
CheckModel(model);
if (_contractorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ContractorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_contractorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ContractorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Surname))
{
throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Surname));
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Patronymic))
{
throw new ArgumentNullException("Нет отчества пользователя", nameof(model.Patronymic));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.MobilePhone))
{
throw new ArgumentNullException("Нет номера телефона пользователя", nameof(model.MobilePhone));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
_logger.LogInformation("User. Id: {id}, Surname: {Surname}, Name: {Name}, Patronymic: {Patronymic} Email: {Email}, Mobile Phone: {MobilePhone}, Password: {Password}", model.Id, model.Surname, model.Name, model.Patronymic, model.Email, model.MobilePhone, model.Password);
var element = _contractorStorage.GetElement(new ContractorSearchModel
{
Email = model.Email,
MobilePhone = model.MobilePhone,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Пользователь с такими почтой или номером телефона уже есть");
}
}
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TravelCompanyContracts.BusinessLogicsContracts.Contractor;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor
{
public class ExcursionGroupLogic : IExcursionGroupLogic
{
private readonly ILogger _logger;
private readonly IExcursionGroupStorage _excursionGroupStorage;
public ExcursionGroupLogic(ILogger<ExcursionGroupLogic> logger, IExcursionGroupStorage excursionGroupStorage)
{
_logger = logger;
_excursionGroupStorage = excursionGroupStorage;
}
public List<ExcursionGroupViewModel>? ReadList(ExcursionGroupSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}, ExcursionGroupName: {ExcursionGroupName}, ContractorID: {ContractorID}.", model?.Id, model?.ExcursionGroupName, model?.ContractorID);
var list = (model == null) ? _excursionGroupStorage.GetFullList() : _excursionGroupStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ExcursionGroupViewModel? ReadElement(ExcursionGroupSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}, ExcursionGroup name: {ExcursionGroupName}", model?.Id, model?.ExcursionGroupName);
var element = _excursionGroupStorage.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(ExcursionGroupBindingModel model)
{
CheckModel(model);
if (_excursionGroupStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ExcursionGroupBindingModel model)
{
CheckModel(model);
if (_excursionGroupStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ExcursionGroupBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_excursionGroupStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ExcursionGroupBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ExcursionGroupName))
{
throw new ArgumentNullException("Нет названия группы", nameof(model.ExcursionGroupName));
}
if (model.PeopleAmount <= 0)
{
throw new ArgumentNullException("Количество участников быть больше 0", nameof(model.PeopleAmount));
}
if (model.ContractorID <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор исполнителя", nameof(model.ContractorID));
}
_logger.LogInformation("ExcursionGroup. Id: {id}, ExcursionGroupName: {ExcursionGroupName}, PeopleAmount: {PeopleAmount}, ContractorID: {ContractorID}", model.Id, model.ExcursionGroupName, model.PeopleAmount, model.ContractorID);
var element = _excursionGroupStorage.GetElement(new ExcursionGroupSearchModel
{
ExcursionGroupName = model.ExcursionGroupName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Группа с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TravelCompanyContracts.BusinessLogicsContracts.Contractor;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor
{
public class ExcursionLogic : IExcursionLogic
{
private readonly ILogger _logger;
private readonly IExcursionStorage _excursionStorage;
public ExcursionLogic(ILogger<ExcursionLogic> logger, IExcursionStorage excursionStorage)
{
_logger = logger;
_excursionStorage = excursionStorage;
}
public List<ExcursionViewModel>? ReadList(ExcursionSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}, ExcursionName: {ExcursionName}, ContractorID: {ContractorID}.", model?.Id, model?.ExcursionName, model?.ContractorID);
var list = (model == null) ? _excursionStorage.GetFullList() : _excursionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ExcursionViewModel? ReadElement(ExcursionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Excursion id: {Id}, Excursion name: {ExcursionName}", model?.Id, model?.ExcursionName);
var element = _excursionStorage.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(ExcursionBindingModel model)
{
CheckModel(model);
if (_excursionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ExcursionBindingModel model)
{
CheckModel(model);
if (_excursionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ExcursionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_excursionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ExcursionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ExcursionName))
{
throw new ArgumentNullException("Нет названия экскурсии", nameof(model.ExcursionName));
}
if (model.ExcursionPrice <= 0)
{
throw new ArgumentNullException("Цена экскурсии должна быть больше 0", nameof(model.ExcursionPrice));
}
if (model.ContractorID <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор исполнителя", nameof(model.ContractorID));
}
_logger.LogInformation("Excursion. Id: {id}, ExcursionName: {ExcursionName}, ExcursionPrice: {ExcursionPrice}, ContractorID: {ContractorID}", model.Id, model.ExcursionName, model.ExcursionPrice, model.ContractorID);
var element = _excursionStorage.GetElement(new ExcursionSearchModel
{
ExcursionName = model.ExcursionName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Экскурсия с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TravelCompanyContracts.BusinessLogicsContracts.Contractor;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic.Contractor
{
public class TourLogic : ITourLogic
{
private readonly ILogger _logger;
private readonly ITourStorage _tourStorage;
public TourLogic(ILogger<TourLogic> logger, ITourStorage tourStorage)
{
_logger = logger;
_tourStorage = tourStorage;
}
public List<TourViewModel>? ReadList(TourSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}, TourName: {TourName}, ContractorID: {ContractorID}.", model?.Id, model?.TourName, model?.ContractorID);
var list = (model == null) ? _tourStorage.GetFullList() : _tourStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public TourViewModel? ReadElement(TourSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}, Tour name: {TourName}", model?.Id, model?.TourName);
var element = _tourStorage.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(TourBindingModel model)
{
CheckModel(model);
if (_tourStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(TourBindingModel model)
{
CheckModel(model);
if (_tourStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(TourBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_tourStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(TourBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.TourName))
{
throw new ArgumentNullException("Нет названия тура", nameof(model.TourName));
}
if (model.TourDate == DateTime.MinValue)
{
throw new ArgumentNullException("Нет даты тура", nameof(model.TourDate));
}
if (model.ContractorID <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор исполнителя", nameof(model.ContractorID));
}
_logger.LogInformation("Tour. Id: {id}, TourName: {TourName}, ContractorID: {ContractorID}", model.Id, model.TourName, model.ContractorID);
var element = _tourStorage.GetElement(new TourSearchModel
{
TourName = model.TourName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Тур с таким названием уже есть");
}
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
namespace TravelCompanyContracts.BusinessLogicsContracts.Contractor
{

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
@ -14,8 +14,8 @@ namespace TravelCompanyContracts.StoragesModels.Contractor
List<ContractorViewModel> GetFullList();
List<ContractorViewModel> GetFilteredList(ContractorSearchModel model);
ContractorViewModel? GetElement(ContractorSearchModel model);
ContractorViewModel? Insert(ContractorSearchModel model);
ContractorViewModel? Update(ContractorSearchModel model);
ContractorViewModel? Delete(ContractorSearchModel model);
ContractorViewModel? Insert(ContractorBindingModel model);
ContractorViewModel? Update(ContractorBindingModel model);
ContractorViewModel? Delete(ContractorBindingModel model);
}
}