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))); }
public IActionResult Put(int id, VmCommentEntry comment) { var updateComment = _context.Comment.FirstOrDefault(f => f.Id == id); if (updateComment == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest()); } updateComment.ModifyDate = DateTime.Now; _mapper.Map(comment, updateComment); _context.SaveChanges(); return(Ok(_mapper.Map <VmCommentEntry>(updateComment))); }