예제 #1
0
 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();
     }
 }
예제 #2
0
 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();
     }
 }
예제 #3
0
 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();
     }
 }
예제 #4
0
 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();
     }
 }
예제 #5
0
 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!");
         }
     }
 }
예제 #6
0
 protected Boolean Equals(CarEntity other)
 {
     return(ID == other.ID);
 }