diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs index c8d2e8e..de9c52c 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceBookingLogic.cs @@ -58,39 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics return element; } - public bool AddLunchToConferenceBooking(ConferenceBookingSearchModel model, ILunchModel lunch) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - _logger.LogInformation("AddLunchToConferenceBooking. NameHall:{NameHall}.Id:{ Id}", model.NameHall, model.Id); - var element = _conferenceBookingStorage.GetElement(model); - - if (element == null) - { - _logger.LogWarning("AddLunchToConferenceBooking element not found"); - return false; - } - - _logger.LogInformation("AddLunchToConferenceBooking find. Id:{Id}", element.Id); - - element.ConferenceBookingLunches[lunch.Id] = lunch; - - _conferenceBookingStorage.Update(new() - { - Id = element.Id, - NameHall = element.NameHall, - BookingDate = element.BookingDate, - ConferenceId = element.ConferenceId, - HeadwaiterId = element.HeadwaiterId, - ConferenceBookingLunches = element.ConferenceBookingLunches - }); - - return true; - } - public bool Create(ConferenceBookingBindingModel model) { CheckModel(model); diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs index b73247c..523d57d 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ConferenceLogic.cs @@ -58,38 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics return element; } - public bool AddMemberToConference(ConferenceSearchModel model, IMemberModel member) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - _logger.LogInformation("AddMemberToConference. ConferenceName:{ConferenceName}.Id:{ Id}", model.ConferenceName, model.Id); - var element = _conferenceStorage.GetElement(model); - - if (element == null) - { - _logger.LogWarning("AddMemberToConference element not found"); - return false; - } - - _logger.LogInformation("AddMemberToConference find. Id:{Id}", element.Id); - - element.ConferenceMembers[member.Id] = member; - - _conferenceStorage.Update(new() - { - Id = element.Id, - ConferenceName = element.ConferenceName, - StartDate = element.StartDate, - OrganiserId = element.OrganiserId, - ConferenceMembers = element.ConferenceMembers, - }); - - return true; - } - public bool Create(ConferenceBindingModel model) { CheckModel(model); diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs index 0d5408d..7fb8f5a 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/MealPlanLogic.cs @@ -58,38 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics return element; } - public bool AddMemberToMealPlan(MealPlanSearchModel model, IMemberModel member) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - _logger.LogInformation("AddMemberToMealPlan. MealPlanName:{MealPlanName}.Id:{ Id}", model.MealPlanName, model.Id); - var element = _mealPlanStorage.GetElement(model); - - if (element == null) - { - _logger.LogWarning("AddMemberToMealPlan element not found"); - return false; - } - - _logger.LogInformation("AddMemberToMealPlan find. Id:{Id}", element.Id); - - element.MealPlanMembers[member.Id] = member; - - _mealPlanStorage.Update(new() - { - Id = element.Id, - MealPlanName = element.MealPlanName, - MealPlanPrice = element.MealPlanPrice, - OrganiserId = element.OrganiserId, - MealPlanMembers = element.MealPlanMembers - }); - - return true; - } - public bool Create(MealPlanBindingModel model) { CheckModel(model); diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs index 32f0827..626688c 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceBookingLogic.cs @@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts { List? ReadList(ConferenceBookingSearchModel? model); ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model); - bool AddLunchToConferenceBooking(ConferenceBookingSearchModel model, ILunchModel lunch); bool Create(ConferenceBookingBindingModel model); bool Update(ConferenceBookingBindingModel model); bool Delete(ConferenceBookingBindingModel model); diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceLogic.cs index 9087010..38cdce6 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IConferenceLogic.cs @@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts { List? ReadList(ConferenceSearchModel? model); ConferenceViewModel? ReadElement(ConferenceSearchModel model); - bool AddMemberToConference(ConferenceSearchModel model, IMemberModel member); bool Create(ConferenceBindingModel model); bool Update(ConferenceBindingModel model); bool Delete(ConferenceBindingModel model); diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IMealPlanLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IMealPlanLogic.cs index 356d384..7b14c31 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IMealPlanLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IMealPlanLogic.cs @@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts { List? ReadList(MealPlanSearchModel? model); MealPlanViewModel? ReadElement(MealPlanSearchModel model); - bool AddMemberToMealPlan(MealPlanSearchModel model, IMemberModel member); bool Create(MealPlanBindingModel model); bool Update(MealPlanBindingModel model); bool Delete(MealPlanBindingModel model); diff --git a/Hotel/HotelContracts/ViewModels/ConferenceBookingViewModel.cs b/Hotel/HotelContracts/ViewModels/ConferenceBookingViewModel.cs index 7a5a70a..8b36dc4 100644 --- a/Hotel/HotelContracts/ViewModels/ConferenceBookingViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ConferenceBookingViewModel.cs @@ -19,13 +19,5 @@ namespace HotelContracts.ViewModels public Dictionary ConferenceBookingLunches { get; set; } public Dictionary ConferenceConferenceBookings { get; set; } = new(); - public ConferenceBookingViewModel() { } - - [JsonConstructor] - public ConferenceBookingViewModel(Dictionary ConferenceBookingLunches, Dictionary ConferenceConferenceBookings) - { - this.ConferenceBookingLunches = ConferenceBookingLunches.ToDictionary(x => x.Key, x => x.Value as ILunchModel); - this.ConferenceConferenceBookings = ConferenceConferenceBookings.ToDictionary(x => x.Key, x => x.Value as IConferenceBookingModel); - } } } \ No newline at end of file diff --git a/Hotel/HotelContracts/ViewModels/ConferenceViewModel.cs b/Hotel/HotelContracts/ViewModels/ConferenceViewModel.cs index c589074..d19e698 100644 --- a/Hotel/HotelContracts/ViewModels/ConferenceViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ConferenceViewModel.cs @@ -18,13 +18,5 @@ namespace HotelContracts.ViewModels public int OrganiserId { get; set; } public Dictionary ConferenceMembers { get; set; } = new(); - - public ConferenceViewModel() { } - - [JsonConstructor] - public ConferenceViewModel(Dictionary ConferenceMembers) - { - this.ConferenceMembers = ConferenceMembers.ToDictionary(x => x.Key, x => x.Value as IMemberModel); - } } } \ No newline at end of file diff --git a/Hotel/HotelContracts/ViewModels/MealPlanViewModel.cs b/Hotel/HotelContracts/ViewModels/MealPlanViewModel.cs index 7d24c48..4997bf6 100644 --- a/Hotel/HotelContracts/ViewModels/MealPlanViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/MealPlanViewModel.cs @@ -19,14 +19,5 @@ namespace HotelContracts.ViewModels public Dictionary MealPlanMembers { get; set; } = new(); public Dictionary MealPlanRooms { get; set; } = new(); - - public MealPlanViewModel() { } - - [JsonConstructor] - public MealPlanViewModel(Dictionary MealPlanMembers, Dictionary MealPlanRooms) - { - this.MealPlanMembers = MealPlanMembers.ToDictionary(x => x.Key, x => x.Value as IMemberModel); - this.MealPlanRooms = MealPlanRooms.ToDictionary(x => x.Key, x => x.Value as IRoomModel); - } } } \ No newline at end of file diff --git a/Hotel/HotelDataBaseImplement/Models/Conference.cs b/Hotel/HotelDataBaseImplement/Models/Conference.cs index 8d66ac9..d830920 100644 --- a/Hotel/HotelDataBaseImplement/Models/Conference.cs +++ b/Hotel/HotelDataBaseImplement/Models/Conference.cs @@ -28,10 +28,8 @@ namespace HotelDataBaseImplement.Models { if (_conferenceMembers == null) { - using var context = new HotelDataBase(); - _conferenceMembers = Members.ToDictionary(x => x.MemberId, x => (context.Members - .FirstOrDefault(y => y.Id == x.MemberId)! as IMemberModel)); - } + _conferenceMembers = Members.ToDictionary(x => x.MemberId, x => (x.Member as IMemberModel)); + } return _conferenceMembers; } } diff --git a/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs b/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs index 2469d52..84c03be 100644 --- a/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs +++ b/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs @@ -27,11 +27,8 @@ namespace HotelDataBaseImplement.Models { if (_conferenceBookingLunches == null) { - using var context = new HotelDataBase(); - _conferenceBookingLunches = Lunches - .ToDictionary(x => x.LunchId, x => (context.Lunches - .FirstOrDefault(y => y.Id == x.LunchId)! as ILunchModel)); - } + _conferenceBookingLunches = Lunches.ToDictionary(x => x.LunchId, x => (x.Lunch as ILunchModel)); + } return _conferenceBookingLunches; } } diff --git a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs index 6522e63..49a35c7 100644 --- a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs +++ b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs @@ -29,10 +29,8 @@ namespace HotelDataBaseImplement.Models { if (_mealPlanMembers == null) { - using var context = new HotelDataBase(); - _mealPlanMembers = Members.ToDictionary(x => x.MemberId, x => (context.Members - .FirstOrDefault(y => y.Id == x.MemberId)! as IMemberModel)); - } + _mealPlanMembers = Members.ToDictionary(x => x.MemberId, x => (x.Member as IMemberModel)); + } return _mealPlanMembers; } } diff --git a/Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs b/Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs index 3209675..089dba1 100644 --- a/Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs +++ b/Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs @@ -19,72 +19,55 @@ namespace HotelRestApi.Controllers _conferenceBooking = conferenceBooking; } - [HttpGet] - public List? GetConferenceBookingList(int headwaiterId) - { - try - { - return _conferenceBooking.ReadList(new ConferenceBookingSearchModel + [HttpGet] + public List? GetConferenceBookings(int? headwaiterId = null) + { + try + { + List res; + if (!headwaiterId.HasValue) { - HeadwaiterId = headwaiterId, - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка бронирования по конференции"); - throw; - } - } - - [HttpGet] - public ConferenceBookingViewModel? GetConferenceBookingById(int conferenceBookingId) - { - try - { - var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel - { - Id = conferenceBookingId - }); + res = _conferenceBooking.ReadList(null); + } + else + { + res = _conferenceBooking.ReadList(new ConferenceBookingSearchModel { HeadwaiterId = headwaiterId }); + } + foreach (var conferencebooking in res) + { + conferencebooking.ConferenceBookingLunches = null!; + } + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка бронирований по конференциям"); + throw; + } + } + [HttpGet] + public Tuple>? GetConferenceBooking(int conferencebookingId) + { + try + { + var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferencebookingId }); if (elem == null) { return null; } + var res = Tuple.Create(elem, elem.ConferenceBookingLunches.Select(x => x.Value.LunchName).ToList()); + res.Item1.ConferenceBookingLunches = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения бронирования по конференции по id={Id}", conferencebookingId); + throw; + } + } - return elem; - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId); - throw; - } - } - - [HttpGet] - public Tuple>>? 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] + [HttpPost] public void CreateConferenceBooking(ConferenceBookingBindingModel model) { try @@ -127,19 +110,5 @@ namespace HotelRestApi.Controllers throw; } } - - [HttpPost] - public void AddLunchToConferenceBooking(Tuple model) - { - try - { - _conferenceBooking.AddLunchToConferenceBooking(model.Item1, model.Item2); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка добавления обеда в бронирование по конференции."); - throw; - } - } } } diff --git a/Hotel/HotelRestApi/Controllers/ConferenceController.cs b/Hotel/HotelRestApi/Controllers/ConferenceController.cs index 15cf03c..20750df 100644 --- a/Hotel/HotelRestApi/Controllers/ConferenceController.cs +++ b/Hotel/HotelRestApi/Controllers/ConferenceController.cs @@ -2,6 +2,7 @@ using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; +using HotelDataBaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace HotelRestApi.Controllers @@ -19,59 +20,55 @@ namespace HotelRestApi.Controllers _conference = conference; } - [HttpGet] - public List? GetConferenceList(int organiserId) - { - try - { - return _conference.ReadList(new ConferenceSearchModel - { - OrganiserId = organiserId, - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка конференций"); - throw; - } - } + [HttpGet] + public List? GetConferences(int? organiserId = null) + { + try + { + List res; + if (!organiserId.HasValue) + { + res = _conference.ReadList(null); + } + else + { + res = _conference.ReadList(new ConferenceSearchModel { OrganiserId = organiserId }); + } + foreach (var conference in res) + { + conference.ConferenceMembers = null!; + } + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения конференций"); + throw; + } + } - [HttpGet] - public List? GetConferences() - { - try - { - return _conference.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка конференций"); - throw; - } - } + [HttpGet] + public Tuple>? GetConference(int conferenceId) + { + try + { + var elem = _conference.ReadElement(new ConferenceSearchModel { Id = conferenceId }); + if (elem == null) + { + return null; + } + var res = Tuple.Create(elem, elem.ConferenceMembers.Select(x => $"{x.Value.MemberSurname} {x.Value.MemberName} {x.Value.MemberPatronymic}").ToList()); + res.Item1.ConferenceMembers = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения конференции по id={Id}", conferenceId); + throw; + } + } - [HttpGet] - public Tuple>>? GetConference(int conferenceId) - { - try - { - var elem = _conference.ReadElement(new ConferenceSearchModel { Id = conferenceId }); - if (elem == null) - { - return null; - } - var members = elem.ConferenceMembers.Select(x => Tuple.Create($"{x.Value.MemberSurname} {x.Value.MemberName} {x.Value.MemberPatronymic}", x.Value.MemberPhoneNumber)).ToList(); - - return Tuple.Create(elem, members); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения конференции по id={Id}", conferenceId); - throw; - } - } - - [HttpPost] + [HttpPost] public void CreateConference(ConferenceBindingModel model) { try @@ -113,19 +110,5 @@ namespace HotelRestApi.Controllers throw; } } - - [HttpPost] - public void AddMemberToConference(Tuple model) - { - try - { - _conference.AddMemberToConference(model.Item1, model.Item2); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка добавления участника в конференцию."); - throw; - } - } } } diff --git a/Hotel/HotelRestApi/Controllers/LunchController.cs b/Hotel/HotelRestApi/Controllers/LunchController.cs index 2bab907..bc64b16 100644 --- a/Hotel/HotelRestApi/Controllers/LunchController.cs +++ b/Hotel/HotelRestApi/Controllers/LunchController.cs @@ -19,55 +19,43 @@ namespace HotelRestApi.Controllers _lunch = lunch; } - [HttpGet] - public List? GetLunchList(int headwaiterId) - { - try - { - return _lunch.ReadList(new LunchSearchModel + [HttpGet] + public List? GetLunches(int? headwaiterId = null) + { + try + { + if (!headwaiterId.HasValue) { - HeadwaiterId = headwaiterId, - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка обедов"); - throw; - } - } + return _lunch.ReadList(null); + } + return _lunch.ReadList(new LunchSearchModel + { + HeadwaiterId = headwaiterId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка обедов"); + throw; + } + } - [HttpGet] - public List? GetLunches() - { - try - { - return _lunch.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка обедов"); - throw; - } - } + [HttpGet] + public LunchViewModel GetLunch(int lunchId) + { + try + { + var elem = _lunch.ReadElement(new LunchSearchModel { Id = lunchId }); + return elem; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId); + throw; + } + } - [HttpGet] - public LunchViewModel? GetLunchById(int lunchId) - { - try - { - return _lunch.ReadElement(new LunchSearchModel - { - Id = lunchId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId); - throw; - } - } - - [HttpPost] + [HttpPost] public void CreateLunch(LunchBindingModel model) { try diff --git a/Hotel/HotelRestApi/Controllers/MealPlanController.cs b/Hotel/HotelRestApi/Controllers/MealPlanController.cs index 4933f15..a381bbc 100644 --- a/Hotel/HotelRestApi/Controllers/MealPlanController.cs +++ b/Hotel/HotelRestApi/Controllers/MealPlanController.cs @@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using HotelDataBaseImplement; +using HotelDataBaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace HotelRestApi.Controllers @@ -20,38 +21,46 @@ namespace HotelRestApi.Controllers _mealPlan = mealPlan; } - [HttpGet] - public List? GetMealPlanList(int organiserId) - { - try - { - return _mealPlan.ReadList(new MealPlanSearchModel - { - OrganiserId = organiserId, - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка планов питания"); - throw; - } - } - [HttpGet] - public Tuple>>? GetMealPlan(int mealPlanId) + public List? GetMealPlans(int? organiserId = null) + { + try + { + List res; + if (!organiserId.HasValue) + { + res = _mealPlan.ReadList(null); + } + else + { + res = _mealPlan.ReadList(new MealPlanSearchModel { OrganiserId = organiserId }); + } + foreach (var mealPlan in res) + { + mealPlan.MealPlanMembers = null!; + } + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения конференций"); + throw; + } + } + + [HttpGet] + public Tuple>? GetMealPlan(int mealPlanId) { try { - using var context = new HotelDataBase(); var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId }); if (elem == null) { return null; } - - var members = elem.MealPlanMembers.Select(x => Tuple.Create(x.Value.MemberSurname, x.Value.MemberName, x.Value.MemberPatronymic, x.Value.MemberPhoneNumber)).ToList(); - - return Tuple.Create(elem, members); + var res = Tuple.Create(elem, elem.MealPlanMembers.Select(x => $"{x.Value.MemberSurname} {x.Value.MemberName} {x.Value.MemberPatronymic}").ToList()); + res.Item1.MealPlanMembers = null!; + return res; } catch (Exception ex) { @@ -102,19 +111,5 @@ namespace HotelRestApi.Controllers throw; } } - - [HttpPost] - public void AddMemberToMealPlan(Tuple model) - { - try - { - _mealPlan.AddMemberToMealPlan(model.Item1, model.Item2); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка добавления участника в план питания."); - throw; - } - } } } diff --git a/Hotel/HotelRestApi/Controllers/MemberController.cs b/Hotel/HotelRestApi/Controllers/MemberController.cs index ef2d430..f8ad40a 100644 --- a/Hotel/HotelRestApi/Controllers/MemberController.cs +++ b/Hotel/HotelRestApi/Controllers/MemberController.cs @@ -2,6 +2,7 @@ using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; +using HotelDataBaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace HotelRestApi.Controllers @@ -19,41 +20,43 @@ namespace HotelRestApi.Controllers _member = member; } - [HttpGet] - public List? GetMemberList(int organiserId) - { - try - { - return _member.ReadList(new MemberSearchModel - { - OrganiserId = organiserId, - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка участников"); - throw; - } - } + [HttpGet] + public List? GetMembers(int? organiserId = null) + { + try + { + if (!organiserId.HasValue) + { + return _member.ReadList(null); + } + return _member.ReadList(new MemberSearchModel + { + 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; - } - } + [HttpGet] + public MemberViewModel GetMember(int lunchId) + { + try + { + var elem = _member.ReadElement(new MemberSearchModel { Id = lunchId }); + return elem; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId); + throw; + } + } - [HttpPost] + [HttpPost] public void CreateMember(MemberBindingModel model) { try diff --git a/Hotel/HotelRestApi/Controllers/RoomController.cs b/Hotel/HotelRestApi/Controllers/RoomController.cs index 4ed78ed..6443fd4 100644 --- a/Hotel/HotelRestApi/Controllers/RoomController.cs +++ b/Hotel/HotelRestApi/Controllers/RoomController.cs @@ -7,18 +7,18 @@ using Microsoft.AspNetCore.Mvc; namespace HotelRestApi.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] - public class RoomController : Controller - { - private readonly ILogger _logger; - private readonly IRoomLogic _room; + [Route("api/[controller]/[action]")] + [ApiController] + public class RoomController : Controller + { + private readonly ILogger _logger; + private readonly IRoomLogic _room; - public RoomController(ILogger logger, IRoomLogic room) - { - _logger = logger; - _room = room; - } + public RoomController(ILogger logger, IRoomLogic room) + { + _logger = logger; + _room = room; + } [HttpGet] public List GetRooms(int? headwaiterId = null) @@ -26,18 +26,18 @@ namespace HotelRestApi.Controllers try { List res; - if (!headwaiterId.HasValue) - { - res = _room.ReadList(null); - } - else - { - res = _room.ReadList(new RoomSearchModel { HeadwaiterId = headwaiterId }); - } - foreach (var service in res) - { - service.RoomLunches = null; - } + if (!headwaiterId.HasValue) + { + res = _room.ReadList(null); + } + else + { + res = _room.ReadList(new RoomSearchModel { HeadwaiterId = headwaiterId }); + } + foreach (var service in res) + { + service.RoomLunches = null; + } return res; } catch (Exception ex) @@ -53,10 +53,10 @@ namespace HotelRestApi.Controllers try { var elem = _room.ReadElement(new RoomSearchModel { Id = roomId }); - if (elem == null) - { - return null; - } + if (elem == null) + { + return null; + } var res = Tuple.Create(elem, elem.RoomLunches.Select(x => x.Value.LunchName).ToList()); res.Item1.RoomLunches = null!; return res; @@ -69,46 +69,46 @@ namespace HotelRestApi.Controllers } [HttpPost] - public void CreateRoom(RoomBindingModel model) - { - try - { - _room.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания номера"); - throw; - } - } + public void CreateRoom(RoomBindingModel model) + { + try + { + _room.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания номера"); + throw; + } + } - [HttpPost] - public void UpdateRoom(RoomBindingModel model) - { - try - { - model.RoomLunches = null!; - _room.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных номера"); - throw; - } - } + [HttpPost] + public void UpdateRoom(RoomBindingModel model) + { + try + { + model.RoomLunches = null!; + _room.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных номера"); + throw; + } + } - [HttpPost] - public void DeleteRoom(RoomBindingModel model) - { - try - { - _room.Delete(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления номера"); - throw; - } - } - } + [HttpPost] + public void DeleteRoom(RoomBindingModel model) + { + try + { + _room.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления номера"); + throw; + } + } + } }