Exemplo n.º 1
0
        public IActionResult Create(int categoryId)
        {
            MovieCreateViewModel model = new MovieCreateViewModel();

            model.LoadModelData(_unitOfWork, categoryId);
            return(View(model));
        }
Exemplo n.º 2
0
 public IActionResult Create(MovieCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.Movie.Category_Id = model.SelectedId;
             _unitOfWork.MovieRepository.AddMovie(model.Movie);
             _unitOfWork.Save();
             return(RedirectToAction("Details", "Home", new { categoryId = model.Movie.Category_Id }));
         }
         catch (ValidationException ex)
         {
             foreach (var member in ex.ValidationResult.MemberNames)
             {
                 ModelState.AddModelError(member, ex.ValidationResult.ErrorMessage);
             }
         }
     }
     model.LoadModelData(_unitOfWork, model.Movie.Category_Id);
     return(View(model));
 }