правки

This commit is contained in:
Вячеслав Иванов 2024-04-30 22:30:12 +04:00
parent 77e3b7c3d4
commit cf109109bc
18 changed files with 265 additions and 459 deletions

View File

@ -58,39 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics
return element; 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) public bool Create(ConferenceBookingBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -58,38 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics
return element; 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) public bool Create(ConferenceBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -58,38 +58,6 @@ namespace HotelBusinessLogic.BusinessLogics
return element; 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) public bool Create(MealPlanBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{ {
List<ConferenceBookingViewModel>? ReadList(ConferenceBookingSearchModel? model); List<ConferenceBookingViewModel>? ReadList(ConferenceBookingSearchModel? model);
ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model); ConferenceBookingViewModel? ReadElement(ConferenceBookingSearchModel model);
bool AddLunchToConferenceBooking(ConferenceBookingSearchModel model, ILunchModel lunch);
bool Create(ConferenceBookingBindingModel model); bool Create(ConferenceBookingBindingModel model);
bool Update(ConferenceBookingBindingModel model); bool Update(ConferenceBookingBindingModel model);
bool Delete(ConferenceBookingBindingModel model); bool Delete(ConferenceBookingBindingModel model);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{ {
List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model); List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model);
ConferenceViewModel? ReadElement(ConferenceSearchModel model); ConferenceViewModel? ReadElement(ConferenceSearchModel model);
bool AddMemberToConference(ConferenceSearchModel model, IMemberModel member);
bool Create(ConferenceBindingModel model); bool Create(ConferenceBindingModel model);
bool Update(ConferenceBindingModel model); bool Update(ConferenceBindingModel model);
bool Delete(ConferenceBindingModel model); bool Delete(ConferenceBindingModel model);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{ {
List<MealPlanViewModel>? ReadList(MealPlanSearchModel? model); List<MealPlanViewModel>? ReadList(MealPlanSearchModel? model);
MealPlanViewModel? ReadElement(MealPlanSearchModel model); MealPlanViewModel? ReadElement(MealPlanSearchModel model);
bool AddMemberToMealPlan(MealPlanSearchModel model, IMemberModel member);
bool Create(MealPlanBindingModel model); bool Create(MealPlanBindingModel model);
bool Update(MealPlanBindingModel model); bool Update(MealPlanBindingModel model);
bool Delete(MealPlanBindingModel model); bool Delete(MealPlanBindingModel model);

View File

@ -19,13 +19,5 @@ namespace HotelContracts.ViewModels
public Dictionary<int, ILunchModel> ConferenceBookingLunches { get; set; } public Dictionary<int, ILunchModel> ConferenceBookingLunches { get; set; }
public Dictionary<int, IConferenceBookingModel> ConferenceConferenceBookings { get; set; } = new(); public Dictionary<int, IConferenceBookingModel> ConferenceConferenceBookings { get; set; } = new();
public ConferenceBookingViewModel() { }
[JsonConstructor]
public ConferenceBookingViewModel(Dictionary<int, LunchViewModel> ConferenceBookingLunches, Dictionary<int, ConferenceBookingViewModel> 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);
}
} }
} }

View File

@ -18,13 +18,5 @@ namespace HotelContracts.ViewModels
public int OrganiserId { get; set; } public int OrganiserId { get; set; }
public Dictionary<int, IMemberModel> ConferenceMembers { get; set; } = new(); public Dictionary<int, IMemberModel> ConferenceMembers { get; set; } = new();
public ConferenceViewModel() { }
[JsonConstructor]
public ConferenceViewModel(Dictionary<int, MemberViewModel> ConferenceMembers)
{
this.ConferenceMembers = ConferenceMembers.ToDictionary(x => x.Key, x => x.Value as IMemberModel);
}
} }
} }

View File

@ -19,14 +19,5 @@ namespace HotelContracts.ViewModels
public Dictionary<int, IMemberModel> MealPlanMembers { get; set; } = new(); public Dictionary<int, IMemberModel> MealPlanMembers { get; set; } = new();
public Dictionary<int, IRoomModel> MealPlanRooms { get; set; } = new(); public Dictionary<int, IRoomModel> MealPlanRooms { get; set; } = new();
public MealPlanViewModel() { }
[JsonConstructor]
public MealPlanViewModel(Dictionary<int, MemberViewModel> MealPlanMembers, Dictionary<int, RoomViewModel> 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);
}
} }
} }

View File

