public void RentCar(CarRent carRent) { using (var ctx = new AppDbContext()) { CarEntity car = ctx.Cars.First(x => x.ID == carRent.CarID); car.ClientID = carRent.ClientID; ctx.Rents.Add(carRent); ctx.SaveChanges(); } }
public void ReturnCar(Int32 leaseID) { using (var ctx = new AppDbContext()) { CarRent exisitngRent = ctx.Rents.First(x => x.ID == leaseID); ctx.Rents.Remove(exisitngRent); CarEntity car = ctx.Cars.First(x => x.ID == exisitngRent.CarID); car.ClientID = null; ctx.SaveChanges(); } }
public void AddCar(CarEntity car) { using (var ctx = new AppDbContext()) { if (ctx.Cars.Any(x => x.RegNumber == car.RegNumber)) { throw new Exception("Car with such registration number exists!"); } ctx.Cars.Add(car); ctx.SaveChanges(); } }
public void EditCar(CarEntity car) { using (var ctx = new AppDbContext()) { if (ctx.Cars.Any(x => x.RegNumber == car.RegNumber)) { throw new Exception("Car with such registration number exists!"); } CarEntity existingCar = ctx.Cars.First(x => x.ID == car.ID); existingCar.RegNumber = car.RegNumber; existingCar.RentPricePerDay = car.RentPricePerDay; ctx.SaveChanges(); } }
public void RemoveCar(CarEntity car) { using (var ctx = new AppDbContext()) { if (car.ClientID != null) { CarEntity existingCar = ctx.Cars.First(x => x.ID == car.ID); ctx.Cars.Remove(existingCar); ctx.SaveChanges(); } else { throw new Exception("Car is rented!"); } } }
protected Boolean Equals(CarEntity other) { return(ID == other.ID); }