Пример #1
0
        public async Task <IActionResult> DelReview(int recipeId, int reviewId)
        {
            Recipe recipe     = repository.Recipes.FirstOrDefault(r => r.RecipeID == recipeId);
            Review review     = recipe.Reviews.FirstOrDefault(r => r.ReviewID == reviewId);
            var    LoggedUser = await userManager.GetUserAsync(User);

            if (recipe.UserId == LoggedUser.UserName || review.UserId == LoggedUser.UserName)
            {
                repository.DelReview(review);
                if (review != null)
                {
                    TempData["message"] = $"{review.Title} was deleted";
                }
            }
            else
            {
                TempData["message"] = $"You are not allowed to delete review!";
            }

            return(RedirectToAction("DataPage"));
        }