@ -28,10 +28,8 @@ namespace HotelDataBaseImplement.Models
{ {
if (_conferenceMembers == null) if (_conferenceMembers == null)
{ {
using var context = new HotelDataBase(); _conferenceMembers = Members.ToDictionary(x => x.MemberId, x => (x.Member as IMemberModel));
_conferenceMembers = Members.ToDictionary(x => x.MemberId, x => (context.Members }
.FirstOrDefault(y => y.Id == x.MemberId)! as IMemberModel));
}
return _conferenceMembers; return _conferenceMembers;
} }
} }

View File

@ -27,11 +27,8 @@ namespace HotelDataBaseImplement.Models
{ {
if (_conferenceBookingLunches == null) if (_conferenceBookingLunches == null)
{ {
using var context = new HotelDataBase(); _conferenceBookingLunches = Lunches.ToDictionary(x => x.LunchId, x => (x.Lunch as ILunchModel));
_conferenceBookingLunches = Lunches }
.ToDictionary(x => x.LunchId, x => (context.Lunches
.FirstOrDefault(y => y.Id == x.LunchId)! as ILunchModel));
}
return _conferenceBookingLunches; return _conferenceBookingLunches;
} }
} }

View File

@ -29,10 +29,8 @@ namespace HotelDataBaseImplement.Models
{ {
if (_mealPlanMembers == null) if (_mealPlanMembers == null)
{ {
using var context = new HotelDataBase(); _mealPlanMembers = Members.ToDictionary(x => x.MemberId, x => (x.Member as IMemberModel));
_mealPlanMembers = Members.ToDictionary(x => x.MemberId, x => (context.Members }
.FirstOrDefault(y => y.Id == x.MemberId)! as IMemberModel));
}
return _mealPlanMembers; return _mealPlanMembers;
} }
} }

View File

@ -19,72 +19,55 @@ namespace HotelRestApi.Controllers
_conferenceBooking = conferenceBooking; _conferenceBooking = conferenceBooking;
} }
[HttpGet] [HttpGet]
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId) public List<ConferenceBookingViewModel>? GetConferenceBookings(int? headwaiterId = null)
{ {
try try
{ {
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel List<ConferenceBookingViewModel> res;
if (!headwaiterId.HasValue)
{ {
HeadwaiterId = headwaiterId, res = _conferenceBooking.ReadList(null);
}); }
} else
catch (Exception ex) {
{ res = _conferenceBooking.ReadList(new ConferenceBookingSearchModel { HeadwaiterId = headwaiterId });
_logger.LogError(ex, "Ошибка получения списка бронирования по конференции"); }
throw; foreach (var conferencebooking in res)
} {
} conferencebooking.ConferenceBookingLunches = null!;
}
[HttpGet] return res;
public ConferenceBookingViewModel? GetConferenceBookingById(int conferenceBookingId) }
{ catch (Exception ex)
try {
{ _logger.LogError(ex, "Ошибка получения списка бронирований по конференциям");
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel throw;
{ }
Id = conferenceBookingId }
});
[HttpGet]
public Tuple<ConferenceBookingViewModel, List<string>>? GetConferenceBooking(int conferencebookingId)
{
try
{
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferencebookingId });
if (elem == null) if (elem == null)
{ {
return 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; [HttpPost]
}
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) public void CreateConferenceBooking(ConferenceBookingBindingModel model)
{ {
try try
@ -127,19 +110,5 @@ namespace HotelRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void AddLunchToConferenceBooking(Tuple<ConferenceBookingSearchModel, LunchViewModel> model)
{
try
{
_conferenceBooking.AddLunchToConferenceBooking(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления обеда в бронирование по конференции.");
throw;
}
}
} }
} }

View File

