full CRUD (75%)

This commit is contained in:
Вячеслав Иванов 2024-05-01 00:14:05 +04:00
parent ee84c3e108
commit e7f2e4d4d9
4 changed files with 80 additions and 59 deletions

View File

@ -125,7 +125,7 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}"));
return View(APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}"));
}
public IActionResult CreateLunch()
@ -171,7 +171,7 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}");
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
@ -212,7 +212,7 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}");
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
@ -353,7 +353,7 @@ 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}");
return View();
}
@ -377,45 +377,37 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}"));
return View(APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}"));
}
[HttpGet]
public Tuple<ConferenceBookingViewModel, string>? GetConferenceBooking(int conferenceBookingId)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<Tuple<ConferenceBookingViewModel, List<Tuple<string, string>>>>($"api/conferencebooking/getconferenceBooking?conferenceBookingId={conferenceBookingId}");
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>>? GetConferenceBooking(int conferencebookingId)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<Tuple<RoomViewModel, List<string>>>($"api/conferencebooking/getconferencebooking?conferencebookingId={conferencebookingId}");
if (result == null)
{
return default;
}
public IActionResult CreateConferenceBooking()
return result;
}
public IActionResult CreateConferenceBooking()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
[HttpPost]
public void CreateConferenceBooking(string nameHall)
public void CreateConferenceBooking(string nameHall, DateTime bookingDate, List<int> lunches)
{
if (string.IsNullOrEmpty(nameHall))
{
@ -425,11 +417,17 @@ 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/conferencebooking/createconferenceBooking", new ConferenceBookingBindingModel
{
NameHall = nameHall,
HeadwaiterId = APIClient.Headwaiter.Id,
BookingDate = bookingDate,
HeadwaiterId = APIClient.Headwaiter.Id,
ConferenceBookingLunches = a
});
Response.Redirect("ListConferenceBookings");
}
@ -440,13 +438,13 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}");
ViewBag.Conferences = APIClient.GetRequest<List<ConferenceViewModel>>($"api/conference/getconferences");
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}");
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
[HttpPost]
public void UpdateConferenceBooking(int conference, int conferenceBooking, string nameHall, DateTime bookingDate)
public void UpdateConferenceBooking(int conferenceBooking, string nameHall, DateTime bookingDate, List<int> lunches)
{
if (APIClient.Headwaiter == null)
{
@ -456,13 +454,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/conferencebooking/updateconferenceBooking", new ConferenceBookingBindingModel
{
Id = conferenceBooking,
NameHall = nameHall,
BookingDate = bookingDate,
HeadwaiterId = APIClient.Headwaiter.Id,
ConferenceId = conference
ConferenceBookingLunches = a
});
Response.Redirect("ListConferenceBookings");
}
@ -473,7 +476,7 @@ namespace HotelHeadwaiterApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}");
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}

View File

@ -7,10 +7,27 @@
<div class="text-center">
<h2 class="display-4">Добавление бронирования по конференции</h2>
</div>
<input type="text"
placeholder="Введите название зала"
name="nameHall"
class="form-control" />
<div class="form-group">
<label for="nameHall">Название зала:</label>
<input type="text" id="nameHall" name="nameHall" class="form-control" placeholder="Введите название зала">
</div>
<div class="form-group">
<label for="bookingDate">Дата:</label>
<input type="datetime-local" id="bookingDate" name="bookingDate" class="form-control" placeholder="Выберите начало конференции">
</div>
<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>
<br>
<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" />

View File

@ -6,6 +6,9 @@
<div class="text-center">
<h2 class="display-4">Добавление обеда</h2>
</div>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-2">Название обеда</label>
</div>
<input type="text"
placeholder="Введите название обеда"
name="lunchName"

View File

@ -13,10 +13,6 @@
<label for="conferenceBooking">Бронирование:</label>
<select id="conferenceBooking" name="conferenceBooking" class="form-control" asp-items="@(new SelectList(@ViewBag.ConferenceBookings, "Id", "NameHall"))"></select>
</div>
<div class="form-group">
<label for="conference">Конференция:</label>
<select id="conference" name="conference" class="form-control" asp-items="@(new SelectList(@ViewBag.Conferences, "Id", "ConferenceName"))"></select>
</div>
<div class="form-group">
<label for="nameHall">Название зала:</label>
<input type="text" id="nameHall" name="nameHall" class="form-control" placeholder="Введите название зала">
@ -26,18 +22,16 @@
<input type="datetime-local" id="bookingDate" name="bookingDate" class="form-control" placeholder="Выберите начало конференции">
</div>
<div class="form-group">
<label>Обеды для бронирования:</label>
<div class="table-responsive">
<table class="table">
<thead class="thead-dark">
<tr>
<th>Обед</th>
<th>Цена</th>
</tr>
</thead>
<tbody id="table-elements" class="u-table-body">
</tbody>
</table>
<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>
<br>
@ -58,7 +52,11 @@
data: { conferenceBookingId: conferenceBooking },
success: function (result) {
$('#nameHall').val(result.item1.nameHall);
$('#table-elements').html(result.item2);
$('#bookingDate').val(result.item1.bookingDate);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};