コード例 #1
0
ファイル: CommentService.cs プロジェクト: JTux/ChoreTracker
        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);
            }
        }
コード例 #2
0
        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 }));
        }