@ -2,6 +2,7 @@
using HotelContracts.BusinessLogicsContracts; using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels; using HotelContracts.SearchModels;
using HotelContracts.ViewModels; using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers namespace HotelRestApi.Controllers
@ -19,59 +20,55 @@ namespace HotelRestApi.Controllers
_conference = conference; _conference = conference;
} }
[HttpGet] [HttpGet]
public List<ConferenceViewModel>? GetConferenceList(int organiserId) public List<ConferenceViewModel>? GetConferences(int? organiserId = null)
{ {
try try
{ {
return _conference.ReadList(new ConferenceSearchModel List<ConferenceViewModel> res;
{ if (!organiserId.HasValue)
OrganiserId = organiserId, {
}); res = _conference.ReadList(null);
} }
catch (Exception ex) else
{ {
_logger.LogError(ex, "Ошибка получения списка конференций"); res = _conference.ReadList(new ConferenceSearchModel { OrganiserId = organiserId });
throw; }
} foreach (var conference in res)
} {
conference.ConferenceMembers = null!;
}
return res;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения конференций");
throw;
}
}
[HttpGet] [HttpGet]
public List<ConferenceViewModel>? GetConferences() public Tuple<ConferenceViewModel, List<string>>? GetConference(int conferenceId)
{ {
try try
{ {
return _conference.ReadList(null); var elem = _conference.ReadElement(new ConferenceSearchModel { Id = conferenceId });
} if (elem == null)
catch (Exception ex) {
{ return null;
_logger.LogError(ex, "Ошибка получения списка конференций"); }
throw; 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] [HttpPost]
public Tuple<ConferenceViewModel, List<Tuple<string, string>>>? 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]
public void CreateConference(ConferenceBindingModel model) public void CreateConference(ConferenceBindingModel model)
{ {
try try
@ -113,19 +110,5 @@ namespace HotelRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void AddMemberToConference(Tuple<ConferenceSearchModel, MemberViewModel> model)
{
try
{
_conference.AddMemberToConference(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления участника в конференцию.");
throw;
}
}
} }
} }

View File

@ -19,55 +19,43 @@ namespace HotelRestApi.Controllers
_lunch = lunch; _lunch = lunch;
} }
[HttpGet] [HttpGet]
public List<LunchViewModel>? GetLunchList(int headwaiterId) public List<LunchViewModel>? GetLunches(int? headwaiterId = null)
{ {
try try
{ {
return _lunch.ReadList(new LunchSearchModel if (!headwaiterId.HasValue)
{ {
HeadwaiterId = headwaiterId, return _lunch.ReadList(null);
}); }
} return _lunch.ReadList(new LunchSearchModel
catch (Exception ex) {
{ HeadwaiterId = headwaiterId
_logger.LogError(ex, "Ошибка получения списка обедов"); });
throw; }
} catch (Exception ex)
} {
_logger.LogError(ex, "Ошибка получения списка обедов");
throw;
}
}
[HttpGet] [HttpGet]
public List<LunchViewModel>? GetLunches() public LunchViewModel GetLunch(int lunchId)
{ {
try try
{ {
return _lunch.ReadList(null); var elem = _lunch.ReadElement(new LunchSearchModel { Id = lunchId });
} return elem;
catch (Exception ex) }
{ catch (Exception ex)
_logger.LogError(ex, "Ошибка получения списка обедов"); {
throw; _logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
} throw;
} }
}
[HttpGet] [HttpPost]
public LunchViewModel? GetLunchById(int lunchId)
{
try
{
return _lunch.ReadElement(new LunchSearchModel
{
Id = lunchId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
throw;
}
}
[HttpPost]
public void CreateLunch(LunchBindingModel model) public void CreateLunch(LunchBindingModel model)
{ {
try try

View File

@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels; using HotelContracts.SearchModels;
using HotelContracts.ViewModels; using HotelContracts.ViewModels;
using HotelDataBaseImplement; using HotelDataBaseImplement;
using HotelDataBaseImplement.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers namespace HotelRestApi.Controllers
@ -20,38 +21,46 @@ namespace HotelRestApi.Controllers
_mealPlan = mealPlan; _mealPlan = mealPlan;
} }
[HttpGet]
public List<MealPlanViewModel>? GetMealPlanList(int organiserId)
{
try
{
return _mealPlan.ReadList(new MealPlanSearchModel
{
OrganiserId = organiserId,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка планов питания");
throw;
}
}
[HttpGet] [HttpGet]
public Tuple<MealPlanViewModel, List<Tuple<string, string, string, string>>>? GetMealPlan(int mealPlanId) public List<MealPlanViewModel>? GetMealPlans(int? organiserId = null)
{
try
{
List<MealPlanViewModel> 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<MealPlanViewModel, List<string>>? GetMealPlan(int mealPlanId)
{ {
try try
{ {
using var context = new HotelDataBase();
var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId }); var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId });
if (elem == null) if (elem == null)
{ {
return null; return null;
} }
var res = Tuple.Create(elem, elem.MealPlanMembers.Select(x => $"{x.Value.MemberSurname} {x.Value.MemberName} {x.Value.MemberPatronymic}").ToList());
var members = elem.MealPlanMembers.Select(x => Tuple.Create(x.Value.MemberSurname, x.Value.MemberName, x.Value.MemberPatronymic, x.Value.MemberPhoneNumber)).ToList(); res.Item1.MealPlanMembers = null!;
return res;
return Tuple.Create(elem, members);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -102,19 +111,5 @@ namespace HotelRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void AddMemberToMealPlan(Tuple<MealPlanSearchModel, MemberViewModel> model)
{
try
{
_mealPlan.AddMemberToMealPlan(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления участника в план питания.");
throw;
}
}
} }
} }

View File

@ -2,6 +2,7 @@
using HotelContracts.BusinessLogicsContracts; using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels; using HotelContracts.SearchModels;
using HotelContracts.ViewModels; using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers namespace HotelRestApi.Controllers
@ -19,41 +20,43 @@ namespace HotelRestApi.Controllers
_member = member; _member = member;
} }
[HttpGet] [HttpGet]
public List<MemberViewModel>? GetMemberList(int organiserId) public List<MemberViewModel>? GetMembers(int? organiserId = null)
{ {
try try
{ {
return _member.ReadList(new MemberSearchModel if (!organiserId.HasValue)
{ {
OrganiserId = organiserId, return _member.ReadList(null);
}); }
} return _member.ReadList(new MemberSearchModel
catch (Exception ex) {
{ OrganiserId = organiserId
_logger.LogError(ex, "Ошибка получения списка участников"); });
throw; }
} catch (Exception ex)
} {
_logger.LogError(ex, "Ошибка получения списка участников");
throw;
}
}
[HttpGet] [HttpGet]
public MemberViewModel? GetMember(int memberId) public MemberViewModel GetMember(int lunchId)
{ {
try try
{ {
return _member.ReadElement(new MemberSearchModel var elem = _member.ReadElement(new MemberSearchModel { Id = lunchId });
{ return elem;
Id = memberId }
}); catch (Exception ex)
} {
catch (Exception ex) _logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
{ throw;
_logger.LogError(ex, "Ошибка получения участника по id={Id}", memberId); }
throw; }
}
}
[HttpPost] [HttpPost]
public void CreateMember(MemberBindingModel model) public void CreateMember(MemberBindingModel model)
{ {
try try

View File

@ -7,18 +7,18 @@ using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers namespace HotelRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class RoomController : Controller public class RoomController : Controller
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IRoomLogic _room; private readonly IRoomLogic _room;
public RoomController(ILogger<RoomController> logger, IRoomLogic room) public RoomController(ILogger<RoomController> logger, IRoomLogic room)
{ {
_logger = logger; _logger = logger;
_room = room; _room = room;
} }
[HttpGet] [HttpGet]
public List<RoomViewModel> GetRooms(int? headwaiterId = null) public List<RoomViewModel> GetRooms(int? headwaiterId = null)
@ -26,18 +26,18 @@ namespace HotelRestApi.Controllers
try try
{ {
List<RoomViewModel> res; List<RoomViewModel> res;
if (!headwaiterId.HasValue) if (!headwaiterId.HasValue)
{ {
res = _room.ReadList(null); res = _room.ReadList(null);
} }
else else
{ {
res = _room.ReadList(new RoomSearchModel { HeadwaiterId = headwaiterId }); res = _room.ReadList(new RoomSearchModel { HeadwaiterId = headwaiterId });
} }
foreach (var service in res) foreach (var service in res)
{ {
service.RoomLunches = null; service.RoomLunches = null;
} }
return res; return res;
} }
catch (Exception ex) catch (Exception ex)
@ -53,10 +53,10 @@ namespace HotelRestApi.Controllers
try try
{ {
var elem = _room.ReadElement(new RoomSearchModel { Id = roomId }); var elem = _room.ReadElement(new RoomSearchModel { Id = roomId });
if (elem == null) if (elem == null)
{ {
return null; return null;
} }
var res = Tuple.Create(elem, elem.RoomLunches.Select(x => x.Value.LunchName).ToList()); var res = Tuple.Create(elem, elem.RoomLunches.Select(x => x.Value.LunchName).ToList());
res.Item1.RoomLunches = null!; res.Item1.RoomLunches = null!;
return res; return res;
@ -69,46 +69,46 @@ namespace HotelRestApi.Controllers
} }
[HttpPost] [HttpPost]
public void CreateRoom(RoomBindingModel model) public void CreateRoom(RoomBindingModel model)
{ {
try try
{ {
_room.Create(model); _room.Create(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка создания номера"); _logger.LogError(ex, "Ошибка создания номера");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void UpdateRoom(RoomBindingModel model) public void UpdateRoom(RoomBindingModel model)
{ {
try try
{ {
model.RoomLunches = null!; model.RoomLunches = null!;
_room.Update(model); _room.Update(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка обновления данных номера"); _logger.LogError(ex, "Ошибка обновления данных номера");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void DeleteRoom(RoomBindingModel model) public void DeleteRoom(RoomBindingModel model)
{ {
try try
{ {
_room.Delete(model); _room.Delete(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления номера"); _logger.LogError(ex, "Ошибка удаления номера");
throw; throw;
} }
} }
} }
} }