crud для участников

This commit is contained in:
AnnZhimol 2023-05-14 21:46:57 +04:00
parent 9a06e6dc58
commit f1f9def74c
13 changed files with 577 additions and 32 deletions

View File

@ -16,6 +16,118 @@ namespace HotelOrganiserApp.Controllers
_logger = logger; _logger = logger;
} }
public IActionResult CreateMember()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void CreateMember(string fio, string citizenship)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(fio) || string.IsNullOrEmpty(citizenship))
{
throw new Exception("Введите фио");
}
if (string.IsNullOrEmpty(citizenship))
{
throw new Exception("Введите гражданство");
}
APIClient.PostRequest("api/main/createmember", new MemberBindingModel
{
MemberFIO = fio,
Citizenship = citizenship,
OrganiserId = APIClient.Organiser.Id,
});
Response.Redirect("ListMembers");
}
public IActionResult UpdateMember()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Members = APIClient.GetRequest<List<MemberViewModel>>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void UpdateMember(int member, string fio, string citizenship)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(fio))
{
throw new Exception("фио не может быть пустым");
}
if (string.IsNullOrEmpty(citizenship))
{
throw new Exception("Гражданство не может быть пустым");
}
APIClient.PostRequest("api/main/updatemember", new MemberBindingModel
{
Id = member,
MemberFIO = fio,
Citizenship = citizenship,
OrganiserId = APIClient.Organiser.Id,
});
Response.Redirect("ListMembers");
}
public IActionResult DeleteMember()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Members = APIClient.GetRequest<List<MemberViewModel>>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}");
return View();
}
[HttpPost]
public void DeleteMember(int member)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
APIClient.PostRequest("api/main/deletemember", new MemberBindingModel
{
Id = member
});
Response.Redirect("ListMembers");
}
[HttpGet]
public MemberViewModel? GetMember(int memberId)
{
if (APIClient.Organiser == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<MemberViewModel>($"api/main/getmember?memberid={memberId}");
if (result == null)
{
return default;
}
var memberFIO = result.MemberFIO;
var citizenship = result.Citizenship;
return result;
}
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.Organiser == null) if (APIClient.Organiser == null)
@ -25,6 +137,15 @@ namespace HotelOrganiserApp.Controllers
return View(); return View();
} }
public IActionResult ListMembers()
{
if (APIClient.Organiser == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<MemberViewModel>>($"api/main/getmemberlist?organiserId={APIClient.Organiser.Id}"));
}
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {

View File

@ -0,0 +1,31 @@
@{
ViewData["Title"] = "CreateMember";
}
<head>
<link rel="stylesheet" href="~/css/createmember.css" asp-append-version="true" />
</head>
<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>
<input
type="text"
placeholder="Введите ФИО участника"
name="fio"
class="u-input u-input-rectangle"/>
</div>
<div class="u-form-email u-form-group u-label-top">
<label class="u-label u-text-custom-color-1 u-label-2">Гражданство</label>
<input
type="text"
placeholder="Введите гражданство участника"
name="citizenship"
class="u-input u-input-rectangle"/>
</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

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteMember";
}
<head>
<link rel="stylesheet" href="~/css/createmember.css" asp-append-version="true" />
</head>
<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="member" name="member" class="form-control" asp-items="@(new SelectList(@ViewBag.Members, "Id", "MemberFIO"))"></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

@ -28,7 +28,7 @@
name="password" name="password"
class="u-input u-input-rectangle u-input-2"/> class="u-input u-input-rectangle u-input-2"/>
</div> </div>
<div class="u-align-center u-form-group u-form-submit u-label-top"> <div class="u-align-center u-form-group u-form-submit u-label-top" style="padding-bottom: 120px">
<div class="col-8"></div> <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="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> </div>

View File

@ -32,7 +32,7 @@
> >
<div <div
class="u-container-layout u-valign-top u-container-layout-2" class="u-container-layout u-valign-top u-container-layout-2"
style="padding: 120px" style="padding-bottom: 120px"
> >
<img <img
class="u-image u-image-contain u-image-1" class="u-image u-image-contain u-image-1"

View File

