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; private readonly TicketOfficeContext _context;
public IndexModel(TicketOfficeContext context, ILogger<IndexModel> logger) public IndexModel(TicketOfficeContext context)
{ {
_context = context; _context = context;
} }
@ -196,6 +196,14 @@ public class IndexModel : PageModel
return false; 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; validationError = String.Empty;
return true; return true;
} }