public bool CreateComment(CommentCreateRAO model) { if (model.Content == null) { return(false); } var comment = new CommentEntity { OwnerId = _userId, Content = model.Content, ParentId = model.ParentId, GroupId = model.GroupId }; using (var ctx = new ApplicationDbContext()) { var parent = ctx.Comments.FirstOrDefault(c => c.CommentId == model.ParentId); if (parent == null && model.ParentId != 0) { return(false); } ctx.Comments.Add(comment); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(CommentCreateDTO dto) { var svc = GetCommentService(); var rao = new CommentCreateRAO { Content = dto.Content, GroupId = dto.GroupId, ParentId = dto.ParentId }; if (svc.CreateComment(rao)) { return(RedirectToAction("Index", "Group", new { id = dto.GroupId })); } return(RedirectToAction("Index", "Group", new { id = dto.GroupId })); }