доделаны CRUD

This commit is contained in:
Анна Забродина 2024-05-02 00:55:35 +04:00
parent 495a1ce739
commit 2adcbcfb1e
15 changed files with 449 additions and 57 deletions

View File

@ -17,7 +17,5 @@ namespace HotelContracts.ViewModels
public string NameHall { get; set; } = string.Empty;
public Dictionary<int, ILunchModel> ConferenceBookingLunches { get; set; }
public Dictionary<int, IConferenceBookingModel> ConferenceConferenceBookings { get; set; } = new();
}
}

View File

@ -17,7 +17,5 @@ namespace HotelContracts.ViewModels
public int OrganiserId { get; set; }
public Dictionary<int, IMemberModel> MealPlanMembers { get; set; } = new();
public Dictionary<int, IRoomModel> MealPlanRooms { get; set; } = new();
}
}

View File

@ -10,7 +10,7 @@ namespace HotelDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-M2G96S06\SQLEXPRESS;Initial Catalog=HotelDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7DB3VEN\SQLEXPRESS;Initial Catalog=HotelDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -8,21 +8,16 @@
<h2 class="display-4">Связывание номера и плана питания</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Номер:</div>
<div class="col-8">
<div class="form-group">
<label for="room">Номер</label>
<select id="room" name="room" class="form-control" asp-items="@(new SelectList(@ViewBag.Rooms, "Id", "RoomName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">План питания:</div>
<div class="col-8">
<div class="form-group">
<label for="mealplan">План питания</label>
<select id="mealplan" name="mealplan" class="form-control" asp-items="@(new SelectList(@ViewBag.MealPlans, "Id", "MealPlanName"))"></select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></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>

View File

