public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate) { // Validate if (movieToCreate.Title.Trim().Length == 0) { ModelState.AddModelError("Title", "Title is required."); } if (movieToCreate.Title.IndexOf("r") > 0) { ModelState.AddModelError("Title", "Title cannot contain the letter r."); } if (movieToCreate.Director.Trim().Length == 0) { ModelState.AddModelError("Director", "Director is required."); } if (!ModelState.IsValid) { return(View()); } // Add to database _entities.AddToMovieSet(movieToCreate); _entities.SaveChanges(); // Redirect return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate) { if (!ModelState.IsValid) { return(View()); } _db.AddToMovieSet(movieToCreate); _db.SaveChanges(); return(RedirectToAction("Index")); }
public string Create(Movie movieToCreate) { try { _entities.AddToMovieSet(movieToCreate); _entities.SaveChanges(); return("Inserted new movie " + movieToCreate.Title); } catch { return("Could not insert movie " + movieToCreate.Title); } }
public ActionResult Create(Movie item) { try { if (!ModelState.IsValid) { return(View()); } _db.AddToMovieSet(item); _db.SaveChanges(); return(RedirectToRoute(this.GetResourceRouteName(routeName, ActionType.Retrieve), new RouteValueDictionary { { "id", item.Id } })); } catch (Exception exception) { throw new HttpException((int)HttpStatusCode.InternalServerError, "An error has occured; see details:", exception); } }
public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate) { // Validate if (!ModelState.IsValid) { return(View()); } // Add to database try { _db.AddToMovieSet(movieToCreate); _db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }