2024-05-03 22:05:00 +04:00
|
|
|
|
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;
|
|
|
|
|
|
2024-05-03 22:06:10 +04:00
|
|
|
|
namespace HotelBusinessLogic.BusinessLogics
|
2024-05-03 22:05:00 +04:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
2024-05-06 22:26:50 +04:00
|
|
|
|
public bool TakeBookingInWork(BookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ChangeStatus(model, AcceptanceStatus.Обработка);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FinishBooking(BookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ChangeStatus(model, AcceptanceStatus.Принимается);
|
|
|
|
|
}
|
2024-05-03 22:05:00 +04:00
|
|
|
|
|
2024-05-06 22:26:50 +04:00
|
|
|
|
public bool DeliveryBooking(BookingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return ChangeStatus(model, AcceptanceStatus.Принят);
|
|
|
|
|
}
|
2024-05-03 22:05:00 +04:00
|
|
|
|
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));
|
|
|
|
|
}
|
2024-05-06 22:26:50 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private bool ChangeStatus(BookingBindingModel model, AcceptanceStatus newStatus)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
if (model.Status + 1 != newStatus)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
model.Status = newStatus;
|
|
|
|
|
if (_bookingStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
model.Status--;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-05-03 22:05:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|