示例#1
0
        public IActionResult Post(VmPostEntry post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var newPost = _mapper.Map <Post>(post);

            newPost.EntryDate = DateTime.Now;
            _context.Post.Add(_mapper.Map <Post>(newPost));
            _context.SaveChanges();
            return(CreatedAtAction(nameof(GetById), new { id = newPost.Id }, post));
        }
        public IActionResult Post(VmCommentEntry comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var newComment = _mapper.Map <Comment>(comment);

            newComment.EntryDate = DateTime.Now;
            _context.Comment.Add(newComment);
            _context.SaveChanges();
            return(Ok(_mapper.Map <VmCommentEntry>(newComment)));
        }
示例#3
0
        public IActionResult Post(VmVote vote)
        {
            var comment = _context.Comment.FirstOrDefault(f => f.Id == vote.Id);

            if (comment == null)
            {
                return(BadRequest());
            }
            comment.Like    = vote.Like;
            comment.Dislike = vote.Dislike;
            _context.SaveChanges();
            return(Ok());
        }