139 lines
3.9 KiB
C#
139 lines
3.9 KiB
C#
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;
|
|
|
|
public MainController(ILogger<MainController> logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan)
|
|
{
|
|
_logger = logger;
|
|
_conference = conference;
|
|
_member = member;
|
|
_mealPlan = mealPlan;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<ConferenceViewModel>? GetConferenceList(int organiserId)
|
|
{
|
|
try
|
|
{
|
|
return _conference.ReadList(new ConferenceSearchModel
|
|
{
|
|
OrganiserId = organiserId,
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка конференций");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<MemberViewModel>? GetMemberList(int organiserId)
|
|
{
|
|
try
|
|
{
|
|
return _member.ReadList(new MemberSearchModel
|
|
{
|
|
OrganiserId= organiserId,
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка участников");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<MealPlanViewModel>? GetMealPlanList(int organiserId)
|
|
{
|
|
try
|
|
{
|
|
return _mealPlan.ReadList(new MealPlanSearchModel
|
|
{
|
|
OrganiserId=organiserId,
|
|
});
|
|
}
|
|
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 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;
|
|
}
|
|
}
|
|
}
|
|
}
|