Merge branch 'main' of https://git.is.ulstu.ru/Vyacheslav/CourseWork_Hotel
This commit is contained in:
commit
7668554357
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -58,48 +58,11 @@ namespace HotelBusinessLogic.BusinessLogics
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool AddLunchToRoom(RoomSearchModel model, ILunchModel lunch)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddLunchToRoom. RoomName:{RoomName}.Id:{ Id}", model.RoomName, model.Id);
|
||||
var element = _roomStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddLunchToRoom element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddLunchToRoom find. Id:{Id}", element.Id);
|
||||
|
||||
element.RoomLunches[lunch.Id] = lunch;
|
||||
|
||||
_roomStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
RoomName = element.RoomName,
|
||||
RoomPrice = element.RoomPrice,
|
||||
RoomFrame = element.RoomFrame,
|
||||
MealPlanId = element.MealPlanId,
|
||||
HeadwaiterId = element.HeadwaiterId,
|
||||
RoomLunches = element.RoomLunches,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(RoomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.RoomLunches = new();
|
||||
|
||||
var result = _roomStorage.Insert(model);
|
||||
|
||||
if (result == null)
|
||||
if (_roomStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
@ -127,9 +90,7 @@ namespace HotelBusinessLogic.BusinessLogics
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
var result = _roomStorage.Delete(model);
|
||||
|
||||
if (result == null)
|
||||
if (_roomStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
@ -166,6 +127,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException("Стоимость комнаты не может быть меньше 0", nameof(model.RoomPrice));
|
||||
}
|
||||
|
||||
var element = _roomStorage.GetElement(new RoomSearchModel
|
||||
{
|
||||
RoomName = model.RoomName
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Услуга с таким названием уже есть");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Room. RoomName:{RoomName}.RoomFrame:{ RoomFrame}.RoomPrice:{ RoomPrice}. Id: { Id}", model.RoomName, model.RoomFrame, model.RoomPrice, model.Id);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,6 @@ namespace HotelContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<RoomViewModel>? ReadList(RoomSearchModel? model);
|
||||
RoomViewModel? ReadElement(RoomSearchModel model);
|
||||
bool AddLunchToRoom(RoomSearchModel model, ILunchModel lunch);
|
||||
bool Create(RoomBindingModel model);
|
||||
bool Update(RoomBindingModel model);
|
||||
bool Delete(RoomBindingModel model);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,13 +22,5 @@ namespace HotelContracts.ViewModels
|
||||
public int HeadwaiterId { get; set; }
|
||||
|
||||
public Dictionary<int, ILunchModel> RoomLunches { get; set; }
|
||||
|
||||
public RoomViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public RoomViewModel(Dictionary<int, LunchViewModel> RoomLunches)
|
||||
{
|
||||
this.RoomLunches = RoomLunches.ToDictionary(x => x.Key, x => x.Value as ILunchModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace HotelDataBaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7DB3VEN\SQLEXPRESS;Initial Catalog=HotelDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-M2G96S06\SQLEXPRESS;Initial Catalog=HotelDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,7 @@ namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
if (_roomLunches == null)
|
||||
{
|
||||
using var context = new HotelDataBase();
|
||||
_roomLunches = Lunches.ToDictionary(x => x.LunchId, x => (context.Lunches
|
||||
.FirstOrDefault(y => y.Id == x.LunchId)! as ILunchModel));
|
||||
_roomLunches = Lunches.ToDictionary(x => x.LunchId, x => (x.Lunch as ILunchModel));
|
||||
}
|
||||
return _roomLunches;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using HotelContracts.BindingModels;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataBaseImplement.Models;
|
||||
using HotelDataModels.Models;
|
||||
using HotelHeadwaiterApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@ -235,20 +236,21 @@ namespace HotelHeadwaiterApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<RoomViewModel>>($"api/room/getroomlist?headwaiterId={APIClient.Headwaiter.Id}"));
|
||||
return View(APIClient.GetRequest<List<RoomViewModel>>($"api/room/getrooms?headwaiterId={APIClient.Headwaiter.Id}"));
|
||||
}
|
||||
|
||||
public IActionResult CreateRoom()
|
||||
public IActionResult CreateRoom()
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateRoom(string roomName, double roomPrice, string roomFrame)
|
||||
public void CreateRoom(string roomName, string roomFrame, double roomPrice, List<int> lunches)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
@ -266,12 +268,18 @@ namespace HotelHeadwaiterApp.Controllers
|
||||
{
|
||||
throw new Exception("Цена не может быть отрицательной");
|
||||
}
|
||||
Dictionary<int, ILunchModel> a = new Dictionary<int, ILunchModel>();
|
||||
foreach (int lunch in lunches)
|
||||
{
|
||||
a.Add(lunch, new LunchSearchModel { Id = lunch } as ILunchModel);
|
||||
}
|
||||
APIClient.PostRequest("api/room/createroom", new RoomBindingModel
|
||||
{
|
||||
RoomName = roomName,
|
||||
RoomPrice = roomPrice,
|
||||
RoomFrame = roomFrame,
|
||||
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||
RoomLunches = a
|
||||
});
|
||||
Response.Redirect("ListRooms");
|
||||
}
|
||||
@ -282,12 +290,13 @@ namespace HotelHeadwaiterApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Rooms = APIClient.GetRequest<List<RoomViewModel>>($"api/room/getroomlist?headwaiterId={APIClient.Headwaiter.Id}");
|
||||
ViewBag.Rooms = APIClient.GetRequest<List<RoomViewModel>>($"api/room/getrooms?headwaiterId={APIClient.Headwaiter.Id}");
|
||||
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateRoom(int room, string roomName, double roomPrice, string roomFrame)
|
||||
public void UpdateRoom(int room, string roomName, double roomPrice, string roomFrame, List<int> lunches)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
@ -305,70 +314,40 @@ namespace HotelHeadwaiterApp.Controllers
|
||||
{
|
||||
throw new Exception("Цена не может быть отрицательной");
|
||||
}
|
||||
Dictionary<int, ILunchModel> a = new Dictionary<int, ILunchModel>();
|
||||
foreach (int lunch in lunches)
|
||||
{
|
||||
a.Add(lunch, new LunchSearchModel { Id = lunch } as ILunchModel);
|
||||
}
|
||||
APIClient.PostRequest("api/room/updateroom", new RoomBindingModel
|
||||
{
|
||||
Id = room,
|
||||
RoomName = roomName,
|
||||
RoomPrice = roomPrice,
|
||||
RoomFrame = roomFrame,
|
||||
HeadwaiterId = APIClient.Headwaiter.Id
|
||||
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||
RoomLunches = a
|
||||
});
|
||||
Response.Redirect("ListRooms");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<RoomViewModel, string>? GetRoom(int roomId)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
var result = APIClient.GetRequest<Tuple<RoomViewModel, List<Tuple<string, string>>>>($"api/room/getroombyid?roomId={roomId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
string table = "";
|
||||
for (int i = 0; i < result.Item2.Count; i++)
|
||||
{
|
||||
var lunchName = result.Item2[i].Item1;
|
||||
var lunchPrice = result.Item2[i].Item2;
|
||||
table += "<tr style=\"height: 44px\">";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{lunchName}</td>";
|
||||
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{lunchPrice}</td>";
|
||||
table += "</tr>";
|
||||
}
|
||||
return Tuple.Create(result.Item1, table);
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<RoomViewModel, List<string>>? GetRoom(int roomId)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
var result = APIClient.GetRequest<Tuple<RoomViewModel, List<string>>>($"api/room/getroom?roomId={roomId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
public IActionResult AddLunchToRoom()
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(Tuple.Create(APIClient.GetRequest<List<RoomViewModel>>($"api/room/getroomlist?headwaiterId={APIClient.Headwaiter.Id}"),
|
||||
APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}")));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddLunchToRoom(int room, int[] lunch)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
throw new Exception("Необходима авторизация");
|
||||
}
|
||||
for (int i = 0; i < lunch.Length; i++)
|
||||
{
|
||||
APIClient.PostRequest("api/room/AddLunchToRoom", Tuple.Create(
|
||||
new RoomSearchModel() { Id = room },
|
||||
new LunchViewModel() { Id = lunch[i] }
|
||||
));
|
||||
}
|
||||
Response.Redirect("ListRooms");
|
||||
}
|
||||
|
||||
public IActionResult DeleteRoom()
|
||||
public IActionResult DeleteRoom()
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
@using HotelContracts.ViewModels;
|
||||
@using HotelDataModels.Models;
|
||||
|
||||
@{
|
||||
@{
|
||||
ViewData["Title"] = "CreateRoom";
|
||||
}
|
||||
|
||||
@ -16,15 +13,6 @@
|
||||
placeholder="Введите название комнаты"
|
||||
name="roomName"
|
||||
class="form-control" />
|
||||
<br>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
||||
</div>
|
||||
<input type="number"
|
||||
placeholder="Введите цену комнаты"
|
||||
name="roomPrice"
|
||||
class="form-control" />
|
||||
<br>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Корпус</label>
|
||||
</div>
|
||||
@ -32,51 +20,27 @@
|
||||
placeholder="Введите корпус комнаты"
|
||||
name="roomFrame"
|
||||
class="form-control" />
|
||||
<br>
|
||||
<div class="u-table u-table-responsive u-table-1">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Обеды для номеров</label>
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr style="height: 44px">
|
||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||
Обед
|
||||
</th>
|
||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||
Цена
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="u-table-body" id="table-elements">
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
||||
</div>
|
||||
<input type="number"
|
||||
placeholder="Введите цену комнаты"
|
||||
name="roomPrice"
|
||||
class="form-control" />
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Обеды</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-8">
|
||||
<select name="lunches" class="form-control" multiple size="6" id="lunches">
|
||||
@foreach (var lunch in ViewBag.Lunches)
|
||||
{
|
||||
<option value="@lunch.Id">@lunch.LunchName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-container-layout u-container-layout-2">
|
||||
<input type="submit" value="Сохранить" class="btn btn-outline-dark text-center d-flex justify-content-md-center" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function check() {
|
||||
var room = $('#room').val();
|
||||
if (room) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetRoom",
|
||||
data: { roomId: room },
|
||||
success: function (result) {
|
||||
$('#roomName').val(result.item1.roomName);
|
||||
$('#roomPrice').val(result.item1.roomPrice);
|
||||
$('#roomFrame').val(result.item1.roomFrame);
|
||||
$('#table-elements').html(result.item2);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
check();
|
||||
$('#room').on('change', function () {
|
||||
check();
|
||||
});
|
||||
</script>
|
||||
}
|
@ -21,6 +21,14 @@
|
||||
name="roomName"
|
||||
class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Корпус</label>
|
||||
<input type="text"
|
||||
id="roomFrame"
|
||||
placeholder="Введите название корпуса"
|
||||
name="roomFrame"
|
||||
class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
||||
<input type="number"
|
||||
@ -30,29 +38,17 @@
|
||||
class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Корпус</label>
|
||||
<input type="text"
|
||||
id="roomFrame"
|
||||
placeholder="Введите название корпуса"
|
||||
name="roomFrame"
|
||||
class="form-control" />
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Обеды</label>
|
||||
</div>
|
||||
<div class="u-table u-table-responsive u-table-1">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Обеды для номеров</label>
|
||||
<table class="table">
|
||||
<thead class="thead-dark">
|
||||
<tr style="height: 44px">
|
||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||
Обед
|
||||
</th>
|
||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||
Цена
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="u-table-body" id="table-elements">
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="form-group">
|
||||
<div class="col-8">
|
||||
<select name="lunches" class="form-control" multiple size="6" id="lunches">
|
||||
@foreach (var lunch in ViewBag.Lunches)
|
||||
{
|
||||
<option value="@lunch.Id">@lunch.LunchName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="u-container-layout u-container-layout-2">
|
||||
@ -74,7 +70,10 @@
|
||||
$('#roomName').val(result.item1.roomName);
|
||||
$('#roomPrice').val(result.item1.roomPrice);
|
||||
$('#roomFrame').val(result.item1.roomFrame);
|
||||
$('#table-elements').html(result.item2);
|
||||
$.map(result.item2, function (n) {
|
||||
console.log("#" + n);
|
||||
$("#" + n).attr("selected", "selected")
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -19,72 +19,55 @@ namespace HotelRestApi.Controllers
|
||||
_conferenceBooking = conferenceBooking;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
|
||||
[HttpGet]
|
||||
public List<ConferenceBookingViewModel>? GetConferenceBookings(int? headwaiterId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ConferenceBookingViewModel> 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
|
||||
res = _conferenceBooking.ReadList(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Id = conferenceBookingId
|
||||
});
|
||||
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<ConferenceBookingViewModel, List<string>>? 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<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]
|
||||
[HttpPost]
|
||||
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ConferenceViewModel>? GetConferenceList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _conference.ReadList(new ConferenceSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка конференций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<ConferenceViewModel>? GetConferences(int? organiserId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ConferenceViewModel> 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<ConferenceViewModel>? GetConferences()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _conference.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка конференций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<ConferenceViewModel, List<string>>? 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<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]
|
||||
[HttpPost]
|
||||
public void CreateConference(ConferenceBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,55 +19,43 @@ namespace HotelRestApi.Controllers
|
||||
_lunch = lunch;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<LunchViewModel>? GetLunchList(int headwaiterId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _lunch.ReadList(new LunchSearchModel
|
||||
[HttpGet]
|
||||
public List<LunchViewModel>? 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<LunchViewModel>? 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
|
||||
|
@ -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<MealPlanViewModel>? GetMealPlanList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mealPlan.ReadList(new MealPlanSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка планов питания");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<MemberViewModel>? GetMemberList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _member.ReadList(new MemberSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка участников");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MemberViewModel>? 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
|
||||
|
@ -2,126 +2,113 @@
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataBaseImplement.Models;
|
||||
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<RoomController> logger, IRoomLogic room)
|
||||
{
|
||||
_logger = logger;
|
||||
_room = room;
|
||||
}
|
||||
public RoomController(ILogger<RoomController> logger, IRoomLogic room)
|
||||
{
|
||||
_logger = logger;
|
||||
_room = room;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<RoomViewModel>? GetRoomList(int headwaiterId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _room.ReadList(new RoomSearchModel
|
||||
{
|
||||
HeadwaiterId = headwaiterId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<RoomViewModel> GetRooms(int? headwaiterId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<RoomViewModel> res;
|
||||
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)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<RoomViewModel>? GetRooms()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _room.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<RoomViewModel, List<string>>? GetRoom(int roomId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _room.ReadElement(new RoomSearchModel { Id = roomId });
|
||||
if (elem == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var res = Tuple.Create(elem, elem.RoomLunches.Select(x => x.Value.LunchName).ToList());
|
||||
res.Item1.RoomLunches = null!;
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения номера по id={Id}", roomId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public RoomViewModel? GetRoomById(int roomId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _room.ReadElement(new RoomSearchModel
|
||||
{
|
||||
Id = roomId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения номера по id={Id}", roomId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateRoom(RoomBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_room.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 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 AddLunchToRoom(Tuple<RoomSearchModel, LunchViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_room.AddLunchToRoom(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления обеда к номеру.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void DeleteRoom(RoomBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_room.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления номера");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user