Реализован поиск посетителей и удаление посетителей с мероприятия

This commit is contained in:
EkaterinaR 2024-11-19 10:28:03 +04:00
parent 1fdcf756f9
commit 9b09498ab2
4 changed files with 122 additions and 43 deletions

View File

@ -16,6 +16,10 @@ using DocumentFormat.OpenXml.Office2010.Excel;
using System.Text; using System.Text;
using System.Security.Cryptography; using System.Security.Cryptography;
using DocumentFormat.OpenXml.Spreadsheet; using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing.Diagrams;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using DocumentFormat.OpenXml.Wordprocessing;
namespace EventVisitorClientApp.Controllers namespace EventVisitorClientApp.Controllers
{ {
@ -306,22 +310,32 @@ namespace EventVisitorClientApp.Controllers
/// </summary> /// </summary>
/// <param></param> /// <param></param>
/// <returns></returns> /// <returns></returns>
///
public IActionResult Visitors(int id) public IActionResult Visitors(int id)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
var allVisitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}"); // Ïîëó÷èòå âñåõ ïîñåòèòåëåé
return View(allVisitors); var visitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
return View(visitors);
}
[HttpPost]
public IActionResult Visitors(int id, string action, string searchTerm, [FromForm] List<int> presentIds)
{
// Ïîëó÷èòå âñåõ ïîñåòèòåëåé
var visitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
if (action == "search" && !string.IsNullOrEmpty(searchTerm))
{
visitors = visitors.Where(v => v.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) ||
v.Email.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)).ToList();
} }
[HttpPost] if (action == "save")
public void Visitors(int id, [FromForm] List<int> presentIds)
{ {
var allVisitors = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}"); foreach (var visitor in visitors)
foreach (var visitor in allVisitors)
{ {
var status = presentIds.Contains(visitor.Id) ? "Ïðèøåë" : "Çàðåãèñòðèðîâàí"; var status = presentIds.Contains(visitor.Id) ? "Ïðèøåë" : "Çàðåãèñòðèðîâàí";
APIClient.PostRequest("api/main/updatevisitor", new VisitorBindingModel APIClient.PostRequest("api/main/updatevisitor", new VisitorBindingModel
@ -330,6 +344,43 @@ namespace EventVisitorClientApp.Controllers
Status = status Status = status
}); });
} }
// Ïîñëå ñîõðàíåíèÿ ïåðåíàïðàâëÿåì îáðàòíî íà ýòîò æå ìåòîä ñ id
return RedirectToAction("Visitors", new { id });
}
return View(visitors); // Âåðíóòü ïðåäñòàâëåíèå ñ îòôèëüòðîâàííûì ñïèñêîì
}
public IActionResult DeleteVisitor(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var existingVisitor = APIClient.GetRequest<VisitorViewModel>($"api/main/GetVisitor?VisitorId={id}");
var existingEvent = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={existingVisitor.EventId}");
int eventId = existingEvent.Id;
APIClient.PostRequest($"api/main/DeleteVisitor", new VisitorBindingModel { Id = id });
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
{
Id = existingVisitor.EventId,
Name = existingEvent.Name,
Description = existingEvent.Description,
Type = existingEvent.Type,
ContactPhone = existingEvent.ContactPhone,
Address = existingEvent.Address,
City = existingEvent.City,
Status = existingEvent.Status,
ContactEmail = existingEvent.ContactEmail,
TimeEnd = existingEvent.TimeEnd,
TimeStart = existingEvent.TimeStart,
Date = existingEvent.Date.ToUniversalTime(),
CountVisitors = existingEvent.CountVisitors,
FreePlaces = existingEvent.FreePlaces + 1,
OrganizerId = APIClient.Client.Id
});
return Redirect($"~/Home/Visitors/{eventId}");
} }
public IActionResult ResultRegistration() public IActionResult ResultRegistration()

View File

@ -9,10 +9,20 @@
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Зарегистрированные пользователи</h1> <h1 class="display-4">Зарегистрированные пользователи</h1>
</div> </div>
<form method="post"> <form method="post" action="/Home/Visitors">
<div class="text-center mt-4"> <input type="hidden" name="id" value="@Model.FirstOrDefault()?.EventId" /> <!-- Предполагается, что EventId доступен в модели-->
@{
<table class="table table-striped table-bordered mt-4"> <div class="form-group row mt-4">
<div class="col-md-10">
<input type="text" name="searchTerm" placeholder="Поиск по имени или почте" class="form-control" />
</div>
<div class="col-md-2">
<button type="submit" style="background-color:black; color: white; width: 100%; font-size: 20px; border-radius: 5px;" name="action" value="search">Поиск</button>
</div>
</div>
<div class="table-responsive mt-4">
<table class="table table-striped table-bordered">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
<th>Имя</th> <th>Имя</th>
@ -20,6 +30,7 @@
<th>Телефон</th> <th>Телефон</th>
<th>Дата рождения</th> <th>Дата рождения</th>
<th></th> <th></th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -40,15 +51,18 @@
<label class="form-check-label" for="present_@item.Id">Да</label> <label class="form-check-label" for="present_@item.Id">Да</label>
</div> </div>
</td> </td>
<td>
<a class="btn btn-danger btn-sm" asp-action="DeleteVisitor" asp-route-id="@item.Id">Удалить</a>
</td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
} <button type="submit" id="saveButton" style="background-color:black; color: white; width: 100%; font-size: 20px; border-radius: 5px;" name="action" value="save">Сохранить</button>
<button type="submit" id="saveButton" class="btn btn-black btn-block">Сохранить</button> </div>
</form> </form>
</div> </div>
</div>
<style> <style>
body { body {
@ -58,17 +72,4 @@
.table { .table {
margin-top: 20px; margin-top: 20px;
} }
.btn {
transition: background-color 0.3s ease;
}
.btn-light {
background-color: #e9ecef; /* Светло-серый цвет */
color: #495057; /* Тёмный текст для контраста */
}
.btn-light:hover {
background-color: #d3d3d3; /* Более тёмный светло-серый при наведении */
}
</style> </style>

View File

@ -30,7 +30,6 @@ namespace EventVisitorLogic.Logic
public bool Delete(VisitorBindingModel model) public bool Delete(VisitorBindingModel model)
{ {
CheckModel(model, false);
if (_visitorStorage.Delete(model) == null) if (_visitorStorage.Delete(model) == null)
{ {
return false; return false;

View File

@ -155,6 +155,21 @@ namespace EventVisitorRestApi.Controllers
} }
} }
[HttpGet]
public VisitorViewModel? GetVisitor(int visitorId)
{
try
{
return _visitor.ReadElement(new VisitorBindingModel
{
Id = visitorId
});
}
catch (Exception ex)
{
throw;
}
}
[HttpPost] [HttpPost]
public void UpdateVisitor(VisitorBindingModel model) public void UpdateVisitor(VisitorBindingModel model)
{ {
@ -168,6 +183,19 @@ namespace EventVisitorRestApi.Controllers
} }
} }
[HttpPost]
public void DeleteVisitor(VisitorBindingModel model)
{
try
{
_visitor.Delete(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost] [HttpPost]
public void DeleteEvent(EventBindingModel model) public void DeleteEvent(EventBindingModel model)
{ {