@ -0,0 +1,89 @@
@using HotelContracts.ViewModels
@model List<MemberViewModel>
@{
ViewData["Title"] = "ListMembers";
}
<head>
<link rel="stylesheet" href="~/css/listmembers.css" asp-append-version="true" />
</head>
<section class="u-clearfix u-section-1" id="sec-e38b">
<div class="u-clearfix u-sheet u-sheet-1">
<div class="u-clearfix u-layout-wrap u-layout-wrap-1">
<div class="u-layout">
<div class="u-layout-row">
<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="u-table u-table-responsive u-table-1">
<table class="u-table-entity">
<colgroup>
<col width="9.8%" />
<col width="62.9%" />
<col width="27.3%" />
</colgroup>
<thead
class="u-custom-color-1 u-table-header u-table-header-1">
<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.MemberFIO)
</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.Citizenship)
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<div
class="u-container-style u-layout-cell u-size-12 u-layout-cell-2"
>
<div class="u-container-layout u-container-layout-2">
<a
asp-area="" asp-controller="Home" asp-action="CreateMember"
class="u-active-custom-color-6 u-border-none u-btn u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1"
>Добавить</a>
<a
asp-area="" asp-controller="Home" asp-action="UpdateMember"
class="u-active-custom-color-6 u-border-none u-btn u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-2"
>иЗМЕНИТЬ</a>
<a
asp-area="" asp-controller="Home" asp-action="DeleteMember"
class="u-active-custom-color-6 u-border-none u-btn u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-3"
>Удалить</a>
</div>
</div>
</div>
</div>
</div>
</div>
</section>

View File

@ -1,25 +0,0 @@

@{
ViewData["Title"] = "ListOfMembers";
}
<div class="text-center">
<h1 class="display-4">Участники</h1>
</div>
<form method="post">
<div class="form-group">
<label for="exampleFormControlSelect2">Доступные для выбора участники</label>
<select multiple class="form-control" id="exampleFormControlSelect2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<button type="button" class="btn btn-lg btn-primary" disabled>Word</button>
<button type="button" class="btn btn-lg btn-primary" disabled>Excel</button>
<button type="button" class="btn btn-secondary btn-lg" disabled>Отмена</button>
</form>

View File

@ -49,7 +49,7 @@
class="u-input u-input-rectangle"/> class="u-input u-input-rectangle"/>
</div> </div>
<div class="u-align-center u-form-group u-form-submit u-label-top" <div class="u-align-center u-form-group u-form-submit u-label-top"
style="padding: 120px"> style="padding-bottom: 120px">
<div class="col-8"></div> <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="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> </div>

View File

@ -0,0 +1,67 @@
@using HotelContracts.ViewModels;
@using HotelDataModels.Models;
@{
ViewData["Title"] = "UpdateMember";
}
<head>
<link rel="stylesheet" href="~/css/createmember.css" asp-append-version="true" />
</head>
<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="member" name="member" class="form-control" asp-items="@(new SelectList(@ViewBag.Members, "Id", "MemberFIO"))"></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>
<input
type="text"
id="fio"
placeholder="Введите ФИО участника"
name="fio"
class="u-input u-input-rectangle"/>
</div>
<div class="u-form-email u-form-group u-label-top">
<label class="u-label u-text-custom-color-1 u-label-2">Гражданство</label>
<input
type="text"
id="citizenship"
placeholder="Введите гражданство участника"
name="citizenship"
class="u-input u-input-rectangle"/>
</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>
@section Scripts
{
<script>
function check() {
var member = $('#member').val();
if (member) {
$.ajax({
method: "GET",
url: "/Home/GetMember",
data: { memberId: member },
success: function (result) {
$('#fio').val(result.memberFIO);
$('#citizenship').val(result.citizenship);
}
});
};
}
check();
$('#member').on('change', function () {
check();
});
</script>
}

View File

