public ActionResult Create(FormCollection collection) { try { Movie movie = new Movie(); movie.Inventory = int.Parse(collection.GetValue("Inventory").AttemptedValue.ToString()); movie.Overview = collection.GetValue("Overview").AttemptedValue.ToString(); movie.ReleaseDate = collection.GetValue("ReleaseDate").AttemptedValue.ToString(); movie.Title = collection.GetValue("Title").AttemptedValue.ToString(); MovieRepository r = new MovieRepository(); r.Add(movie); return RedirectToAction("Index"); } catch { return View(); } }
public static void SeedMovies() { // Read the contents of the file string s = File.ReadAllText("..\\..\\..\\AdaMovieStoreSample\\App_Data\\movies.json"); // Parse the contents using JSON.NET JArray data = (JArray)JsonConvert.DeserializeObject(s); MovieRepository repository = new MovieRepository(); // Process the data foreach (JToken token in data) { Movie m = new Movie(); m.Title = token["title"].Value<string>(); m.Overview = token["overview"].Value<string>(); m.ReleaseDate = token["release_date"].Value<string>(); m.Inventory = token["inventory"].Value<int>(); repository.Add(m); } }