правки

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;
}
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);

View File

@ -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);

View File

@ -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);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{
List<ConferenceBookingViewModel>? 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);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{
List<ConferenceViewModel>? 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);

View File

@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
{
List<MealPlanViewModel>? 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);

View File

@ -19,13 +19,5 @@ namespace HotelContracts.ViewModels
public Dictionary<int, ILunchModel> ConferenceBookingLunches { get; set; }
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 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, 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,9 +28,7 @@ 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;
}

View File

@ -27,10 +27,7 @@ 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;
}

View File

@ -29,9 +29,7 @@ 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;
}

View File

@ -20,66 +20,49 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId)
public List<ConferenceBookingViewModel>? GetConferenceBookings(int? headwaiterId = null)
{
try
{
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
List<ConferenceBookingViewModel> res;
if (!headwaiterId.HasValue)
{
HeadwaiterId = headwaiterId,
});
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, "Ошибка получения списка бронирования по конференции");
_logger.LogError(ex, "Ошибка получения списка бронирований по конференциям");
throw;
}
}
[HttpGet]
public ConferenceBookingViewModel? GetConferenceBookingById(int conferenceBookingId)
public Tuple<ConferenceBookingViewModel, List<string>>? GetConferenceBooking(int conferencebookingId)
{
try
{
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel
{
Id = conferenceBookingId
});
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferencebookingId });
if (elem == null)
{
return null;
}
return elem;
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;
}
}
[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);
_logger.LogError(ex, "Ошибка получения бронирования по конференции по id={Id}", conferencebookingId);
throw;
}
}
@ -127,19 +110,5 @@ namespace HotelRestApi.Controllers
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.SearchModels;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers
@ -20,38 +21,34 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public List<ConferenceViewModel>? GetConferenceList(int organiserId)
public List<ConferenceViewModel>? GetConferences(int? organiserId = null)
{
try
{
return _conference.ReadList(new ConferenceSearchModel
List<ConferenceViewModel> res;
if (!organiserId.HasValue)
{
OrganiserId = organiserId,
});
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, "Ошибка получения списка конференций");
_logger.LogError(ex, "Ошибка получения конференций");
throw;
}
}
[HttpGet]
public List<ConferenceViewModel>? GetConferences()
{
try
{
return _conference.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка конференций");
throw;
}
}
[HttpGet]
public Tuple<ConferenceViewModel, List<Tuple<string, string>>>? GetConference(int conferenceId)
public Tuple<ConferenceViewModel, List<string>>? GetConference(int conferenceId)
{
try
{
@ -60,9 +57,9 @@ namespace HotelRestApi.Controllers
{
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);
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)
{
@ -113,19 +110,5 @@ namespace HotelRestApi.Controllers
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

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

View File

@ -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
@ -21,37 +22,45 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public List<MealPlanViewModel>? GetMealPlanList(int organiserId)
public List<MealPlanViewModel>? GetMealPlans(int? organiserId = null)
{
try
{
return _mealPlan.ReadList(new MealPlanSearchModel
List<MealPlanViewModel> res;
if (!organiserId.HasValue)
{
OrganiserId = organiserId,
});
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, "Ошибка получения списка планов питания");
_logger.LogError(ex, "Ошибка получения конференций");
throw;
}
}
[HttpGet]
public Tuple<MealPlanViewModel, List<Tuple<string, string, string, string>>>? GetMealPlan(int mealPlanId)
public Tuple<MealPlanViewModel, List<string>>? 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<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.SearchModels;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers
@ -20,13 +21,17 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public List<MemberViewModel>? GetMemberList(int organiserId)
public List<MemberViewModel>? GetMembers(int? organiserId = null)
{
try
{
if (!organiserId.HasValue)
{
return _member.ReadList(null);
}
return _member.ReadList(new MemberSearchModel
{
OrganiserId = organiserId,
OrganiserId = organiserId
});
}
catch (Exception ex)
@ -37,18 +42,16 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public MemberViewModel? GetMember(int memberId)
public MemberViewModel GetMember(int lunchId)
{
try
{
return _member.ReadElement(new MemberSearchModel
{
Id = memberId
});
var elem = _member.ReadElement(new MemberSearchModel { Id = lunchId });
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения участника по id={Id}", memberId);
_logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
throw;
}
}