Car, Polis & User repos + moved to dedicated folders
This commit is contained in:
parent
83c9b7fe6e
commit
d75f179ad4
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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user