Room (без отображения обедов)
This commit is contained in:
parent
b969347e3e
commit
77e3b7c3d4
@ -58,48 +58,11 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
return element;
|
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)
|
public bool Create(RoomBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
model.RoomLunches = new();
|
|
||||||
|
|
||||||
var result = _roomStorage.Insert(model);
|
if (_roomStorage.Insert(model) == null)
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -127,9 +90,7 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
var result = _roomStorage.Delete(model);
|
if (_roomStorage.Delete(model) == null)
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
@ -166,6 +127,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
throw new ArgumentNullException("Стоимость комнаты не может быть меньше 0", nameof(model.RoomPrice));
|
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);
|
_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<RoomViewModel>? ReadList(RoomSearchModel? model);
|
List<RoomViewModel>? ReadList(RoomSearchModel? model);
|
||||||
RoomViewModel? ReadElement(RoomSearchModel model);
|
RoomViewModel? ReadElement(RoomSearchModel model);
|
||||||
bool AddLunchToRoom(RoomSearchModel model, ILunchModel lunch);
|
|
||||||
bool Create(RoomBindingModel model);
|
bool Create(RoomBindingModel model);
|
||||||
bool Update(RoomBindingModel model);
|
bool Update(RoomBindingModel model);
|
||||||
bool Delete(RoomBindingModel model);
|
bool Delete(RoomBindingModel model);
|
||||||
|
@ -22,13 +22,5 @@ namespace HotelContracts.ViewModels
|
|||||||
public int HeadwaiterId { get; set; }
|
public int HeadwaiterId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, ILunchModel> RoomLunches { 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)
|
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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,7 @@ namespace HotelDataBaseImplement.Models
|
|||||||
{
|
{
|
||||||
if (_roomLunches == null)
|
if (_roomLunches == null)
|
||||||
{
|
{
|
||||||
using var context = new HotelDataBase();
|
_roomLunches = Lunches.ToDictionary(x => x.LunchId, x => (x.Lunch as ILunchModel));
|
||||||
_roomLunches = Lunches.ToDictionary(x => x.LunchId, x => (context.Lunches
|
|
||||||
.FirstOrDefault(y => y.Id == x.LunchId)! as ILunchModel));
|
|
||||||
}
|
}
|
||||||
return _roomLunches;
|
return _roomLunches;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using HotelContracts.BindingModels;
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
using HotelDataBaseImplement.Models;
|
using HotelDataBaseImplement.Models;
|
||||||
|
using HotelDataModels.Models;
|
||||||
using HotelHeadwaiterApp.Models;
|
using HotelHeadwaiterApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
@ -235,20 +236,21 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
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)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[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)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
@ -266,12 +268,18 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Цена не может быть отрицательной");
|
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
|
APIClient.PostRequest("api/room/createroom", new RoomBindingModel
|
||||||
{
|
{
|
||||||
RoomName = roomName,
|
RoomName = roomName,
|
||||||
RoomPrice = roomPrice,
|
RoomPrice = roomPrice,
|
||||||
RoomFrame = roomFrame,
|
RoomFrame = roomFrame,
|
||||||
HeadwaiterId = APIClient.Headwaiter.Id,
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||||
|
RoomLunches = a
|
||||||
});
|
});
|
||||||
Response.Redirect("ListRooms");
|
Response.Redirect("ListRooms");
|
||||||
}
|
}
|
||||||
@ -282,12 +290,13 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
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();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[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)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
@ -305,70 +314,40 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
{
|
{
|
||||||
throw new Exception("Цена не может быть отрицательной");
|
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
|
APIClient.PostRequest("api/room/updateroom", new RoomBindingModel
|
||||||
{
|
{
|
||||||
Id = room,
|
Id = room,
|
||||||
RoomName = roomName,
|
RoomName = roomName,
|
||||||
RoomPrice = roomPrice,
|
RoomPrice = roomPrice,
|
||||||
RoomFrame = roomFrame,
|
RoomFrame = roomFrame,
|
||||||
HeadwaiterId = APIClient.Headwaiter.Id
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||||
|
RoomLunches = a
|
||||||
});
|
});
|
||||||
Response.Redirect("ListRooms");
|
Response.Redirect("ListRooms");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public Tuple<RoomViewModel, string>? GetRoom(int roomId)
|
public Tuple<RoomViewModel, List<string>>? GetRoom(int roomId)
|
||||||
{
|
{
|
||||||
if (APIClient.Headwaiter == null)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Необходима авторизация");
|
throw new Exception("Необходима авторизация");
|
||||||
}
|
}
|
||||||
var result = APIClient.GetRequest<Tuple<RoomViewModel, List<Tuple<string, string>>>>($"api/room/getroombyid?roomId={roomId}");
|
var result = APIClient.GetRequest<Tuple<RoomViewModel, List<string>>>($"api/room/getroom?roomId={roomId}");
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
return default;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult AddLunchToRoom()
|
return result;
|
||||||
{
|
}
|
||||||
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}")));
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost]
|
public IActionResult DeleteRoom()
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
if (APIClient.Headwaiter == null)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
@using HotelContracts.ViewModels;
|
@{
|
||||||
@using HotelDataModels.Models;
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "CreateRoom";
|
ViewData["Title"] = "CreateRoom";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,15 +13,6 @@
|
|||||||
placeholder="Введите название комнаты"
|
placeholder="Введите название комнаты"
|
||||||
name="roomName"
|
name="roomName"
|
||||||
class="form-control" />
|
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">
|
<div class="form-group">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-2">Корпус</label>
|
<label class="u-label u-text-custom-color-1 u-label-2">Корпус</label>
|
||||||
</div>
|
</div>
|
||||||
@ -32,51 +20,27 @@
|
|||||||
placeholder="Введите корпус комнаты"
|
placeholder="Введите корпус комнаты"
|
||||||
name="roomFrame"
|
name="roomFrame"
|
||||||
class="form-control" />
|
class="form-control" />
|
||||||
<br>
|
<div class="form-group">
|
||||||
<div class="u-table u-table-responsive u-table-1">
|
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
||||||
<label class="u-label u-text-custom-color-1 u-label-1">Обеды для номеров</label>
|
</div>
|
||||||
<table class="table">
|
<input type="number"
|
||||||
<thead class="thead-dark">
|
placeholder="Введите цену комнаты"
|
||||||
<tr style="height: 44px">
|
name="roomPrice"
|
||||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
class="form-control" />
|
||||||
Обед
|
<div class="form-group">
|
||||||
</th>
|
<label class="u-label u-text-custom-color-1 u-label-2">Обеды</label>
|
||||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
</div>
|
||||||
Цена
|
<div class="form-group">
|
||||||
</th>
|
<div class="col-8">
|
||||||
</tr>
|
<select name="lunches" class="form-control" multiple size="6" id="lunches">
|
||||||
</thead>
|
@foreach (var lunch in ViewBag.Lunches)
|
||||||
<tbody class="u-table-body" id="table-elements">
|
{
|
||||||
</tbody>
|
<option value="@lunch.Id">@lunch.LunchName</option>
|
||||||
</table>
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="u-container-layout u-container-layout-2">
|
<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" />
|
<input type="submit" value="Сохранить" class="btn btn-outline-dark text-center d-flex justify-content-md-center" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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"
|
name="roomName"
|
||||||
class="form-control" />
|
class="form-control" />
|
||||||
</div>
|
</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">
|
<div class="form-group">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
<label class="u-label u-text-custom-color-1 u-label-2">Цена комнаты</label>
|
||||||
<input type="number"
|
<input type="number"
|
||||||
@ -30,29 +38,17 @@
|
|||||||
class="form-control" />
|
class="form-control" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-1">Корпус</label>
|
<label class="u-label u-text-custom-color-1 u-label-2">Обеды</label>
|
||||||
<input type="text"
|
|
||||||
id="roomFrame"
|
|
||||||
placeholder="Введите название корпуса"
|
|
||||||
name="roomFrame"
|
|
||||||
class="form-control" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="u-table u-table-responsive u-table-1">
|
<div class="form-group">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-1">Обеды для номеров</label>
|
<div class="col-8">
|
||||||
<table class="table">
|
<select name="lunches" class="form-control" multiple size="6" id="lunches">
|
||||||
<thead class="thead-dark">
|
@foreach (var lunch in ViewBag.Lunches)
|
||||||
<tr style="height: 44px">
|
{
|
||||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
<option value="@lunch.Id">@lunch.LunchName</option>
|
||||||
Обед
|
}
|
||||||
</th>
|
</select>
|
||||||
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
</div>
|
||||||
Цена
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="u-table-body" id="table-elements">
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="u-container-layout u-container-layout-2">
|
<div class="u-container-layout u-container-layout-2">
|
||||||
@ -74,7 +70,10 @@
|
|||||||
$('#roomName').val(result.item1.roomName);
|
$('#roomName').val(result.item1.roomName);
|
||||||
$('#roomPrice').val(result.item1.roomPrice);
|
$('#roomPrice').val(result.item1.roomPrice);
|
||||||
$('#roomFrame').val(result.item1.roomFrame);
|
$('#roomFrame').val(result.item1.roomFrame);
|
||||||
$('#table-elements').html(result.item2);
|
$.map(result.item2, function (n) {
|
||||||
|
console.log("#" + n);
|
||||||
|
$("#" + n).attr("selected", "selected")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -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,55 +20,55 @@ namespace HotelRestApi.Controllers
|
|||||||
_room = room;
|
_room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<RoomViewModel>? GetRoomList(int headwaiterId)
|
public List<RoomViewModel> GetRooms(int? headwaiterId = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _room.ReadList(new RoomSearchModel
|
List<RoomViewModel> res;
|
||||||
|
if (!headwaiterId.HasValue)
|
||||||
{
|
{
|
||||||
HeadwaiterId = headwaiterId,
|
res = _room.ReadList(null);
|
||||||
});
|
}
|
||||||
}
|
else
|
||||||
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 RoomViewModel? GetRoomById(int roomId)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return _room.ReadElement(new RoomSearchModel
|
|
||||||
{
|
{
|
||||||
Id = roomId
|
res = _room.ReadList(new RoomSearchModel { HeadwaiterId = headwaiterId });
|
||||||
});
|
}
|
||||||
}
|
foreach (var service in res)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
service.RoomLunches = null;
|
||||||
_logger.LogError(ex, "Ошибка получения номера по id={Id}", roomId);
|
}
|
||||||
throw;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
public void CreateRoom(RoomBindingModel model)
|
public void CreateRoom(RoomBindingModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -109,19 +110,5 @@ namespace HotelRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
|
||||||
public void AddLunchToRoom(Tuple<RoomSearchModel, LunchViewModel> model)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_room.AddLunchToRoom(model.Item1, model.Item2);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка добавления обеда к номеру.");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user