diff --git a/Repositories/UserPolises/IUserPolisRepository.cs b/Repositories/UserPolises/IUserPolisRepository.cs new file mode 100644 index 0000000..b222989 --- /dev/null +++ b/Repositories/UserPolises/IUserPolisRepository.cs @@ -0,0 +1,14 @@ +using Renis.Database.Models; + +namespace Renis.Repositories; + +public interface IUserPolisRepository +{ + public Task AddUserPolis(UserPolis userPolis); + public Task UpdateUserPolis(UserPolis userPolis); + public Task DeleteUserPolis(UserPolis userPolis); + public Task GetUserPolisById(long id); + public Task GetUserPolisByUserIdAndPolisId(long userId, long polisId); + public IQueryable GetUserPolises(); + public Task Save(); +} \ No newline at end of file diff --git a/Repositories/UserPolises/UserPolisRepository.cs b/Repositories/UserPolises/UserPolisRepository.cs new file mode 100644 index 0000000..0848763 --- /dev/null +++ b/Repositories/UserPolises/UserPolisRepository.cs @@ -0,0 +1,48 @@ +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; + } +}