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(); } }