Beispiel #1
0
 public bool UpdateCar(CarModel updatedCar)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Car car = carEntities.Cars.Where(c => c.LicensePlate == updatedCar.LicensePlate).FirstOrDefault();
             if (car == null)
             {
                 throw new ArgumentException($"Car with license plate {updatedCar.LicensePlate} was not found");
             }
             car.CarTypeId     = CarTypesManager.getCarTypeId(updatedCar.CarType.Producer, updatedCar.CarType.Model, updatedCar.CarType.ManufacturingYear, updatedCar.CarType.Gear);
             car.Kilometers    = updatedCar.CurrentKM;
             car.Photo         = updatedCar.CarPhoto;
             car.IsConditionOK = updatedCar.IsFunctional;
             car.BranchId      = updatedCar.Branch.BranchId;
             carEntities.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #2
0
 public CarModel AddCar(CarModel addCar)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Car car = new Car();
             car.CarTypeId     = CarTypesManager.getCarTypeId(addCar.CarType.Producer, addCar.CarType.Model, addCar.CarType.ManufacturingYear, addCar.CarType.Gear);
             car.Kilometers    = addCar.CurrentKM;
             car.Photo         = addCar.CarPhoto;
             car.IsConditionOK = addCar.IsFunctional;
             car.BranchId      = addCar.Branch.BranchId;
             car.LicensePlate  = addCar.LicensePlate;
             carEntities.Cars.Add(car);
             carEntities.SaveChanges();
         }
         return(addCar);
     }
     catch (Exception e)
     {
         return(null);
     }
 }