Exemplo n.º 1
0
        public async Task <IActionResult> CreateOrEdit(int?id = null)
        {
            if (id == null)
            {
                return(View(new MovieViewModel {
                    ActionName = "Create"
                }));
            }

            var result = await _movieService.GetMovie(id.Value);

            if (!result.IsSuccess)
            {
                return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = result.IsSuccess }));
            }

            var movie = result.Data;

            if (!await _userManager.CheckEditPermissionAsync(User, movie))
            {
                return(Forbid());
            }

            var model = MovieViewModel.FromModel(movie);

            model.ActionName = "Edit";
            return(View(model));
        }