From f669a44a29fe83b03837c07d722a43e40e12ed47 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 7 Sep 2024 12:02:42 +0300 Subject: [PATCH 1/2] User repo --- Repositories/IUserRepository.cs | 14 ++++++++++ Repositories/UserRepository.cs | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Repositories/IUserRepository.cs create mode 100644 Repositories/UserRepository.cs diff --git a/Repositories/IUserRepository.cs b/Repositories/IUserRepository.cs new file mode 100644 index 0000000..c83ce1f --- /dev/null +++ b/Repositories/IUserRepository.cs @@ -0,0 +1,14 @@ +using Renis.Database.Models; + +namespace Renis.Repositories; + +public interface IUserRepository +{ + public Task AddUser(User user); + public Task UpdateUser(User user); + public Task DeleteUser(User user); + public Task GetUserById(long id); + public Task GetUserByPhone(string phone); + public IQueryable GetUsers(); + public Task Save(); +} \ No newline at end of file diff --git a/Repositories/UserRepository.cs b/Repositories/UserRepository.cs new file mode 100644 index 0000000..3353af6 --- /dev/null +++ b/Repositories/UserRepository.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using Renis.Database; +using Renis.Database.Models; + +namespace Renis.Repositories; + +public class UserRepository(ApplicationContext db) : IUserRepository +{ + private readonly ApplicationContext _db = db; + + public async Task AddUser(User user) + { + _db.Users.Add(user); + return await Save(); + } + + public async Task DeleteUser(User user) + { + _db.Users.Remove(user); + return await Save(); + } + + public async Task GetUserById(long id) + { + return await _db.Users.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task GetUserByPhone(string phone) + { + return await _db.Users.FirstOrDefaultAsync(x => x.Phone == phone); + } + + public IQueryable GetUsers() + { + return _db.Users.AsQueryable(); + } + + public async Task Save() + { + return await _db.SaveChangesAsync() > 0; + } + + public async Task UpdateUser(User user) + { + _db.Users.Update(user); + return await Save(); + } +} \ No newline at end of file -- 2.45.2 From f94d3e79df092c10914bae40e4ecdc159e507959 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 7 Sep 2024 12:13:43 +0300 Subject: [PATCH 2/2] Polis repo --- Repositories/IPolisRepository.cs | 14 ++++++++++++++ Repositories/PolisRepository.cs | 0 2 files changed, 14 insertions(+) create mode 100644 Repositories/IPolisRepository.cs create mode 100644 Repositories/PolisRepository.cs diff --git a/Repositories/IPolisRepository.cs b/Repositories/IPolisRepository.cs new file mode 100644 index 0000000..340ae6f --- /dev/null +++ b/Repositories/IPolisRepository.cs @@ -0,0 +1,14 @@ +using Renis.Database.Models; + +namespace Renis.Repositories; + +public interface IPolisRepository +{ + public Task AddPolis(Polis polis); + public Task UpdatePolis(Polis polis); + public Task DeletePolis(Polis polis); + public Task GetPolisById(long id); + public Task GetPolisByNumber(string number); + public IQueryable GetPolises(); + public Task Save(); +} diff --git a/Repositories/PolisRepository.cs b/Repositories/PolisRepository.cs new file mode 100644 index 0000000..e69de29 -- 2.45.2