Esempio n. 1
0
 //add car
 public void Insert(CarViewModel carVM)
 {
     DBCarRent.Car car = MapViewModelToModel(carVM);
     using (CarsRepository carsRepository = new CarsRepository())
     {
         carsRepository.Insert(car);
     }
 }
Esempio n. 2
0
 //update car
 public void Update(CarViewModel carVM)
 {
     DBCarRent.Car car = MapViewModelToModel(carVM);
     using (CarsRepository carsRepository = new CarsRepository())
     {
         var carNumber = car.CarNumber;
         carsRepository.Update(carNumber, car);
     }
 }
Esempio n. 3
0
 //get car by id
 public CarViewModel GetById(int id)
 {
     DBCarRent.Car car = null;
     using (CarsRepository carsRepository = new CarsRepository())
     {
         car = carsRepository.GetCarById(id);
     }
     return(MapModelToViewModel(car));
 }
Esempio n. 4
0
        //ViewModel To Model
        private DBCarRent.Car  MapViewModelToModel(CarViewModel carVM)
        {
            DBCarRent.Car car = new DBCarRent.Car();

            car.Photo            = carVM.Photo;
            car.Model            = carVM.Model;
            car.PricePerDay      = string.IsNullOrEmpty(carVM.PricePerDay) ? 0 : Int32.Parse(carVM.PricePerDay);
            car.CostOfDayOverdue = string.IsNullOrEmpty(carVM.CostOfDayOverdue) ? 0 : Int32.Parse(carVM.CostOfDayOverdue);
            car.Availability     = carVM.Availability;
            car.Year             = string.IsNullOrEmpty(carVM.Year) ? 0 :  Int32.Parse(carVM.Year);
            car.GearBox          = carVM.GearBox;
            car.Mileage          = string.IsNullOrEmpty(carVM.Year) ? 0 : Int32.Parse(carVM.Mileage);
            car.CarNumber        = carVM.CarNumber;
            car.Branch           = carVM.Branch;

            return(car);
        }
Esempio n. 5
0
        //Model To ViewModel
        private CarViewModel MapModelToViewModel(DBCarRent.Car car)
        {
            CarViewModel carVM = new CarViewModel();

            carVM.Photo            = car.Photo;
            carVM.Model            = car.Model;
            carVM.PricePerDay      = car.PricePerDay.ToString();
            carVM.CostOfDayOverdue = car.CostOfDayOverdue.ToString();
            carVM.Availability     = car.Availability;
            carVM.Year             = car.Year.ToString();
            carVM.GearBox          = car.GearBox;
            carVM.Mileage          = car.Mileage.ToString();
            carVM.CarNumber        = car.CarNumber;
            carVM.Branch           = car.Branch;

            return(carVM);
        }