fix: add place already taken validation

This commit is contained in:
cuqmbr 2022-05-13 10:16:45 +03:00
parent 8141ac5307
commit 6413d88ffc

View File

@ -23,7 +23,7 @@ public class IndexModel : PageModel
private readonly TicketOfficeContext _context;
public IndexModel(TicketOfficeContext context, ILogger<IndexModel> logger)
public IndexModel(TicketOfficeContext context)
{
_context = context;
}
@ -195,6 +195,14 @@ public class IndexModel : PageModel
validationError = "Поле має бути заповненим";
return false;
}
Ticket? ticket = _context.Ticket.FirstOrDefault(t => t.RouteId == Ticket.RouteId && t.PassengerPlace == Ticket.PassengerPlace);
if (ticket is not null)
{
validationError = "Місце вже зайняте";
return false;
}
validationError = String.Empty;
return true;