Merge branch 'main' of https://git.georesinwaybill.ru/espada/renis-backend
This commit is contained in:
commit
a670b00308
@ -9,11 +9,12 @@ public class Car
|
||||
[Required]
|
||||
public string Number { get; set; } = null!;
|
||||
[Required]
|
||||
Polis Polis { get; set; } = null!;
|
||||
public Polis Polis { get; set; } = null!;
|
||||
[Required]
|
||||
long PolisId { get; set; }
|
||||
public long PolisId { get; set; }
|
||||
[Required]
|
||||
User Resp { get; set; } = null!;
|
||||
public User Resp { get; set; } = null!;
|
||||
[Required]
|
||||
long RespId { get; set; }
|
||||
public long RespId { get; set; }
|
||||
public bool Verified { get; set; }
|
||||
}
|
48
Repositories/Cars/CarRepository.cs
Normal file
48
Repositories/Cars/CarRepository.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Renis.Database;
|
||||
using Renis.Database.Models;
|
||||
|
||||
namespace Renis.Repositories;
|
||||
|
||||
public class CarRepository(ApplicationContext db) : ICarRepository
|
||||
{
|
||||
private readonly ApplicationContext _db = db;
|
||||
|
||||
public async Task<bool> AddCar(Car car)
|
||||
{
|
||||
_db.Cars.Add(car);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteCar(Car car)
|
||||
{
|
||||
_db.Cars.Remove(car);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<Car?> GetCarById(long id)
|
||||
{
|
||||
return await _db.Cars.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task<Car?> GetCarByNumber(string number)
|
||||
{
|
||||
return await _db.Cars.FirstOrDefaultAsync(x => x.Number == number);
|
||||
}
|
||||
|
||||
public IQueryable<Car> GetCars()
|
||||
{
|
||||
return _db.Cars.AsQueryable();
|
||||
}
|
||||
|
||||
public async Task<bool> Save()
|
||||
{
|
||||
return await _db.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateCar(Car car)
|
||||
{
|
||||
_db.Cars.Update(car);
|
||||
return await Save();
|
||||
}
|
||||
}
|
14
Repositories/Cars/ICarRepository.cs
Normal file
14
Repositories/Cars/ICarRepository.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Renis.Database.Models;
|
||||
|
||||
namespace Renis.Repositories;
|
||||
|
||||
public interface ICarRepository
|
||||
{
|
||||
public Task<bool> AddCar(Car car);
|
||||
public Task<bool> UpdateCar(Car car);
|
||||
public Task<bool> DeleteCar(Car car);
|
||||
public Task<Car?> GetCarById(long id);
|
||||
public Task<Car?> GetCarByNumber(string number);
|
||||
public IQueryable<Car> GetCars();
|
||||
public Task<bool> Save();
|
||||
}
|
48
Repositories/Polises/PolisRepository.cs
Normal file
48
Repositories/Polises/PolisRepository.cs
Normal file
@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
14
Repositories/UserPolises/IUserPolisRepository.cs
Normal file
14
Repositories/UserPolises/IUserPolisRepository.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Renis.Database.Models;
|
||||
|
||||
namespace Renis.Repositories;
|
||||
|
||||
public interface IUserPolisRepository
|
||||
{
|
||||
public Task<bool> AddUserPolis(UserPolis userPolis);
|
||||
public Task<bool> UpdateUserPolis(UserPolis userPolis);
|
||||
public Task<bool> DeleteUserPolis(UserPolis userPolis);
|
||||
public Task<UserPolis?> GetUserPolisById(long id);
|
||||
public Task<UserPolis?> GetUserPolisByUserIdAndPolisId(long userId, long polisId);
|
||||
public IQueryable<UserPolis> GetUserPolises();
|
||||
public Task<bool> Save();
|
||||
}
|
48
Repositories/UserPolises/UserPolisRepository.cs
Normal file
48
Repositories/UserPolises/UserPolisRepository.cs
Normal file
@ -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<bool> AddUserPolis(UserPolis userPolis)
|
||||
{
|
||||
_db.UserPolises.Add(userPolis);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserPolis(UserPolis userPolis)
|
||||
{
|
||||
_db.UserPolises.Update(userPolis);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteUserPolis(UserPolis userPolis)
|
||||
{
|
||||
_db.UserPolises.Remove(userPolis);
|
||||
return await Save();
|
||||
}
|
||||
|
||||
public async Task<UserPolis?> GetUserPolisById(long id)
|
||||
{
|
||||
return await _db.UserPolises.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task<UserPolis?> GetUserPolisByUserIdAndPolisId(long userId, long polisId)
|
||||
{
|
||||
return await _db.UserPolises.FirstOrDefaultAsync(x => x.UserId == userId && x.PolisId == polisId);
|
||||
}
|
||||
|
||||
public IQueryable<UserPolis> GetUserPolises()
|
||||
{
|
||||
return _db.UserPolises.AsQueryable();
|
||||
}
|
||||
|
||||
public async Task<bool> Save()
|
||||
{
|
||||
return await _db.SaveChangesAsync() > 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user