using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.IO.Packaging; namespace HotelRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class MainController : Controller { private readonly ILogger _logger; private readonly IConferenceLogic _conference; private readonly IMemberLogic _member; private readonly IMealPlanLogic _mealPlan; private readonly IDinnerLogic _dinner; private readonly IConferenceBookingLogic _conferenceBooking; private readonly IRoomLogic _room; public MainController(ILogger logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan, IDinnerLogic dinner, IConferenceBookingLogic conferenceBooking, IRoomLogic room) { _logger = logger; _conference = conference; _member = member; _mealPlan = mealPlan; _dinner = dinner; _conferenceBooking = conferenceBooking; _room = room; } [HttpGet] public List? GetConferenceList(int organiserId) { try { return _conference.ReadList(new ConferenceSearchModel { OrganiserId = organiserId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка конференций"); throw; } } [HttpGet] public List? GetMemberList(int organiserId) { try { return _member.ReadList(new MemberSearchModel { OrganiserId= organiserId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка участников"); throw; } } [HttpGet] public List? GetMealPlanList(int organiserId) { try { return _mealPlan.ReadList(new MealPlanSearchModel { OrganiserId=organiserId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка планов питания"); throw; } } [HttpGet] public List? GetDinnerList(int headwaiterId) { try { return _dinner.ReadList(new DinnerSearchModel { //HeadwaiterId = headwaiterId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка обедов"); throw; } } [HttpGet] public List? GetConferenceBookingList(int headwaiterId) { try { return _conferenceBooking.ReadList(new ConferenceBookingSearchModel { HeadwaiterId = headwaiterId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка бронирования по конференциям"); throw; } } [HttpGet] public List? GetRoomPlanList(int headwaiterId) { try { return _room.ReadList(new RoomSearchModel { //HeadwaiterId = headwaiterId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка номеров"); throw; } } [HttpPost] public void UpdateMember(MemberBindingModel model) { try { _member.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления данных"); throw; } } [HttpGet] public MemberViewModel? GetMember(int memberId) { try { return _member.ReadElement(new MemberSearchModel { Id = memberId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения участника по id={Id}", memberId); throw; } } [HttpPost] public void CreateMember(MemberBindingModel model) { try { _member.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания участника"); throw; } } [HttpPost] public void DeleteMember(MemberBindingModel model) { try { _member.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления участника"); throw; } } [HttpPost] public void UpdateDinner(DinnerBindingModel model) { try { _dinner.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления данных обеда"); throw; } } [HttpGet] public DinnerViewModel? GetDinner(int dinnerId) { try { return _dinner.ReadElement(new DinnerSearchModel { Id = dinnerId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения обеда по id={Id}", dinnerId); throw; } } [HttpPost] public void CreateDinner(DinnerBindingModel model) { try { _dinner.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания обеда"); throw; } } [HttpPost] public void DeleteDinner(DinnerBindingModel model) { try { _dinner.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления обеда"); throw; } } [HttpPost] public void CreateConference(ConferenceBindingModel model) { try { _conference.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания конференции"); throw; } } [HttpPost] public void CreateMealPlan(MealPlanBindingModel model) { try { _mealPlan.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания плана питания"); throw; } } [HttpPost] public void CreateRoom(RoomBindingModel model) { try { _room.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания комнаты"); throw; } } [HttpPost] public void CreateConferenceBooking(ConferenceBookingBindingModel model) { try { _conferenceBooking.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания бронирования конференций"); throw; } } } }