public static UpdateCarViewModel ConvertToUpdateViewModel(this Car carDomain)
        {
            UpdateCarViewModel updateVm = new UpdateCarViewModel()
            {
                Id = carDomain.Id
                , DailyRentalFee = carDomain.DailyRentalFee
                , Make           = carDomain.Make
                , NumberOfDoors  = carDomain.NumberOfDoors
            };

            if (carDomain.CountriesAllowedIn != null && carDomain.CountriesAllowedIn.Count() > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < carDomain.CountriesAllowedIn.Count(); i++)
                {
                    sb.Append(carDomain.CountriesAllowedIn.ElementAt(i));
                    if (i < carDomain.CountriesAllowedIn.Count() - 1)
                    {
                        sb.Append(";");
                    }
                }
                updateVm.DelimitedListOfCountries = sb.ToString();
            }

            return(updateVm);
        }
        public ActionResult Edit(UpdateCarViewModel updateCarViewModel)
        {
            if (ModelState.IsValid)
            {
                Car modifiedCar = updateCarViewModel.ConvertToDomain();
                CarRentalContext.Cars.Save(modifiedCar);

                //or use the Update method:
                //CarRentalContext.Cars.Update(Query.EQ("_id", ObjectId.Parse(updateCarViewModel.Id)), Update.Replace(modifiedCar), UpdateFlags.Upsert);

                //some example code

                /*
                 * CarRentalContext.Cars.Update(Query.EQ("_id", ObjectId.Parse(updateCarViewModel.Id)), Update<Car>.Set(c => c.DailyRentalFee, 12));
                 * CarRentalContext.Cars.Update(Query.EQ("Make", "Ford"), Update<Car>.Set(c => c.DailyRentalFee, 2), UpdateFlags.Multi);
                 *
                 * FindAndModifyArgs args = new FindAndModifyArgs()
                 * {
                 *      Query = Query.EQ("Make", "Ford")
                 *      ,Update = Update<Car>.Set(c => c.DailyRentalFee, 2),
                 *      Upsert = false
                 *      ,SortBy = SortBy<Car>.Ascending(c => c.Id)
                 *      ,VersionReturned = FindAndModifyDocumentVersion.Modified
                 * };
                 * FindAndModifyResult res = CarRentalContext.Cars.FindAndModify(args);
                 */

                return(RedirectToAction("Index"));
            }
            return(View(updateCarViewModel));
        }
        public static Car ConvertToDomain(this UpdateCarViewModel updateCarViewModel)
        {
            Car car = new Car()
            {
                Id = updateCarViewModel.Id
                , DailyRentalFee = updateCarViewModel.DailyRentalFee
                , Make           = updateCarViewModel.Make
                , NumberOfDoors  = updateCarViewModel.NumberOfDoors
            };

            string[] countries = updateCarViewModel.DelimitedListOfCountries.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            car.CountriesAllowedIn = countries.ToList();
            return(car);
        }
 public UpdateCarPage()
 {
     InitializeComponent();
     BindingContext = new UpdateCarViewModel();
 }