@ -351,32 +351,19 @@ namespace HotelOrganiserApp.Controllers
}
[HttpGet]
public Tuple<MealPlanViewModel, string>? GetMealPlan(int mealPlanId)
public Tuple<MealPlanViewModel, List<string>>? GetMealPlan(int mealPlanId)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<Tuple<MealPlanViewModel, List<Tuple<string, string, string, string>>>>($"api/mealplan/getmealplan?mealPlanId={mealPlanId}");
var result = APIClient.GetRequest<Tuple<MealPlanViewModel, List<string>>>($"api/mealPlan/getmealPlan?mealPlanId={mealPlanId}");
if (result == null)
{
return default;
}
string table = "";
for (int i = 0; i < result.Item2.Count; i++)
{
var memberSurname = result.Item2[i].Item1;
var memberName = result.Item2[i].Item2;
var memberPatronymic = result.Item2[i].Item3;
var memberPhoneNumber = result.Item2[i].Item4;
table += "<tr style=\"height: 44px\">";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberSurname}</td>";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberName}</td>";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberPatronymic}</td>";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberPhoneNumber}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
return result;
}
public IActionResult DeleteMealPlan()
@ -403,6 +390,169 @@ namespace HotelOrganiserApp.Controllers
Response.Redirect("ListMealPlans");
}
public IActionResult ListConferences()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<ConferenceViewModel>>($"api/conference/getconferences?organiserId={APIClient.Organiser.Id}"));
}
public IActionResult CreateConference()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Member = APIClient.GetRequest<List<MemberViewModel>>($"api/member/getmembers?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void CreateConference(string conferenceName, DateTime startDate, List<int> memberselect)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(conferenceName) || string.IsNullOrEmpty(startDate.ToString()))
{
throw new Exception("Введите название");
}
if (string.IsNullOrEmpty(startDate.ToString()))
{
throw new Exception("Введите дату");
}
Dictionary<int, IMemberModel> member = new Dictionary<int, IMemberModel>();
foreach (int members in memberselect)
{
member.Add(members, new MemberSearchModel { Id = members } as IMemberModel);
}
APIClient.PostRequest("api/conference/createconference", new ConferenceBindingModel
{
ConferenceName = conferenceName,
StartDate = startDate,
OrganiserId = APIClient.Organiser.Id,
ConferenceMembers = member
});
Response.Redirect("ListConferences");
}
public IActionResult UpdateConference()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Conferences = APIClient.GetRequest<List<ConferenceViewModel>>($"api/conference/getconferences?organiserId={APIClient.Organiser.Id}");
ViewBag.Member = APIClient.GetRequest<List<MemberViewModel>>($"api/member/getmembers?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void UpdateConference(int conference, string conferenceName, DateTime startDate, List<int> memberselect)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(conferenceName))
{
throw new Exception("Название не может быть пустым");
}
if (string.IsNullOrEmpty(startDate.ToString()))
{
throw new Exception("Дата не может быть пустым");
}
Dictionary<int, IMemberModel> member = new Dictionary<int, IMemberModel>();
foreach (int members in memberselect)
{
member.Add(members, new MemberSearchModel { Id = members } as IMemberModel);
}
APIClient.PostRequest("api/conference/updateconference", new ConferenceBindingModel
{
Id = conference,
ConferenceName = conferenceName,
StartDate = startDate,
OrganiserId = APIClient.Organiser.Id,
ConferenceMembers = member
});
Response.Redirect("ListConferences");
}
[HttpGet]
public Tuple<ConferenceViewModel, List<string>>? GetConference(int conferenceId)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<Tuple<ConferenceViewModel, List<string>>>($"api/conference/getconference?conferenceId={conferenceId}");
if (result == null)
{
return default;
}
return result;
}
public IActionResult DeleteConference()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Conferences = APIClient.GetRequest<List<ConferenceViewModel>>($"api/conference/getconferences?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void DeleteConference(int conference)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
APIClient.PostRequest("api/conference/deleteconference", new ConferenceBindingModel
{
Id = conference
});
Response.Redirect("ListConferences");
}
public IActionResult ConferenceConferenceBookings()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Conferences = APIClient.GetRequest<List<ConferenceViewModel>>($"api/conference/getconferences?organiserId={APIClient.Organiser.Id}");
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/conferenceBooking/getconferenceBookings");
return View();
}
[HttpPost]
public void ConferenceConferenceBookings(int conference, int conferenceBooking)
{
if (APIClient.Organiser == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var roomElem = APIClient.GetRequest<ConferenceBookingViewModel>($"api/conferenceBooking/getconferenceBookingbyid?conferenceBookingId={conferenceBooking}");
APIClient.PostRequest("api/conferencebooking/updateconferenceBooking", new ConferenceBookingBindingModel
{
Id = conferenceBooking,
HeadwaiterId = roomElem.HeadwaiterId,
ConferenceId = conference,
BookingDate = roomElem.BookingDate,
NameHall = roomElem.NameHall,
});
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -0,0 +1,22 @@
@using HotelContracts.ViewModels;
@{
ViewData["Title"] = "ConferenceConferenceBookings";
}
<div class="text-center">
<h2 class="display-4">Связывание конференции и бронирования по конференции</h2>
</div>
<form method="post">
<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="conferenceBooking">Помещение конференции</label>
<select id="conferenceBooking" name="conferenceBooking" class="form-control" asp-items="@(new SelectList(@ViewBag.ConferenceBookings, "Id", "NameHall"))"></select>
</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>

View File

@ -0,0 +1,45 @@
@using HotelContracts.ViewModels;
@using HotelDataModels.Models;
@{
ViewData["Title"] = "CreateConference";
}
<form method="post">
<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="conferenceName"
class="form-control" />
<br>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-2">Дата начала</label>
</div>
<input type="datetime-local"
placeholder="Введите дату начала"
name="startDate"
class="form-control" />
<br>
<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="memberselect" class="form-control" multiple size="6" id="memberselect">
@foreach (var member in ViewBag.Member)
{
<option value="@member.Id">@($"{member.MemberSurname} {member.MemberName} {member.MemberPatronymic}")</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" />
</div>
</form>

View File

@ -0,0 +1,22 @@
@{
ViewData["Title"] = "DeleteConference";
}
<form method="post">
<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-1">Конференция</label>
<select id="conference" name="conference" class="form-control">
@foreach (var conference in ViewBag.Conferences)
{
<option value="@conference.Id">@(conference.ConferenceName)</option>
}
</select>
</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" />
</div>
</form>

View File

@ -0,0 +1,67 @@
@using HotelContracts.ViewModels
@model List<ConferenceViewModel>
@{
ViewData["Title"] = "ListConferences";
}
<div class="text-center">
<h2 class="display-4">Список конференций</h2>
</div>
<section class="u-clearfix u-section-1" id="sec-e38b">
<div class="u-clearfix u-sheet u-sheet-1">
<div class="u-container-style u-layout-cell u-size-48 u-layout-cell-1">
<div class="u-container-layout u-container-layout-1">
<div class="btn-group" role="group" aria-label="Basic example">
<a asp-area="" asp-controller="Home" asp-action="CreateConference"
class="btn btn-outline-dark mr-2">Добавить</a>
<a asp-area="" asp-controller="Home" asp-action="UpdateConference"
class="btn btn-outline-dark mr-2">Изменить</a>
<a asp-area="" asp-controller="Home" asp-action="DeleteConference"
class="btn btn-outline-dark">Удалить</a>
</div>
<div class="u-table u-table-responsive u-table-1">
<table class="table">
<thead class="thead-dark">
<tr style="height: 31px">
<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>
<th class="u-border-1 u-border-grey-50 u-table-cell">
Дата начала конференции
</th>
</tr>
</thead>
<tbody class="u-table-body">
@foreach (var item in Model)
{
<tr style="height: 75px">
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
@Html.DisplayFor(modelItem => item.Id)
</td>
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
@Html.DisplayFor(modelItem => item.ConferenceName)
</td>
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
@Html.DisplayFor(modelItem => item.StartDate)
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<style>
.btn-group > .btn {
margin-right: 10px;
}
</style>

View File

@ -0,0 +1,79 @@
@using HotelContracts.ViewModels;
@using HotelDataModels.Models;
@{
ViewData["Title"] = "UpdateConference";
}
<form method="post">
<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-1">Конференция</label>
<select id="conference" name="conference" class="form-control" asp-items="@(new SelectList(@ViewBag.Conferences, "Id", "ConferenceName"))"></select>
</div>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-1">Название конференции</label>
<input type="text"
id="conferenceName"
placeholder="Введите название конференции"
name="conferenceName"
class="form-control" />
</div>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-1">Дата начала</label>
<input type="datetime-local"
id="startDate"
placeholder="Введите дату начала"
name="startDate"
class="form-control" />
</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="memberselect" class="form-control" multiple size="6" id="memberselect">
@foreach (var member in ViewBag.Member)
{
<option value="@member.Id">@($"{member.MemberSurname} {member.MemberName} {member.MemberPatronymic}")</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 conference = $('#conference').val();
$("#memberselect option:selected").removeAttr("selected");
if (conference) {
$.ajax({
method: "GET",
url: "/Home/GetConference",
data: { conferenceId: conference },
success: function (result) {
console.log(result.item2);
$('#conferenceName').val(result.item1.conferenceName);
var startDate = new Date(result.item1.startDate).toISOString().slice(0, 16);
$('#startDate').val(startDate);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#conference').on('change', function () {
check();
});
</script>
}

View File

@ -10,15 +10,8 @@
<h2 class="display-4">Изменение плана питания</h2>
</div>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-1">План питания: </label>
<div class="u-input u-input-rectangle">
<select id="mealplan" name="mealplan" class="form-control">
@foreach (var mealplan in ViewBag.MealPlans)
{
<option value="@mealplan.Id">@(mealplan.MealPlanName)</option>
}
</select>
</div>
<label class="u-label u-text-custom-color-1 u-label-1">План питания</label>
<select id="mealplan" name="mealplan" class="form-control" asp-items="@(new SelectList(@ViewBag.MealPlans, "Id", "MealPlanName"))"></select>
</div>
<div class="form-group">
<label class="u-label u-text-custom-color-1 u-label-1">Название плана питания</label>
@ -49,9 +42,8 @@
</select>
</div>
</div>
<div class="u-align-right u-form-group u-form-submit u-label-top">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></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>
@ -61,21 +53,26 @@
<script>
function check() {
var mealPlan = $('#mealplan').val();
$("#memberselect option:selected").removeAttr("selected");
if (mealPlan) {
$.ajax({
method: "GET",
url: "/Home/GetMealPlan",
data: { mealPlanId: mealPlan },
success: function (result) {
console.log(result.item2);
$('#mealPlanName').val(result.item1.mealPlanName);
$('#mealPlanPrice').val(result.item1.mealPlanPrice);
$('#table-elements').html(result.item2);
$.map(result.item2, function (n) {
console.log("#" + n);
$("#" + n).attr("selected", "selected")
});
}
});
};
}
check();
$('#mealPlan').on('change', function () {
$('#mealplan').on('change', function () {
check();
});
</script>

View File

@ -52,9 +52,8 @@
name="memberPhoneNumber"
class="form-control" />
</div>
<div class="u-align-right u-form-group u-form-submit u-label-top">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></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>

View File

@ -32,7 +32,7 @@
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="ListConferences">Конференции</a>
</li>
<li class="nav-item">
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="AddConferenceBookingToConfe">Привязка конференций</a>
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="ConferenceConferenceBookings">Связывание</a>
</li>
<li class="nav-item">
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="ListMemberConferenceToFile">Отчёт по бронированиям</a>

View File

@ -67,6 +67,26 @@ namespace HotelRestApi.Controllers
}
}
[HttpGet]
public ConferenceBookingViewModel GetConferenceBookingById(int conferencebookingId)
{
try
{
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferencebookingId });
if (elem == null)
{
return null;
}
elem.ConferenceBookingLunches = null!;
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения бронирования по конференции по id={Id}", conferencebookingId);
throw;
}
}
[HttpPost]
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
{

View File

@ -42,16 +42,16 @@ namespace HotelRestApi.Controllers
}
[HttpGet]
public MemberViewModel GetMember(int lunchId)
public MemberViewModel GetMember(int memberId)
{
try
{
var elem = _member.ReadElement(new MemberSearchModel { Id = lunchId });
var elem = _member.ReadElement(new MemberSearchModel { Id = memberId });
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
_logger.LogError(ex, "Ошибка получения участника по id={Id}", memberId);
throw;
}
}