public void AddComment(AddComment Command) { var comment = new Comment(Command.Name, Command.Email, Command.Message, Command.ArticleId); _commentRepo.AddComment(comment); _commentRepo.Save(); }
public ActionResult Add(PostDetailsViewModel model) { if (!ModelState.IsValid) { return(Redirect(Request.UrlReferrer.ToString())); //return RedirectToRoute("PostDetails", new { id = model.PostId, name = model.Post.GetTitleAsUrl() }); } Comment comment = model.Comment; comment.DateAdded = DateTime.Now; comment.UserId = User.Identity.GetUserId(); try { _commentRepo.AddComment(comment); _commentRepo.SaveChanges(); string commentClass = "comment-" + comment.Id; TempData["scrollId"] = commentClass; return(Redirect(Request.UrlReferrer.ToString())); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult <CommentDto> CreateComment(CreateCommentDto comment) { var commentEntity = _mapper.Map <Comment>(comment); commentRepo.AddComment(commentEntity); commentRepo.Save(); var commentToReturn = _mapper.Map <CommentDto>(commentEntity); return(CreatedAtRoute("GetRealEstate", new { userName = commentToReturn.UserName }, commentToReturn)); }