renis-backend/Repositories/PolisRepository.cs

49 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using Renis.Database;
using Renis.Database.Models;
namespace Renis.Repositories;
public class PolisRepository(ApplicationContext db) : IPolisRepository
{
private readonly ApplicationContext _db = db;
public async Task<bool> AddPolis(Polis polis)
{
_db.Polises.Add(polis);
return await Save();
}
public async Task<bool> DeletePolis(Polis polis)
{
_db.Polises.Remove(polis);
return await Save();
}
public async Task<Polis?> GetPolisById(long id)
{
return await _db.Polises.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task<Polis?> GetPolisByNumber(string number)
{
return await _db.Polises.FirstOrDefaultAsync(x => x.Number == number);
}
public IQueryable<Polis> GetPolises()
{
return _db.Polises.AsQueryable();
}
public async Task<bool> Save()
{
return await _db.SaveChangesAsync() > 0;
}
public async Task<bool> UpdatePolis(Polis polis)
{
_db.Polises.Update(polis);
return await Save();
}
}