diff options
Diffstat (limited to 'Services')
-rw-r--r-- | Services/IRaffleService.cs | 1 | ||||
-rw-r--r-- | Services/RaffleService.cs | 9 | ||||
-rw-r--r-- | Services/UserAccountService.cs | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/Services/IRaffleService.cs b/Services/IRaffleService.cs index 2ee8b10..5102af2 100644 --- a/Services/IRaffleService.cs +++ b/Services/IRaffleService.cs @@ -10,5 +10,6 @@ namespace BackendPIA.Services { public Task<IEnumerable<int>> GetTakenTickets(long id); public IEnumerable<Ticket> GetRaffleTickets(long id); public Task<IEnumerable<RaffleWinner>> GetRaffleWinners(long id); + public bool RaffleExists(long id); } }
\ No newline at end of file diff --git a/Services/RaffleService.cs b/Services/RaffleService.cs index 5d1901f..bbc20f4 100644 --- a/Services/RaffleService.cs +++ b/Services/RaffleService.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using BackendPIA.Models; +using BackendPIA.Forms; namespace BackendPIA.Services { public class RaffleService : IRaffleService { @@ -65,5 +66,13 @@ namespace BackendPIA.Services { return await _context.RaffleWinners.Include(rw => rw.UserAccount).Include(rw => rw.Raffle).Include(rw => rw.Prize) .Where(rw => rw.RaffleId == id).ToListAsync(); } + + public bool RaffleExists(long id) { + return _context.Raffles.Any(r => r.Id == id); + } + + public IEnumerable<Prize> GetRafflePrizes(long id) { + return _context.Prizes.Where(p => p.RaffleId == id).ToList(); + } } }
\ No newline at end of file diff --git a/Services/UserAccountService.cs b/Services/UserAccountService.cs index eccaff3..2ae3240 100644 --- a/Services/UserAccountService.cs +++ b/Services/UserAccountService.cs @@ -5,9 +5,11 @@ using BackendPIA.Forms; namespace BackendPIA.Services { public class UserAccountService : IUserAccountService { private readonly UserManager<UserAccount> _manager; + private readonly ApplicationDbContext _context; - public UserAccountService(UserManager<UserAccount> manager) { + public UserAccountService(UserManager<UserAccount> manager, ApplicationDbContext context) { _manager = manager; + _context = context; } public async Task<IdentityResult> CreateUserAccount(UserAccount user, string password, string role) { @@ -22,6 +24,9 @@ namespace BackendPIA.Services { public async Task<UserAccount> GetUserAccount(string email) { var result = await _manager.FindByEmailAsync(email); + if(result != null) + result.Tickets = _context.Tickets.Where(t => t.Owner == result).ToList(); + return result; } } |