Beispiel #1
0
        public static void SeedMovies()
        {
            // Read the contents of the file
            string s = File.ReadAllText("..\\..\\..\\MovieRentals\\App_Data\\movies.json");

            // Parse the contents using JSON.NET
            JArray data = (JArray)JsonConvert.DeserializeObject(s);

            MovieRepository repository = new MovieRepository();
            int indexNumber = 1;

            // Process the data
            foreach (JToken token in data)
            {
                Movie m = new Movie();
                m.Id = indexNumber;
                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);
                indexNumber++;
            }
        }
        public void Add(Movie movie)
        {
            db.Open();
            try
            {
                SqlCommand command = new SqlCommand(
                    "insert into movies (Id, Title, Overview, ReleaseDate, Inventory) values (@id, @title, @overview, @release_date, @inventory)",
                    this.db);
                command.Parameters.AddWithValue("@id", movie.Id);
                command.Parameters.AddWithValue("@title", movie.Title);
                command.Parameters.AddWithValue("@overview", movie.Overview);
                command.Parameters.AddWithValue("@release_date", movie.ReleaseDate);
                command.Parameters.AddWithValue("@inventory", movie.Inventory);

                command.ExecuteNonQuery();
            }
            finally
            {
                db.Close();
            }
        }
 public Movie Update(Movie movie)
 {
     throw new NotImplementedException();
 }
 public void Save(Movie movie)
 {
     throw new NotImplementedException();
 }