146 lines
4.5 KiB
C#
146 lines
4.5 KiB
C#
|
using HotelContracts.BindingModels;
|
|||
|
using HotelContracts.BusinessLogicsContracts;
|
|||
|
using HotelContracts.SearchModels;
|
|||
|
using HotelContracts.ViewModels;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace HotelRestApi.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]/[action]")]
|
|||
|
[ApiController]
|
|||
|
public class ConferenceBookingController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IConferenceBookingLogic _conferenceBooking;
|
|||
|
|
|||
|
public ConferenceBookingController(ILogger<ConferenceBookingController> logger, IConferenceBookingLogic conferenceBooking)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_conferenceBooking = conferenceBooking;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
|
|||
|
{
|
|||
|
HeadwaiterId = headwaiterId,
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка бронирования по конференции");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public ConferenceBookingViewModel? GetConferenceBookingById(int conferenceBookingId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel
|
|||
|
{
|
|||
|
Id = conferenceBookingId
|
|||
|
});
|
|||
|
|
|||
|
if (elem == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return elem;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public Tuple<ConferenceBookingViewModel, List<Tuple<string, double>>>? GetConferenceBooking(int conferenceBookingId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel
|
|||
|
{
|
|||
|
Id = conferenceBookingId
|
|||
|
});
|
|||
|
|
|||
|
if (elem == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return Tuple.Create(elem, elem.ConferenceBookingLunches.Select(x => Tuple.Create(x.Value.LunchName, x.Value.LunchPrice)).ToList());
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_conferenceBooking.Create(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка создания бронирования по конференции");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void UpdateConferenceBooking(ConferenceBookingBindingModel model)
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
model.ConferenceBookingLunches = null!;
|
|||
|
_conferenceBooking.Update(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка обновления данных бронирования по конференции");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void DeleteConferenceBooking(ConferenceBookingBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_conferenceBooking.Delete(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка удаления бронирования по конференции");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void AddLunchToConferenceBooking(Tuple<ConferenceBookingSearchModel, LunchViewModel> model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_conferenceBooking.AddLunchToConferenceBooking(model.Item1, model.Item2);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка добавления обеда в бронирование по конференции.");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|