Работает фильтрация

This commit is contained in:
EkaterinaR 2024-11-22 21:17:59 +04:00
parent 9b09498ab2
commit 01ea8b36ca
4 changed files with 114 additions and 13 deletions

View File

@ -20,6 +20,7 @@ using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing.Diagrams;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
namespace EventVisitorClientApp.Controllers
{
@ -186,14 +187,39 @@ namespace EventVisitorClientApp.Controllers
/// Óïðàâëåíèå ìåðîïðèÿòèÿìè
/// </summary>
/// <returns></returns>
public IActionResult MyEvents()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<EventViewModel>>($"api/main/GetEventList?OrganizerId={APIClient.Client.Id}"));
}
public IActionResult MyEvents(string statusFilter, string typeFilter)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var events = APIClient.GetRequest<List<EventViewModel>>($"api/main/GetEventList?OrganizerId={APIClient.Client.Id}");
var currentDateTime = DateTime.Now;
// Ôèëüòðàöèÿ ïî ñòàòóñó
if (!string.IsNullOrEmpty(statusFilter))
{
if (statusFilter == "past")
{
events = events.Where(e => e.TimeStart < currentDateTime).ToList();
}
else if (statusFilter == "future")
{
events = events.Where(e => e.TimeStart > currentDateTime).ToList();
}
}
// Ôèëüòðàöèÿ ïî òèïó
if (!string.IsNullOrEmpty(typeFilter))
{
events = events.Where(e => e.Type.Equals(typeFilter, StringComparison.OrdinalIgnoreCase)).ToList();
}
return View(events);
}
public IActionResult CreateEvent()
{
if (APIClient.Client == null)
@ -284,10 +310,46 @@ namespace EventVisitorClientApp.Controllers
DateTime start = (timestart.HasValue) ? DateTime.SpecifyKind(timestart.Value, DateTimeKind.Utc) : existingEvent.TimeStart.ToUniversalTime();
DateTime end = (timeend.HasValue) ? DateTime.SpecifyKind(timeend.Value, DateTimeKind.Utc) : existingEvent.TimeEnd.ToUniversalTime();
int countRegisterPlace = existingEvent.CountVisitors - existingEvent.FreePlaces;
var visitorList = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
string msg = "";
if (existingEvent.TimeStart != timestart && existingEvent.Address != address)
{
msg = $"Âíèìàíèå! Èçìåíèëàñü äàòà íà÷àëà è àäðåññ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå íà÷íåòñÿ: {timestart} è ïðîéäåò ïî àäðåññó {address}";
}
else if(existingEvent.TimeStart == timestart && existingEvent.Address != address)
{
msg = $"Âíèìàíèå! Èçìåíèëñÿ àäðåññ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå ïðîéäåò ïî àäðåññó {address}";
}
else if(existingEvent.TimeStart != timestart && existingEvent.Address == address)
{
msg = $"Âíèìàíèå! Èçìåíèëîñü âðåìÿ íà÷àëà ìåðîïðèÿòèÿ ìåðîïðèÿòèÿ {existingEvent.Name}. Ìåðîïðèÿòèå íà÷íåòñÿ: {timestart}";
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
{
MailAddress = email,
Subject = "Èçìåíåíèÿ â ìåðîïðèÿòèè",
Text = msg
});
}
if (msg != "")
{
if (visitorList.Count != 0)
{
foreach (var visitor in visitorList)
{
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
{
MailAddress = visitor.Email,
Subject = "Èçìåíåíèÿ â ìåðîïðèÿòèè",
Text = msg
});
}
}
}
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
{
Id = id,
Name = name,
Name = existingEvent.Name,
Description = description,
Type = type,
ContactPhone = phone,

View File

@ -12,10 +12,35 @@
<div class="text-center mt-4">
@{
<p>
<a class="btn btn-light" asp-action="CreateEvent">Создать мероприятие</a>
</p>
<form method="get" class="row">
<div class="col-md-4 mb-3">
<label for="statusFilter">Фильтр по статусу:</label>
<select class="form-control" id="statusFilter" name="statusFilter">
<option value="">Все</option>
<option value="future">Будущие</option>
<option value="past">Прошедшие</option>
</select>
</div>
<div class="col-md-4 mb-3">
<label for="typeFilter">Фильтр по типу:</label>
<select class="form-control" id="typeFilter" name="typeFilter">
<option value="">Все</option>
<option value="Конференция">Конференция</option>
<option value="Встреча">Встреча</option>
<option value="Семинар">Семинар</option>
<option value="Тренинг">Тренинг</option>
<option value="Фестиваль">Фестиваль</option>
<option value="Соревнование">Соревнование</option>
<option value="Другое">Другое</option>
</select>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-primary btn-block">Применить фильтр</button>
</div>
</form>
<table class="table table-striped table-bordered mt-4">
<thead class="thead-light">
<tr>
@ -75,4 +100,20 @@
.btn-light:hover {
background-color: #d3d3d3; /* Более тёмный светло-серый при наведении */
}
.row {
display: flex; /* Включаем Flexbox */
flex-wrap: wrap; /* Разрешаем перенос на следующую строку при необходимости */
align-items: center; /* Выравнивание по вертикали */
}
.col-md-4 {
flex: 1; /* Делаем элементы одинаковой ширины */
margin-right: 10px; /* Добавляем отступ между элементами */
}
.btn-block {
width: 100%;
background-color:black;
}
</style>

View File

@ -9,8 +9,7 @@
<div class="row mb-3">
<label for="name" class="col-sm-4 col-form-label">Название мероприятия:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="name" name="name" value="@Html.DisplayFor(model => model.Name)" required>
<div class="invalid-feedback">Пожалуйста, введите название мероприятия.</div>
<input type="text" class="form-control" id="name" name="name" value="@Html.DisplayFor(model => model.Name)" disabled>
</div>
</div>
<div class="row mb-3">

View File

@ -38,7 +38,6 @@ namespace EventVisitorDatabase.Implements
public List<EventViewModel> GetFilteredList(EventBindingModel model)
{
using var context = new EventVisitorDbContext();
return context.Events
.Include(x => x.Organizer)
.Where(x => x.OrganizerId == model.OrganizerId).Select(x => x.GetViewModel).ToList();