Ejemplo n.º 1
0
        public ActionResult Edit(int id, BusVehicleModel model)
        {
            try
            {
                // TODO: Add update logic here
                // Get all states again
                var times = GetAllTimesPerHour();

                // Set these states on the model. We need to do this because
                // only the selected value from the DropDownList is posted back, not the whole
                // list of states.
                model.DepartureTimes = GetSelectListItems(times);

                BusVehicle busVehicle = context.BusVehicles.Where(some => some.Id == model.Id).Single <BusVehicle>();
                busVehicle.Name          = model.Name;
                busVehicle.AC            = model.AC;
                busVehicle.Fare          = model.Fare;
                busVehicle.DepartureTime = model.DepartureTime;
                busVehicle.RouteID       = model.RouteID;

                context.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
 private void PrepareBusVehicle(BusVehicleModel model)
 {
     model.Routes = context.Routes.AsQueryable <Route>().Select(x =>
                                                                new SelectListItem()
     {
         Text  = x.Origin + " <--> " + x.Destination,
         Value = x.Id.ToString()
     });
 }
Ejemplo n.º 3
0
        // GET: BusVehicle/Create
        public ActionResult Create()
        {
            BusVehicleModel model = new BusVehicleModel();

            // Preparing route for dropdown list
            PrepareBusVehicle(model);

            // Let's get all states that we need for a DropDownList
            var times = GetAllTimesPerHour();

            // Create a list of SelectListItems so these can be rendered on the page
            model.DepartureTimes = GetSelectListItems(times);

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Create()
        {
            BusVehicleModel model = new BusVehicleModel();

            // Preparing route for dropdown list
            PrepareBusVehicle(model);

            // Let's get all states that we need for a DropDownList
            var classes = AppConstants.BusClasses;

            // Create a list of SelectListItems so these can be rendered on the page
            model.Classes = GetSelectListItems(classes);

            return(View(model));
        }
Ejemplo n.º 5
0
        public ActionResult Delete(int id, BusVehicleModel model)
        {
            try
            {
                // TODO: Add delete logic here
                BusVehicle busVehicle = context.BusVehicles.Where(some => some.Id == model.Id).Single <BusVehicle>();

                context.BusVehicles.DeleteOnSubmit(busVehicle);
                context.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 6
0
        // GET: BusVehicle/Delete/5
        public ActionResult Delete(int id)
        {
            BusVehicleModel model = context.BusVehicles.Where(some => some.Id == id).Select(
                some => new BusVehicleModel()
            {
                Id            = some.Id,
                Name          = some.Name,
                RouteID       = some.RouteID,
                AC            = some.AC,
                Fare          = some.Fare,
                DepartureTime = some.DepartureTime
            }).SingleOrDefault();

            PrepareBusVehicle(model);

            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult Create(BusVehicleModel model)
        {
            try
            {
                // TODO: Add insert logic here

                // Get all states again
                var times   = AppConstants.HOURS;
                var classes = AppConstants.BusClasses;

                // Set these states on the model. We need to do this because
                // only the selected value from the DropDownList is posted back, not the whole
                // list of states.
                //model.DepartureTimes = GetSelectListItems(times.Keys);
                //ViewBag.Hours = times;
                model.Classes = GetSelectListItems(classes);

                BusVehicle busVehicle = new BusVehicle()
                {
                    Name          = model.Name,
                    Class         = model.Class,
                    Capacity      = model.Capacity,
                    Fare          = model.Fare,
                    DepartureTime = DateTime.Parse(model.DepartureTime),
                    RouteID       = model.RouteID
                };

                context.BusVehicles.InsertOnSubmit(busVehicle);
                context.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                model = new BusVehicleModel();
                PrepareBusVehicle(model);

                // Create a list of SelectListItems so these can be rendered on the page
                //model.DepartureTimes = GetSelectListItems(AppConstants.HOURS);
                //ViewBag.Hours = AppConstants.HOURS;
                model.Classes = GetSelectListItems(AppConstants.BusClasses);

                return(View(model));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Delete(int id)
        {
            BusVehicleModel model = context.BusVehicles.Where(some => some.Id == id).Select(
                some => new BusVehicleModel()
            {
                Id            = some.Id,
                Name          = some.Name,
                RouteID       = some.RouteID,
                Class         = some.Class,
                Capacity      = (int)some.Capacity,
                Fare          = (int)some.Fare,
                DepartureTime = some.DepartureTime.ToString()
            }).SingleOrDefault();

            PrepareBusVehicle(model);

            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult Create(BusVehicleModel model)
        {
            try
            {
                // TODO: Add insert logic here

                // Get all states again
                var times = GetAllTimesPerHour();

                // Set these states on the model. We need to do this because
                // only the selected value from the DropDownList is posted back, not the whole
                // list of states.
                model.DepartureTimes = GetSelectListItems(times);

                BusVehicle busVehicle = new BusVehicle()
                {
                    Name          = model.Name,
                    AC            = model.AC,
                    Fare          = model.Fare,
                    DepartureTime = model.DepartureTime,
                    RouteID       = model.RouteID
                };

                context.BusVehicles.InsertOnSubmit(busVehicle);
                context.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                model = new BusVehicleModel();
                PrepareBusVehicle(model);

                // Create a list of SelectListItems so these can be rendered on the page
                model.DepartureTimes = GetSelectListItems(GetAllTimesPerHour());

                return(View(model));
            }
        }
Ejemplo n.º 10
0
        // GET: BusVehicle/Edit/5
        public ActionResult Edit(int id)
        {
            BusVehicleModel model = context.BusVehicles.Where(some => some.Id == id).Select(
                some => new BusVehicleModel()
            {
                Name          = some.Name,
                AC            = some.AC,
                Fare          = some.Fare,
                DepartureTime = some.DepartureTime,
                RouteID       = some.RouteID
            }).SingleOrDefault();

            // Preparing route for dropdown list
            PrepareBusVehicle(model);

            // Let's get all states that we need for a DropDownList
            var times = GetAllTimesPerHour();

            // Create a list of SelectListItems so these can be rendered on the page
            model.DepartureTimes = GetSelectListItems(times);

            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int id)
        {
            BusVehicleModel model = context.BusVehicles.Where(some => some.Id == id).Select(
                some => new BusVehicleModel()
            {
                Name          = some.Name,
                Class         = some.Class,
                Capacity      = (int)some.Capacity,
                Fare          = (int)some.Fare,
                DepartureTime = some.DepartureTime.ToString(),
                RouteID       = some.RouteID
            }).SingleOrDefault();

            // Preparing route for dropdown list
            PrepareBusVehicle(model);

            // Let's get all states that we need for a DropDownList
            var classes = AppConstants.BusClasses;

            // Create a list of SelectListItems so these can be rendered on the page
            model.Classes = GetSelectListItems(classes);

            return(View(model));
        }