100 lines
2.7 KiB
C#
100 lines
2.7 KiB
C#
|
using HotelContracts.BindingModels;
|
|||
|
using HotelContracts.BusinessLogicsContracts;
|
|||
|
using HotelContracts.SearchModels;
|
|||
|
using HotelContracts.StoragesContracts;
|
|||
|
using HotelContracts.ViewModels;
|
|||
|
using HotelDataModels.Enums;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace HotelBusinessLogic
|
|||
|
{
|
|||
|
public class BookingLogic : IBookingLogic
|
|||
|
{
|
|||
|
private readonly IBookingStorage _bookingStorage;
|
|||
|
|
|||
|
public BookingLogic(IBookingStorage bookingStorage)
|
|||
|
{
|
|||
|
_bookingStorage = bookingStorage;
|
|||
|
}
|
|||
|
public BookingViewModel? ReadElement(BookingSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
|
|||
|
var element = _bookingStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public List<BookingViewModel>? ReadList(BookingSearchModel? model)
|
|||
|
{
|
|||
|
var list = model == null ? _bookingStorage.GetFullList() : _bookingStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(BookingBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_bookingStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(BookingBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_bookingStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(BookingBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_bookingStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(BookingBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (model.RoomId <= 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Некорректный идентификатор комнаты", nameof(model.RoomId));
|
|||
|
}
|
|||
|
if (model.ClientId <= 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Некорректный идентификатор клиента", nameof(model.ClientId));
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|