38 lines
983 B
C#
38 lines
983 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using TicketAppIncrArchi.Domain.Entities;
|
|
using TicketAppIncrArchi.Application.Interfaces;
|
|
using TicketAppIncrArchi.Infrastructure.Persistence;
|
|
|
|
|
|
public class TicketRepository : ITicketRepository
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public TicketRepository(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Ticket?> GetByIdAsync(Guid id)
|
|
=> await _context.Tickets.FindAsync(id);
|
|
|
|
public async Task<List<Ticket>> GetAllAsync()
|
|
=> await _context.Tickets.ToListAsync();
|
|
|
|
public async Task<Ticket> AddAsync(Ticket ticket)
|
|
{
|
|
_context.Tickets.Add(ticket);
|
|
await _context.SaveChangesAsync();
|
|
return(ticket);
|
|
}
|
|
|
|
public async Task DeleteAsync(Guid id)
|
|
{
|
|
var ticket = await _context.Tickets.FindAsync(id);
|
|
if (ticket is null) return;
|
|
|
|
_context.Tickets.Remove(ticket);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|