public ActionResult GetCars(int id)
        {
            RentalsViewModel             viewModel = new RentalsViewModel();
            IEnumerable <SelectListItem> cars      = viewModel.GetCars(id);

            return(Json(cars, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(Reservation reservation, int Id)
        {
            Reservation      reservationToEdit = context.Find(Id);
            RentalsViewModel viewModel         = RentalsViewModel.FromReservation(reservation);

            if (reservationToEdit == null)
            {
                return(HttpNotFound());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(viewModel));
                }

                reservationToEdit.CarID         = reservation.CarID;
                reservationToEdit.CostumerID    = reservation.CostumerID;
                reservationToEdit.StartDate     = reservation.StartDate;
                reservationToEdit.ReservStatsID = reservation.ReservStatsID;
                reservationToEdit.EndDate       = reservation.EndDate;
                reservationToEdit.LocationID    = reservation.LocationID;

                context.Commit();

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Create()
        {
            Reservation      reservation = new Reservation();
            RentalsViewModel viewModel   = RentalsViewModel.FromReservation(reservation);

            viewModel.Locations = viewModel.GetLocations();
            viewModel.Cars      = viewModel.GetCars();
            return(View(viewModel));
        }
        protected override void OnWireViewModelEvents(ViewModelBase viewModel)
        {
            RentalsViewModel vm = viewModel as RentalsViewModel;

            if (vm != null)
            {
                vm.RentalReturned += OnRentalReturned;
                vm.ErrorOccured   += OnErrorOccured;
            }
        }
        public void TestViewLoaded()
        {
            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            RentalsViewModel viewModel = new RentalsViewModel(mockServiceFactory.Object);

            //Assert.IsTrue(viewModel.Cars == null);

            object loaded = viewModel.ViewLoaded; // fires off the OnViewLoaded protected method

            //Assert.IsTrue(viewModel.Cars != null && viewModel.Cars.Length == data.Length && viewModel.Cars[0] == data[0]);
        }
        public ActionResult Edit(int Id)
        {
            Reservation      reservation = context.Find(Id);
            RentalsViewModel viewModel   = RentalsViewModel.FromReservation(reservation);

            viewModel.Locations = viewModel.GetLocations();
            viewModel.Cars      = viewModel.GetCars();

            if (reservation == null)
            {
                return(HttpNotFound());
            }
            else
            {
                return(View(viewModel));
            }
        }