Ejemplo n.º 1
0
        public void EditGenre(GenreEdit newItem)
        {
            Genre genre = dc.Genres.Include("Movies").FirstOrDefault(m => m.Id == newItem.Id);

            genre.Name = newItem.Name;

            try
            {

                if (newItem.movieRemoveId.Count != 0)
                {
                    foreach (var item in newItem.movieRemoveId)
                    {
                        genre.Movies.Remove(dc.Movies.Find(item));
                        //Addition to remove director from movie
                        dc.Movies.Find(item).Genres.Remove(dc.Genres.Find(newItem.Id));
                        dc.SaveChanges();
                    }

                }

            }
            catch (System.NullReferenceException)
            {

            }

            try
            {
                if (newItem.MovieId.Count != 0)
                {
                    foreach (var item in newItem.MovieId)
                    {
                        genre.Movies.Add(dc.Movies.Find(item));

                        dc.Movies.Find(item).Genres.Add(dc.Genres.Find(newItem.Id));
                        dc.SaveChanges();
                    }
                }

            }
            catch (System.NullReferenceException)
            {

            }

            dc.Entry(genre).State = EntityState.Modified;
            dc.SaveChanges();
        }
        public ActionResult Edit(GenreEdit newItem)
        {
            gen.EditGenre(newItem);

            return View("Index", gen.GetGenresForList());
        }