Фильтрация по времени

This commit is contained in:
GokaPek 2024-05-30 00:09:06 +04:00
parent 3da62fe249
commit 70560b602e
4 changed files with 43 additions and 22 deletions

View File

@ -217,7 +217,7 @@ namespace UniversityClientApp.Controllers
}
}
[HttpGet]
/*[HttpGet]
public IActionResult ReportDisciplines()
{
if (APIStorekeeper.Client == null)
@ -225,21 +225,28 @@ namespace UniversityClientApp.Controllers
return Redirect("~/Home/Enter");
}
return View();
}
}*/
[HttpGet]
public IActionResult GetReportDisciplines(DateOnly dateFrom, DateOnly dateTo)
public IActionResult ReportDisciplines(DateOnly dateFrom, DateOnly dateTo)
{
if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
// Ïîëó÷àåì äàííûå îò ñåðâåðà
//var reportData = APIStorekeeper.GetRequest<List<ReportDisciplineViewModel>>($"api/disciplines/GetReportDisciplines?datefrom={dateFrom}&dateto={dateTo}");
var reportData = APIStorekeeper.GetRequest<List<ReportDisciplineViewModel>>($"api/discipline/getreportdisciplines");
// Ïåðåäàåì äàííûå â ÷àñòè÷íîå ïðåäñòàâëåíèå
return PartialView("ReportDisciplines", reportData);
if (dateFrom == DateOnly.MinValue || dateTo == DateOnly.MaxValue)
{
return View("ReportDisciplines", null);
}
var reportData = APIStorekeeper.GetRequest<List<ReportDisciplineViewModel>>($"api/discipline/getreportdisciplines?datefrom={dateFrom:yyyy-MM-dd}&dateto={dateTo:yyyy-MM-dd}");
return View("ReportDisciplines", reportData);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -1,7 +1,7 @@
@using UniversityContracts.ViewModels
@model List<ReportDisciplineViewModel>
<form method="get" action="/Home/GetReportDisciplines">
<form method="get" action="/Home/ReportDisciplines">
<div class="text-center">
<h2 class="display-4">Отчёт за период по дисциплинам</h2>
</div>

View File

@ -94,11 +94,25 @@ namespace UniversityDatabaseImplement.Implements
query = query.Where(x => x.TeacherId == model.TeacherId.Value);
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
/*if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value);
}*/
var x = query.Select(x => x.GetViewModel).ToList();
var res = new List<DisciplineViewModel>();
foreach (var item in x) {
if (item.Date > model.DateFrom && item.Date < model.DateTo)
{
res.Add(item);
}
}
return query.Select(x => x.GetViewModel).ToList();
//return query.Select(x => x.GetViewModel).ToList();
return res;
}

View File

@ -33,21 +33,21 @@ namespace UniversityRestApi.Controllers
throw;
}
}
/*[HttpPost]
public List<ReportDisciplineViewModel> GetReportDisciplines(DateOnly dateFrom, DateOnly dateTo)
{
try
{
return _reportLogic.GetDisciplines(new ReportDateRangeBindingModel { DateFrom = dateFrom, DateTo = dateTo });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка дисциплин");
throw;
}
}*/
[HttpGet]
public List<ReportDisciplineViewModel> GetReportDisciplines(DateOnly dateFrom, DateOnly dateTo)
{
try
{
return _reportLogic.GetDisciplines(new ReportDateRangeBindingModel { DateFrom = dateFrom, DateTo = dateTo });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка дисциплин");
throw;
}
}
[HttpPost]
public List<ReportDisciplineViewModel> GetReportDisciplines()
{
try