Exemplo n.º 1
0
        public async Task <ActionResult> AddAsync(CommentModel comment)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid)
                {
                    comment.CommentDate = DateTime.UtcNow;
                    Comment c = new Comment
                    {
                        ArticleId   = comment.ArticleId,
                        Email       = comment.Email,
                        Name        = comment.Email,
                        Text        = comment.Text,
                        WebSite     = comment.WebSite,
                        CommentDate = comment.CommentDate,
                        UserImage   = string.IsNullOrEmpty(comment.User.ProfilePicture) ? "default_pic.jpg" : comment.User.ProfilePicture
                    };
                    _blogDbContext.Comments.Add(c);
                    await _blogDbContext.SaveChangesAsync();

                    return(Json(comment));
                }
            }//

            else
            {
                return(Json("bad request"));
            }

            return(Json("Bad Validation"));
        }
Exemplo n.º 2
0
 public async Task <ActionResult> AddAsync(CommentModel comment)
 {
     if (ModelState.IsValid)
     {
         comment.CommentDate = DateTime.UtcNow;
         Comment c = new Comment
         {
             ArticleId   = comment.ArticleId,
             Email       = comment.Email,
             Name        = comment.Name,
             Text        = comment.Text,
             WebSite     = comment.WebSite,
             CommentDate = comment.CommentDate,
             UserImage   = string.IsNullOrEmpty(comment.UserImage) ? "default_pic.jpg" : comment.UserImage
         };
         _blogDbContext.Comments.Add(c);
         await _blogDbContext.SaveChangesAsync();
     }
     return(RedirectToAction("Details", "Articles", new { id = comment.ArticleId }));
 }