diff options
Diffstat (limited to 'Logics')
-rw-r--r-- | Logics/CreateTicketLogic.cs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Logics/CreateTicketLogic.cs b/Logics/CreateTicketLogic.cs index df64a1a..be3c66c 100644 --- a/Logics/CreateTicketLogic.cs +++ b/Logics/CreateTicketLogic.cs @@ -24,17 +24,26 @@ namespace BackendPIA.Logics { } public async Task<bool> Call() { + var raffle = _context.Raffles.Find(_raffle_id); + // Check if the user exists. if(_user == null) return false; // Check if the given raffle exists- - if(!_context.Raffles.Any(r => r.Id == _raffle_id)) { + if(raffle == null) { ErrorMessage = "The raffle doesn't exist."; return false; } + // Check if the raffle has already closed. + if(raffle.IsClosed) { + ErrorMessage = "The raffle is already closed."; + + return false; + } + // Check if the user already has a ticket for the given raffle. if(_context.Tickets.Where(t => t.RaffleId == _raffle_id).Where(t => t.UserAccountId == _user.Id).Count() > 0) { ErrorMessage = $"There's already a ticket for {_user.UserName}."; |