using Microsoft.EntityFrameworkCore; using Renis.Database; using Renis.Database.Models; namespace Renis.Repositories; public class UserPolisRepository(ApplicationContext db) : IUserPolisRepository { private readonly ApplicationContext _db = db; public async Task AddUserPolis(UserPolis userPolis) { _db.UserPolises.Add(userPolis); return await Save(); } public async Task UpdateUserPolis(UserPolis userPolis) { _db.UserPolises.Update(userPolis); return await Save(); } public async Task DeleteUserPolis(UserPolis userPolis) { _db.UserPolises.Remove(userPolis); return await Save(); } public async Task GetUserPolisById(long id) { return await _db.UserPolises.FirstOrDefaultAsync(x => x.Id == id); } public async Task GetUserPolisByUserIdAndPolisId(long userId, long polisId) { return await _db.UserPolises.FirstOrDefaultAsync(x => x.UserId == userId && x.PolisId == polisId); } public IQueryable GetUserPolises() { return _db.UserPolises.AsQueryable(); } public async Task Save() { return await _db.SaveChangesAsync() > 0; } }