Пример #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 car type details by id
        /// </summary>
        /// <param name="carId"></param>
        /// <returns></returns>
        public Car GetCarDetails(int carId)
        {
            Car      spicificCar = new Car();
            Car_Type carType     = carDb.Car_Types.FirstOrDefault(car => car.Model_Id == carId);

            spicificCar.CostPerDay       = (int)carType.Cost_pre_Day;
            spicificCar.DelayCostPerDay  = (int)carType.Delay_Cost_per_Day;
            spicificCar.IsGear           = carType.isGear;
            spicificCar.Manufacturer     = carType.Company_Name;
            spicificCar.Model            = carType.Model;
            spicificCar.ModelId          = carType.Model_Id;
            spicificCar.YearManufactured = carType.Manufactured_Year;
            return(spicificCar);
        }