예제 #1
0
        public async Task <IActionResult> Create(CreateReviewInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            bool idIsValidMovieOrSeasonId = await reviewService.IsValidMovieOrSeasonIdAsync(input.Id);

            if (!idIsValidMovieOrSeasonId)
            {
                return(Redirect(GlobalConstants.redirectError));
            }

            string userId = await userService.GetUserIdFromUserNameAsync(User.Identity.Name);

            var itemType = await reviewService.IsIdMovieOrSeasonIdAsync(input.Id);

            if (itemType == GlobalConstants.Movie)
            {
                if (!await reviewService.CreateMovieReviewAsync(userId, input))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }

                return(Redirect(redirectMovieDetails + input.Id));
            }
            else if (itemType == GlobalConstants.Season)
            {
                if (!await reviewService.CreateSeasonReviewAsync(userId, input))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }

                return(Redirect(redirectSeasonDetails + input.Id));
            }
            else
            {
                return(Redirect(GlobalConstants.redirectError));
            }
        }