Example #1
0
        public GenreFull AddGenre(GenreAdd newGenre)
        {
            var genre = AutoMapper.Mapper.Map<Genre>(newGenre);

            //add Movies if automapper won't map
            foreach(var item in newGenre.MovieIds)
            {
                var m = dc.Movies.Find(item);
                genre.Movies.Add(m);
            }

            dc.Genres.Add(genre);
            dc.SaveChanges();

            return GetGenreFull(genre.Id);
        }
 public ActionResult Create(GenreAdd newGenre)
 {
     if (ModelState.IsValid)
     {
         var addedItem = Repo_Genre.AddGenre(newGenre);
         if (addedItem == null)
         {
             return View("Error");
         }
         else
         {
             return RedirectToAction("Details", new { Id = addedItem.Id });
         }
     }
     else
     {
         return RedirectToAction("Create");
     }
 }