refactor: route searching is starting only if departure/arrival city and date is specified

This commit is contained in:
cuqmbr 2022-04-02 14:22:27 +03:00
parent 7c536032b6
commit 8fd36aeec8
2 changed files with 22 additions and 5 deletions

View File

@ -40,7 +40,7 @@
</div> </div>
</form> </form>
@if (Model.Routes != null) @if (Model.Routes != null && Model.Routes.Count > 0)
{ {
<div class="route-list"> <div class="route-list">
<table> <table>
@ -172,6 +172,12 @@
</table> </table>
</div> </div>
} }
else if (Model.Routes == null)
{
<div class="search-error">
<p>Введіть дату й місто відправлення або прибуття</p>
</div>
}
else else
{ {
<div class="search-error"> <div class="search-error">

View File

@ -8,7 +8,7 @@ namespace TicketOffice.Pages.Routes;
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
public List<Route> Routes { get; set; } = null!; public List<Route> Routes { get; set; }
[BindProperty(SupportsGet = true)] public string From { get; set; } [BindProperty(SupportsGet = true)] public string From { get; set; }
[BindProperty(SupportsGet = true)] public string To { get; set; } [BindProperty(SupportsGet = true)] public string To { get; set; }
[BindProperty(SupportsGet = true)] public DateTime Date { get; set; } = new DateTime(2022, 03, 28, 0, 0, 0).Date; [BindProperty(SupportsGet = true)] public DateTime Date { get; set; } = new DateTime(2022, 03, 28, 0, 0, 0).Date;
@ -22,8 +22,11 @@ public class IndexModel : PageModel
} }
public void OnGet() public void OnGet()
{
if (!string.IsNullOrWhiteSpace(From) || !string.IsNullOrWhiteSpace(To))
{ {
RetrieveAllRoutes(); RetrieveAllRoutes();
}
if (!string.IsNullOrWhiteSpace(From)) if (!string.IsNullOrWhiteSpace(From))
{ {
@ -35,8 +38,11 @@ public class IndexModel : PageModel
FilterRoutesByTo(); FilterRoutesByTo();
} }
if (!string.IsNullOrWhiteSpace(From) || !string.IsNullOrWhiteSpace(To))
{
FilterRoutesByDate(); FilterRoutesByDate();
} }
}
public void OnGetSortByNumber() public void OnGetSortByNumber()
{ {
@ -119,6 +125,11 @@ public class IndexModel : PageModel
}); });
} }
public void OnGetBuyTicket(int routeId)
{
}
private void RetrieveAllRoutes() private void RetrieveAllRoutes()
{ {
Routes = _context.Route Routes = _context.Route