Merge pull request 'repos' (#1) from repos into main
Reviewed-on: https://git.georesinwaybill.ru/espada/renis-backend/pulls/1
This commit is contained in:
commit
e1f9b65d84
14
Repositories/IPolisRepository.cs
Normal file
14
Repositories/IPolisRepository.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Renis.Database.Models;
|
||||
|
||||
namespace Renis.Repositories;
|
||||
|
||||
public interface IPolisRepository
|
||||
{
|
||||
public Task<bool> AddPolis(Polis polis);
|
||||
public Task<bool> UpdatePolis(Polis polis);
|
||||
public Task<bool> DeletePolis(Polis polis);
|
||||
public Task<Polis?> GetPolisById(long id);
|
||||
public Task<Polis?> GetPolisByNumber(string number);
|
||||
public IQueryable<Polis> GetPolises();
|
||||
public Task<bool> Save();
|
||||
}
|
14
Repositories/IUserRepository.cs
Normal file
14
Repositories/IUserRepository.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Renis.Database.Models;
|
||||
|
||||
namespace Renis.Repositories;
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
public Task<bool> AddUser(User user);
|
||||
public Task<bool> UpdateUser(User user);
|
||||
public Task<bool> DeleteUser(User user);
|
||||
public Task<User?> GetUserById(long id);
|
||||
public Task<User?> GetUserByPhone(string phone);
|
||||
public IQueryable<User> GetUsers();
|
||||
public Task<bool> Save();
|
||||
}
|
0
Repositories/PolisRepository.cs
Normal file
0
Repositories/PolisRepository.cs
Normal file
48
Repositories/UserRepository.cs
Normal file
48
Repositories/UserRepository.cs
Normal file
@ -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<bool> AddUser(User user)
|
||||
{
|
||||
_db.Users.Add(user);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteUser(User user)
|
||||
{
|
||||
_db.Users.Remove(user);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<User?> GetUserById(long id)
|
||||
{
|
||||
return await _db.Users.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task<User?> GetUserByPhone(string phone)
|
||||
{
|
||||
return await _db.Users.FirstOrDefaultAsync(x => x.Phone == phone);
|
||||
}
|
||||
|
||||
public IQueryable<User> GetUsers()
|
||||
{
|
||||
return _db.Users.AsQueryable();
|
||||
}
|
||||
|
||||
public async Task<bool> Save()
|
||||
{
|
||||
return await _db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUser(User user)
|
||||
{
|
||||
_db.Users.Update(user);
|
||||
return await Save();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user