Example #1
0
        public JsonResult GetRecipeCommentsForUser(int recipeId)
        {
            var recipe = unitOfWork.RecipeRepository.GetById(recipeId);

            if (recipe != null)
            {
                var comments     = recipe.Comments;
                var commentsJson = comments.Select(comment => new CommentJsonViewModel
                {
                    UserId = comment.UserId, UserName = IdentityHelpers.GetUserName(comment.UserId), CommentText = comment.CommentText, CreateDateTime = String.Format("{0:r}", comment.CreateDateTime)
                }).ToList();
                return(Json(commentsJson));
            }
            return(null);
        }