예제 #1
0
        /// <summary>
        /// Deleting car types but making sure to first erase all cars with this type
        /// </summary>
        /// <param name="modelId"></param>
        /// <returns></returns>
        public bool DeleteCarType(int modelId)
        {
            CarsForRent        rents             = new CarsForRent();
            List <CarsForRent> listOfCarsbyModel = new List <CarsForRent>();

            listOfCarsbyModel = rents.GetCarsByCarType(modelId);
            if (listOfCarsbyModel != null)
            {
                foreach (var deletingCar in listOfCarsbyModel)
                {
                    deletingCar.DeleteCar(deletingCar.LicenseNumber);
                }
            }
            bool isDeleted = false;

            try
            {
                Car_Type carType = carDb.Car_Types.FirstOrDefault(spicifCar => spicifCar.Model_Id == modelId);

                carDb.Car_Types.Remove(carType);
                carDb.SaveChanges();
                isDeleted = true;
            }
            catch (Exception)
            {
                isDeleted = false;
                throw;
            }
            return(isDeleted);
        }
예제 #2
0
        /// <summary>
        /// Gets all cartype info that is associated with the car by license
        /// </summary>
        /// <param name="license"></param>
        /// <returns></returns>
        public CarsForRent GetCarInfo(int license)
        {
            Cars_for_Rent for_Rent = rentalCardb.Cars_for_Rents.FirstOrDefault(avalibleCar => avalibleCar.License == license);
            CarsForRent   car      = new CarsForRent();

            car.CarUsage      = for_Rent.Distance_Usage;
            car.IsUsable      = for_Rent.IsUsable;
            car.IsAvalible    = for_Rent.IsAvalible;
            car.LicenseNumber = for_Rent.License;
            car.Lot           = for_Rent.Branch_Id;
            car.CarType       = for_Rent.Car_Type_Id;
            car.Image         = for_Rent.CarImage;
            return(car);
        }