@ -0,0 +1,82 @@
.u-section-1 .u-sheet-1 {
min-height: 370px;
}
.u-section-1 .u-layout-wrap-1 {
margin-top: 40px;
margin-bottom: 40px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 290px;
}
.u-section-1 .u-container-layout-1 {
padding: 0 30px;
}
.u-section-1 .u-form-1 {
left: 0;
right: auto;
}
.u-section-1 .u-label-1 {
font-weight: 700;
}
.u-section-1 .u-label-2 {
font-weight: 700;
}
.u-section-1 .u-btn-1 {
background-image: none;
}
@media (max-width: 1199px) {
.u-section-1 .u-sheet-1 {
min-height: 342px;
}
.u-section-1 .u-layout-wrap-1 {
position: relative;
}
.u-section-1 .u-layout-cell-1 {
min-height: 239px;
}
}
@media (max-width: 991px) {
.u-section-1 .u-sheet-1 {
min-height: 277px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 183px;
}
}
@media (max-width: 767px) {
.u-section-1 .u-sheet-1 {
min-height: 508px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 137px;
}
.u-section-1 .u-container-layout-1 {
padding-left: 10px;
padding-right: 10px;
}
}
@media (max-width: 575px) {
.u-section-1 .u-sheet-1 {
min-height: 345px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 86px;
}
}

View File

@ -0,0 +1,137 @@
.u-section-1 .u-sheet-1 {
min-height: 506px;
}
.u-section-1 .u-layout-wrap-1 {
width: 965px;
margin: 39px auto 60px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 400px;
}
.u-section-1 .u-container-layout-1 {
padding: 9px 0;
}
.u-section-1 .u-table-1 {
width: 694px;
margin: 16px auto 0;
}
.u-section-1 .u-table-header-1 {
font-weight: 700;
background-image: none;
}
.u-section-1 .u-layout-cell-2 {
min-height: 400px;
}
.u-section-1 .u-container-layout-2 {
padding: 30px 11px;
}
.u-section-1 .u-btn-1 {
font-weight: 700;
text-transform: uppercase;
letter-spacing: 1px;
background-image: none;
margin: 0 auto;
padding: 10px 34px 10px 33px;
}
.u-section-1 .u-btn-2 {
font-weight: 700;
text-transform: uppercase;
letter-spacing: 1px;
background-image: none;
margin: 20px auto 0;
}
.u-section-1 .u-btn-3 {
font-weight: 700;
text-transform: uppercase;
letter-spacing: 1px;
background-image: none;
margin: 20px auto 0;
padding: 10px 37px 10px 36px;
}
.u-section-1 .u-btn-4 {
font-weight: 700;
text-transform: uppercase;
letter-spacing: 1px;
background-image: none;
margin: 20px auto 0;
}
@media (max-width: 1199px) {
.u-section-1 .u-sheet-1 {
min-height: 436px;
}
.u-section-1 .u-layout-wrap-1 {
width: 940px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 390px;
}
.u-section-1 .u-table-1 {
width: 470px;
}
.u-section-1 .u-layout-cell-2 {
min-height: 390px;
}
}
@media (max-width: 991px) {
.u-section-1 .u-sheet-1 {
min-height: 206px;
}
.u-section-1 .u-layout-wrap-1 {
width: 720px;
}
.u-section-1 .u-layout-cell-1 {
min-height: 100px;
}
.u-section-1 .u-table-1 {
width: 360px;
}
.u-section-1 .u-layout-cell-2 {
min-height: 100px;
}
}
@media (max-width: 767px) {
.u-section-1 .u-sheet-1 {
min-height: 306px;
}
.u-section-1 .u-layout-wrap-1 {
width: 540px;
}
.u-section-1 .u-container-layout-2 {
padding-left: 10px;
padding-right: 10px;
}
}
@media (max-width: 575px) {
.u-section-1 .u-layout-wrap-1 {
width: 340px;
}
.u-section-1 .u-table-1 {
width: 340px;
}
}

View File

@ -49321,10 +49321,7 @@ blockquote {
.u-footer { .u-footer {
background-image: none; background-image: none;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
} }
.u-footer .u-sheet-1 { .u-footer .u-sheet-1 {

View File

@ -76,6 +76,20 @@ namespace HotelRestApi.Controllers
} }
} }
[HttpPost]
public void UpdateMember(MemberBindingModel model)
{
try
{
_member.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
[HttpGet] [HttpGet]
public MemberViewModel? GetMember(int memberId) public MemberViewModel? GetMember(int memberId)
{ {
@ -107,6 +121,20 @@ namespace HotelRestApi.Controllers
} }
} }
[HttpPost]
public void DeleteMember(MemberBindingModel model)
{
try
{
_member.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления участника");
throw;
}
}
[HttpPost] [HttpPost]
public void CreateConference(ConferenceBindingModel model) public void CreateConference(ConferenceBindingModel model)
{ {