Exemple #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);
     }
 }
Exemple #2
0
        public List <CarModel> getAllCars(bool includeNonFunctional = false)//workers and manager can view non-functional cars
        {
            List <CarModel> cars = new List <CarModel>();

            using (CarRentalEntities carEntities = new CarRentalEntities())
            {
                foreach (Car car in carEntities.Cars.Where(c => includeNonFunctional || c.IsConditionOK))
                {
                    cars.Add(new CarModel()
                    {
                        CarType      = CarTypesManager.getCarTypeById(car.CarTypeId),
                        CurrentKM    = car.Kilometers,
                        CarPhoto     = car.Photo,
                        IsFunctional = car.IsConditionOK,
                        LicensePlate = car.LicensePlate,
                        Branch       = BranchesManager.getBranchById(car.BranchId)
                    });
                }
            }
            return(cars);
        }
Exemple #3
0
        public CarModel getCarByLicensePlate(string licensePlate)
        {
            Car car;

            using (CarRentalEntities carEntities = new CarRentalEntities())
            {
                car = carEntities.Cars.Where(c => c.LicensePlate == licensePlate).FirstOrDefault();
            }
            if (car == null)
            {
                return(null);
            }
            return(new CarModel()
            {
                CarType = CarTypesManager.getCarTypeById(car.CarTypeId),
                CurrentKM = car.Kilometers,
                CarPhoto = car.Photo,
                IsFunctional = car.IsConditionOK,
                LicensePlate = car.LicensePlate,
                Branch = BranchesManager.getBranchById(car.BranchId)
            });
        }
Exemple #4
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);
     }
 }