Add logic

This commit is contained in:
Viltskaa 2023-04-07 00:11:08 +04:00
parent 983edf0994
commit 767ea158e8
8 changed files with 492 additions and 0 deletions

View File

@ -0,0 +1,78 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataModels.Models;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class CleaningInstrumentsLogic : ICleaningInstrumentsLogic
{
private readonly ICleaningInstrumentsStorage _cleaningInstruments;
private readonly ILogger _logger;
public CleaningInstrumentsLogic(ICleaningInstrumentsStorage cleaningInstruments, ILogger logger)
{
_cleaningInstruments = cleaningInstruments;
_logger = logger;
}
public List<CleaningInstrumentsViewModel>? ReadList(CleaningInstrumentsSearchModel? model)
{
var list = model == null ? _cleaningInstruments.GetFullList() : _cleaningInstruments.GetFilteredList(model);
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
return list;
}
public CleaningInstrumentsViewModel? ReadElement(CleaningInstrumentsSearchModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
var element = _cleaningInstruments.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(CleaningInstrumentsBindingModel model)
{
CheckModel(model);
if (_cleaningInstruments.Insert(model) != null) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(CleaningInstrumentsBindingModel model)
{
CheckModel(model);
if (_cleaningInstruments.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(CleaningInstrumentsBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_cleaningInstruments.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(CleaningInstrumentsBindingModel? model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (string.IsNullOrEmpty(model.Type))
throw new ArgumentException("Type must be not null");
}
}

View File

@ -0,0 +1,77 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class CleaningLogic : ICleaningLogic
{
private readonly ICleaningStorage _cleaningStorage;
private readonly ILogger _logger;
public CleaningLogic(ICleaningStorage cleaningStorage, ILogger<MaitreLogic> logger)
{
_logger = logger;
_cleaningStorage = cleaningStorage;
}
public List<CleaningViewModel>? ReadList(CleaningSearchModel? model)
{
var list = model == null ? _cleaningStorage.GetFullList() : _cleaningStorage.GetFilteredList(model);
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
return list;
}
public CleaningViewModel? ReadElement(CleaningSearchModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
var element = _cleaningStorage.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(CleaningBindingModel model)
{
CheckModel(model);
if (_cleaningStorage.Insert(model) != null) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(CleaningBindingModel model)
{
CheckModel(model);
if (_cleaningStorage.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(CleaningBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_cleaningStorage.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(CleaningBindingModel? model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (model.RoomId < 0)
throw new ArgumentException("RoomId must be more then 0");
}
}

View File

@ -0,0 +1,81 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class GuestLogic : IGuestLogic
{
private readonly IGuestStorage _guestStorage;
private readonly ILogger _logger;
public GuestLogic(IGuestStorage guestStorage, ILogger<GuestLogic> logger)
{
_logger = logger;
_guestStorage = guestStorage;
}
public List<GuestViewModel>? ReadList(GuestSearchModel? model)
{
var list = model == null ? _guestStorage.GetFullList() : _guestStorage.GetFilteredList(model);
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
return list;
}
public GuestViewModel? ReadElement(GuestSearchModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
var element = _guestStorage.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(GuestBindingModel model)
{
CheckModel(model);
if (_guestStorage.Insert(model) != null) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(GuestBindingModel model)
{
CheckModel(model);
if (_guestStorage.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(GuestBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_guestStorage.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(GuestBindingModel? model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (string.IsNullOrEmpty(model.Name))
throw new ArgumentException("Name must be not null");
if (string.IsNullOrEmpty(model.SecondName))
throw new ArgumentException("Second name must be not null");
if (string.IsNullOrEmpty(model.LastName))
throw new ArgumentException("Last name must be not null");
}
}

View File

@ -0,0 +1,88 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class MaitreLogic : IMaitreLogic
{
private readonly IMaitreStorage _maitreStorage;
private readonly ILogger _logger;
public MaitreLogic(IMaitreStorage maitreLogic, ILogger<MaitreLogic> logger)
{
_logger = logger;
_maitreStorage = maitreLogic;
}
public List<MaitreViewModel>? ReadList(MaitreSearchModel? model)
{
var list = model == null ? _maitreStorage.GetFullList() : _maitreStorage.GetFilteredList(model);
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
return list;
}
public MaitreViewModel? ReadElement(MaitreSearchModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
var element = _maitreStorage.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(MaitreBindingModel model)
{
CheckModel(model);
if (_maitreStorage.Insert(model) != null) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(MaitreBindingModel model)
{
CheckModel(model);
if (_maitreStorage.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(MaitreBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_maitreStorage.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(MaitreBindingModel? model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (string.IsNullOrEmpty(model.Name))
throw new ArgumentException("Name must be not null");
if (string.IsNullOrEmpty(model.SecondName))
throw new ArgumentException("Second name must be not null");
if (string.IsNullOrEmpty(model.LastName))
throw new ArgumentException("Last name must be not null");
var Maitre = _maitreStorage.GetElement(new MaitreSearchModel {
Login = model.Login
});
if (Maitre != null && Maitre.Id != model.Id)
{
throw new InvalidOperationException("Login is already exists");
}
}
}

View File

@ -0,0 +1,76 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class ReservationLogic : IReservationLogic
{
private readonly ILogger _logger;
private readonly IReservationStorage _reservationStorage;
public ReservationLogic(IReservationStorage reservationStorage, ILogger<ReservationLogic> logger)
{
_logger = logger;
_reservationStorage = reservationStorage;
}
public List<ReservationViewModel>? ReadList(ReservationSearchModel? model)
{
var list = model == null ? _reservationStorage.GetFullList() : _reservationStorage.GetFilteredList(model);
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
return list;
}
public ReservationViewModel? ReadElement(ReservationSearchModel model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
var element = _reservationStorage.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(ReservationBindingModel model)
{
CheckModel(model);
if (_reservationStorage.Insert(model) != null) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(ReservationBindingModel model)
{
CheckModel(model);
if (_reservationStorage.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(ReservationBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_reservationStorage.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(ReservationBindingModel? model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (model.StartDate > model.EndDate)
throw new ArgumentException("Start date must be early then end date");
_logger.LogInformation("Reservation .Id:{Id}", model.Id);
}
}

View File

@ -0,0 +1,80 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics;
public class RoomLogic : IRoomLogic
{
private readonly IRoomStorage _roomStorage;
private readonly ILogger _logger;
public RoomLogic(IRoomStorage roomStorage, ILogger<RoomLogic> logger)
{
_logger = logger;
_roomStorage = roomStorage;
}
public List<RoomViewModel>? ReadList(RoomSearchModel? model)
{
var list = model == null ? _roomStorage.GetFullList() : _roomStorage.GetFilteredList(model);
_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 .Id:{Id} .Type:{Type} .Cost:{Cost}",
model.Id, model.Type, model.Cost);
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) return true;
_logger.LogWarning("Insert operation failed");
return false;
}
public bool Update(RoomBindingModel model)
{
CheckModel(model);
if (_roomStorage.Update(model) != null) return true;
_logger.LogWarning("Update operation failed");
return false;
}
public bool Delete(RoomBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Delete .Id:{Id}", model.Id);
if (_roomStorage.Delete(model) != null) return true;
_logger.LogWarning("Delete operation failed");
return false;
}
private void CheckModel(RoomBindingModel? model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (string.IsNullOrEmpty(model.Type))
throw new ArgumentException("Type must be not null");
_logger.LogInformation("Room .Id:{Id} .Type:{Type} .Cost:{Cost}",
model.Id, model.Type, model.Cost);
}
}

View File

@ -6,4 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0-preview.2.23128.3" />
</ItemGroup>
</Project>

View File

@ -6,4 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-preview.2.23128.3" />
</ItemGroup>
</Project>