diff --git a/Database/Models/Car.cs b/Database/Models/Car.cs index ba77df7..66a5cca 100644 --- a/Database/Models/Car.cs +++ b/Database/Models/Car.cs @@ -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; } } \ No newline at end of file diff --git a/Repositories/Cars/CarRepository.cs b/Repositories/Cars/CarRepository.cs new file mode 100644 index 0000000..bb03135 --- /dev/null +++ b/Repositories/Cars/CarRepository.cs @@ -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 AddCar(Car car) + { + _db.Cars.Add(car); + return await Save(); + } + + public async Task DeleteCar(Car car) + { + _db.Cars.Remove(car); + return await Save(); + } + + public async Task GetCarById(long id) + { + return await _db.Cars.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task GetCarByNumber(string number) + { + return await _db.Cars.FirstOrDefaultAsync(x => x.Number == number); + } + + public IQueryable GetCars() + { + return _db.Cars.AsQueryable(); + } + + public async Task Save() + { + return await _db.SaveChangesAsync() > 0; + } + + public async Task UpdateCar(Car car) + { + _db.Cars.Update(car); + return await Save(); + } +} diff --git a/Repositories/Cars/ICarRepository.cs b/Repositories/Cars/ICarRepository.cs new file mode 100644 index 0000000..06e55b3 --- /dev/null +++ b/Repositories/Cars/ICarRepository.cs @@ -0,0 +1,14 @@ +using Renis.Database.Models; + +namespace Renis.Repositories; + +public interface ICarRepository +{ + public Task AddCar(Car car); + public Task UpdateCar(Car car); + public Task DeleteCar(Car car); + public Task GetCarById(long id); + public Task GetCarByNumber(string number); + public IQueryable GetCars(); + public Task Save(); +} diff --git a/Repositories/PolisRepository.cs b/Repositories/PolisRepository.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Repositories/IPolisRepository.cs b/Repositories/Polises/IPolisRepository.cs similarity index 100% rename from Repositories/IPolisRepository.cs rename to Repositories/Polises/IPolisRepository.cs diff --git a/Repositories/Polises/PolisRepository.cs b/Repositories/Polises/PolisRepository.cs new file mode 100644 index 0000000..00e8a4f --- /dev/null +++ b/Repositories/Polises/PolisRepository.cs @@ -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 AddPolis(Polis polis) + { + _db.Polises.Add(polis); + return await Save(); + } + + public async Task DeletePolis(Polis polis) + { + _db.Polises.Remove(polis); + return await Save(); + } + + public async Task GetPolisById(long id) + { + return await _db.Polises.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task GetPolisByNumber(string number) + { + return await _db.Polises.FirstOrDefaultAsync(x => x.Number == number); + } + + public IQueryable GetPolises() + { + return _db.Polises.AsQueryable(); + } + + public async Task Save() + { + return await _db.SaveChangesAsync() > 0; + } + + public async Task UpdatePolis(Polis polis) + { + _db.Polises.Update(polis); + return await Save(); + } +} 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; + } +} diff --git a/Repositories/IUserRepository.cs b/Repositories/Users/IUserRepository.cs similarity index 100% rename from Repositories/IUserRepository.cs rename to Repositories/Users/IUserRepository.cs diff --git a/Repositories/UserRepository.cs b/Repositories/Users/UserRepository.cs similarity index 100% rename from Repositories/UserRepository.cs rename to Repositories/Users/UserRepository.cs