summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Controllers/RafflesController.cs2
-rw-r--r--Logics/RafflePlayLogic.cs6
-rw-r--r--Services/IRaffleService.cs1
-rw-r--r--Services/RaffleService.cs4
4 files changed, 10 insertions, 3 deletions
diff --git a/Controllers/RafflesController.cs b/Controllers/RafflesController.cs
index 0da75d5..9f50449 100644
--- a/Controllers/RafflesController.cs
+++ b/Controllers/RafflesController.cs
@@ -120,7 +120,7 @@ namespace BackendPIA.Controllers {
if(raffle == null)
return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't exist."));
- var prizes = _service.GetRaffleTickets(id);
+ var prizes = _service.GetRafflePrizes(id);
return Ok(_mapper.Map<IEnumerable<PrizeDTO>>(prizes));
}
diff --git a/Logics/RafflePlayLogic.cs b/Logics/RafflePlayLogic.cs
index 74591b6..06cf0c5 100644
--- a/Logics/RafflePlayLogic.cs
+++ b/Logics/RafflePlayLogic.cs
@@ -37,6 +37,12 @@ namespace BackendPIA.Logics {
return false;
}
+ if(raffle.Prizes.Count() < raffle.Winners) {
+ ErrorMessage = $"Can't play: not enough prizes.";
+
+ return false;
+ }
+
Winners = await _game_service.GetWinners(_raffle_id);
return true;
diff --git a/Services/IRaffleService.cs b/Services/IRaffleService.cs
index 5102af2..d706d66 100644
--- a/Services/IRaffleService.cs
+++ b/Services/IRaffleService.cs
@@ -10,6 +10,7 @@ namespace BackendPIA.Services {
public Task<IEnumerable<int>> GetTakenTickets(long id);
public IEnumerable<Ticket> GetRaffleTickets(long id);
public Task<IEnumerable<RaffleWinner>> GetRaffleWinners(long id);
+ public IEnumerable<Prize> GetRafflePrizes(long id);
public bool RaffleExists(long id);
}
} \ No newline at end of file
diff --git a/Services/RaffleService.cs b/Services/RaffleService.cs
index bbc20f4..b0890a4 100644
--- a/Services/RaffleService.cs
+++ b/Services/RaffleService.cs
@@ -35,11 +35,11 @@ namespace BackendPIA.Services {
if(String.IsNullOrEmpty(query))
return await _context.Raffles.ToListAsync();
- return _context.Raffles.Where(r => r.Name == query);
+ return _context.Raffles.FromSql($"SELECT * FROM \"Raffles\" AS r WHERE r.\"Name\" ILIKE {query}").ToList();
}
public async Task<Raffle> GetRaffle(long id) {
- return await _context.Raffles.FindAsync(id);
+ return await _context.Raffles.Include(r => r.Prizes).FirstOrDefaultAsync(r => r.Id == id);
}
public async Task<bool> DeleteRaffle(long id) {