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/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/PolisRepository.cs b/Repositories/Polises/PolisRepository.cs similarity index 100% rename from Repositories/PolisRepository.cs rename to Repositories/Polises/PolisRepository.cs 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