Ех :< Я еще new() добавил в твою часть, посомтри, вдруг он не нужен :(

This commit is contained in:
Кашин Максим 2023-05-18 01:11:54 +04:00
parent 6af99f8e65
commit 6fb7d5e29b
7 changed files with 93 additions and 3 deletions

View File

@ -524,5 +524,35 @@ namespace HostrelHeadwaiterApp.Controllers
}
return View(APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/main/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}"));
}
[HttpGet]
public IActionResult AddConferenceBookingToConference()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Conferences = APIClient.GetRequest<List<ConferenceViewModel>>($"api/main/getconferencelist?organiserId={APIClient.Headwaiter.Id}");
ViewBag.ConferenceBookings = APIClient.GetRequest<List<ConferenceBookingViewModel>>($"api/main/getconferenceBookings");
return View();
}
[HttpPost]
public void AddConferenceBookingToConference(int conference, int conferenceBooking)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var conferenceBookingElem = APIClient.GetRequest<ConferenceBookingViewModel>($"api/main/getconferenceBookingbyid?conferenceBookingId={conferenceBooking}");
APIClient.PostRequest("api/main/updateconferenceBooking", new ConferenceBookingBindingModel
{
Id = conferenceBooking,
ConferenceId = conference,
NameHall = conferenceBookingElem.NameHall,
HeadwaiterId = conferenceBookingElem.HeadwaiterId,
});
Response.Redirect("ListConferences");
}
}
}

View File

@ -0,0 +1,25 @@
@using HotelContracts.ViewModels;
@using HotelDataModels.Models;
@{
ViewData["Title"] = "AddConferenceBookingToConference";
}
<form method="post">
<div class="u-form-group u-form-name u-label-top">
<label class="u-label u-text-custom-color-1 u-label-1">План питания: </label>
<div class="u-input u-input-rectangle">
<select id="conference" name="conference" class="form-control" asp-items="@(new SelectList(@ViewBag.Conferences, "Id", "ConferenceName"))"></select>
</div>
</div>
<div class="u-form-group u-form-name u-label-top">
<label class="u-label u-text-custom-color-1 u-label-1">Комната: </label>
<div class="u-input u-input-rectangle">
<select id="conferenceBooking" name="conferenceBooking" class="form-control" asp-items="@(new SelectList(@ViewBag.ConferenceBookings, "Id", "NameHall"))"></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>
</form>

View File

@ -29,6 +29,8 @@
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="ListConferenceBookings">Бронирование</a>
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="AddConferenceBookingToConference">Привязка к конференациям</a>
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="Privacy">Метрдотель</a>
<a class="nav-link " asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>

View File

@ -95,7 +95,7 @@ namespace HotelBusinessLogic.BusinessLogics
_saveToExcel.CreateReport(new ExcelInfoHeadwaiter
{
FileName = model.FileName,
Title = "Список изделий",
Title = "Список участников",
MealPlanDinner = GetMealPlanDinner()
});
}

View File

@ -20,12 +20,14 @@ namespace HotelContracts.ViewModels
public string NameHall { get; set; } = string.Empty;
public Dictionary<int, IDinnerModel> ConferenceBookingDinners { get; set; } = new();
public Dictionary<int, IConferenceBookingModel> ConferenceConferenceBookings { get; set; } = new();
public ConferenceBookingViewModel() { }
[JsonConstructor]
public ConferenceBookingViewModel(Dictionary<int, DinnerViewModel> ConferenceBookingDinners)
public ConferenceBookingViewModel(Dictionary<int, DinnerViewModel> ConferenceBookingDinners, Dictionary<int, ConferenceBookingViewModel> ConferenceConferenceBookings)
{
this.ConferenceBookingDinners = ConferenceBookingDinners.ToDictionary(x => x.Key, x => x.Value as IDinnerModel);
this.ConferenceConferenceBookings = ConferenceConferenceBookings.ToDictionary(x => x.Key, x => x.Value as IConferenceBookingModel);
}
}
}

View File

@ -39,7 +39,7 @@ namespace HotelDataBaseImplement.Models
}
[ForeignKey("ConferenceId")]
public virtual List<ConferenceBooking> ConferenceBookings { get; set; }
public virtual List<ConferenceBooking> ConferenceBookings { get; set; } = new();
[ForeignKey("ConferenceId")]
public virtual List<ConferenceMember> Members { get; set; } = new();

View File

@ -581,5 +581,36 @@ namespace HotelRestApi.Controllers
throw;
}
}
[HttpGet]
public List<ConferenceBookingViewModel>? GetConferenceBookings()
{
try
{
return _conferenceBooking.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка номеров");
throw;
}
}
[HttpGet]
public ConferenceBookingViewModel GetConferenceBookingById(int conferenceBookingId)
{
try
{
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferenceBookingId });
if (elem == null)
return null;
return elem;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId);
throw;
}
}
}
}