Готовая бизнес логика для админа
This commit is contained in:
parent
875f1c4911
commit
5631b888f8
@ -92,14 +92,14 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(AdministratorBindingModel model, bool Parametrs = true)
|
||||
private void CheckModel(AdministratorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!Parametrs)
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -131,7 +131,8 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Пароль превышает допустимое количество символов", nameof(model.AdministratorPassword));
|
||||
}
|
||||
_logger.LogInformation("Administrator. AdministratorFIO: {AdministratorFIO}. AdministratorLogin: {AdministratorLogin}. Id: {Id}", model.AdministratorFIO, model.AdministratorLogin, model.Id);
|
||||
_logger.LogInformation("Administrator. AdministratorFIO: {AdministratorFIO}. AdministratorLogin: {AdministratorLogin}. AdministratorPhone: {AdministratorPhone}.AdministratorEmail: {AdministratorEmail}.AdministratorPassword: {AdministratorPassword}.Id: {Id}",
|
||||
model.AdministratorFIO, model.AdministratorLogin, model.AdministratorPhone, model.AdministratorEmail, model.AdministratorPassword, model.Id);
|
||||
|
||||
var elementEmail = _administratorStorage.GetElement(new AdministratorSearchModel
|
||||
{
|
||||
@ -139,7 +140,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
});
|
||||
if (elementEmail != null && elementEmail.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("администратор с такой почтой уже есть");
|
||||
throw new InvalidOperationException("Администратор с такой почтой уже есть");
|
||||
}
|
||||
|
||||
var elementPhone = _administratorStorage.GetElement(new AdministratorSearchModel
|
||||
@ -148,7 +149,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
});
|
||||
if (elementPhone != null && elementPhone.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("администратор с таким номером уже есть");
|
||||
throw new InvalidOperationException("Администратор с таким номером уже есть");
|
||||
}
|
||||
|
||||
var elementLogin = _administratorStorage.GetElement(new AdministratorSearchModel
|
||||
@ -157,7 +158,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
});
|
||||
if (elementLogin != null && elementLogin.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("администратор с таким логином уже есть");
|
||||
throw new InvalidOperationException("Администратор с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,6 +14,108 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ConferenceBookingLogic : IConferenceBookingLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConferenceBookingStorage _conferenceBookingStorage;
|
||||
public ConferenceBookingLogic(ILogger<ConferenceBookingLogic> logger, IConferenceBookingStorage conferenceBookingStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_conferenceBookingStorage = conferenceBookingStorage;
|
||||
}
|
||||
public List<ConferenceBookingViewModel>? ReadList(ConferenceBookingSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
|
||||
var list = model == null ? _conferenceBookingStorage.GetFullList() : _conferenceBookingStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
public ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
|
||||
var element = _conferenceBookingStorage.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(ConferenceBookingBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_conferenceBookingStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Update(ConferenceBookingBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_conferenceBookingStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ConferenceBookingBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_conferenceBookingStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ConferenceBookingBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.PlaceСonference))
|
||||
{
|
||||
throw new ArgumentNullException("Нет места конференции", nameof(model.PlaceСonference));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ConferenceBooking. PlaceСonference:{PlaceСonference}. Id: { Id}", model.PlaceСonference, model.Id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,5 +14,115 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class DinnerLogic : IDinnerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDinnerStorage _dinnerStorage;
|
||||
public DinnerLogic(ILogger<DinnerLogic> logger, IDinnerStorage dinnerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_dinnerStorage = dinnerStorage;
|
||||
}
|
||||
public List<DinnerViewModel>? ReadList(DinnerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DinnerName:{DinnerName}.Id:{ Id}", model?.DinnerName, model?.Id);
|
||||
|
||||
var list = model == null ? _dinnerStorage.GetFullList() : _dinnerStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
public DinnerViewModel? ReadElement(DinnerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. DinnerName:{DinnerName}.Id:{Id}", model.DinnerName, model.Id);
|
||||
|
||||
var element = _dinnerStorage.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(DinnerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_dinnerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Update(DinnerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_dinnerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Delete(DinnerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_dinnerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(DinnerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.DinnerName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени обеда", nameof(model.DinnerName));
|
||||
}
|
||||
|
||||
if (model.DinnerPrice < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость обеда не может быть меньше 0", nameof(model.DinnerPrice));
|
||||
}
|
||||
if (model.DinnerСalorieСontent < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Калорийность обеда не может быть меньше 0", nameof(model.DinnerСalorieСontent));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Dinner. DinnerName:{DinnerName}.DinnerPrice:{DinnerPrice}.DinnerСalorieСontent:{DinnerСalorieСontent}. Id: { Id}", model.DinnerName, model.DinnerPrice, model.DinnerСalorieСontent, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,6 +14,116 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class RoomLogic : IRoomLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRoomStorage _roomStorage;
|
||||
public RoomLogic(ILogger<RoomLogic> logger, IRoomStorage roomStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_roomStorage = roomStorage;
|
||||
}
|
||||
public List<RoomViewModel>? ReadList(RoomSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. RoomNumber:{RoomNumber}.Id:{ Id}", model?.RoomNumber, model?.Id);
|
||||
|
||||
var list = model == null ? _roomStorage.GetFullList() : _roomStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
public RoomViewModel? ReadElement(RoomSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. RoomNumber:{RoomNumber}.Id:{Id}", model.RoomNumber, model.Id);
|
||||
|
||||
var element = _roomStorage.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(RoomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_roomStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Update(RoomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_roomStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Delete(RoomBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_roomStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(RoomBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.RoomNumber < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Номер комнаты не может быть меньше 0", nameof(model.RoomNumber));
|
||||
}
|
||||
if (model.CountBeds < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество спальных мест не может быть меньше 0", nameof(model.CountBeds));
|
||||
}
|
||||
if (model.RoomPrice < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена комнаты не может быть меньше 0", nameof(model.RoomPrice));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Room. RoomNumber:{RoomNumber}.CountBeds:{CountBeds}.RoomPrice:{RoomPrice}. Id: {Id}", model.RoomNumber, model.CountBeds, model.RoomPrice, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user