示例#1
0
        public async Task <ActionResult <Comment> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();


            var comment = AssigndataUtils.AssignComment(commentDTO, 0);

            _context.Comments.Add(comment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool commentExist = _context.Comments.Any(e => e.Id == comment.Id);
                if (commentExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetComments", new { id = comment.Id }, comment));
        }
示例#2
0
        public async Task <IActionResult> Excute()
        {
            //if (id != comments.Id)
            //{
            //    return BadRequest();
            //}
            AssigndataUtils AssigndataUtils = new AssigndataUtils();

            var _context = new TGDDContext();

            Comment comment = AssigndataUtils.AssignComment(CommentDTO, CommentId);

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool commentExist = _context.Comments.Any(e => e.Id == CommentId);
                if (!commentExist)
                {
                    return(NotFound("Không tìm thấy comment!"));
                }
                else
                {
                    throw;
                }
            }
            return(Ok("Chỉnh sửa thành công !"));
        }