コード例 #1
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                _db.Movies.Add(movie);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View();
        }
コード例 #2
0
        public ActionResult Edit(Movie model)
        {
            if (ModelState.IsValid)
            {
                //Don't use this it has some inherit problems
                //_db.Entry(movie).State = System.Data.Entity.EntityState.Modified;

                Movie dbMovie = _db.Movies.Find(model.Id);
                dbMovie.Title = model.Title;
                dbMovie.Director = model.Director;
                _db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View();
        }