Exemplo n.º 1
0
        public ActionResult Save(Cycle cycle)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CycleFormViewModel(cycle)
                {
                    BikeTypes = _myContext.BikeTypes.ToList()
                };
                return(View("CycleForm", viewModel));
            }
            if (cycle.Id == 0)
            {
                cycle.DateAdded = DateTime.Now;
                _myContext.Cycles.Add(cycle);
            }
            else
            {
                var cycleInDB = _myContext.Cycles.Single(c => c.Id == cycle.Id);

                cycleInDB.Name          = cycle.Name;
                cycleInDB.ReleaseDate   = cycle.ReleaseDate;
                cycleInDB.BikeTypeId    = cycle.BikeTypeId;
                cycleInDB.NumberInStock = cycle.NumberInStock;
            }

            _myContext.SaveChanges();

            return(RedirectToAction("Index", "Cycles"));
        }
Exemplo n.º 2
0
        public ActionResult New()
        {
            var cycleType = _myContext.BikeTypes.ToList();
            var viewModel = new CycleFormViewModel
            {
                BikeTypes = cycleType
            };

            return(View("CycleForm", viewModel));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            var cycle = _myContext.Cycles.SingleOrDefault(c => c.Id == id);

            if (cycle == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new CycleFormViewModel(cycle)
            {
                BikeTypes = _myContext.BikeTypes.ToList()
            };

            return(View("CycleForm", viewModel));
        }