using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.JsonPatch; using BackendPIA.Models; namespace BackendPIA.Services { public class PrizeService : IPrizeService { private readonly ApplicationDbContext _context; public PrizeService(ApplicationDbContext context) { _context = context; } public async Task CreatePrize(Prize to_create) { await _context.AddAsync(to_create); await _context.SaveChangesAsync(); to_create.Raffle = _context.Raffles.Find(to_create.RaffleId); return to_create; } public async Task> GetPrizes() { return await _context.Prizes.Include(p => p.Raffle).ToListAsync(); } public async Task GetPrize(long id) { return await _context.Prizes.Include(p => p.Raffle).FirstOrDefaultAsync(p => p.Id == id); } public async Task DeletePrize(long id) { var prize = _context.Prizes.Find(id); if(prize == null) return false; _context.Remove(prize); _context.SaveChangesAsync(); return true; } } }