Esempio n. 1
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);
        }
Esempio n. 2
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)
            });
        }