public async Task <ActionResult <Entry> > NewEntry(Entry entry) { _context.Entries.Add(entry); await _context.SaveChangesAsync(); return(entry); }
public async Task <ActionResult <Entry> > PostEntry(Entry entry) { entry.Date = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest()); } _context.Entries.Add(entry); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult <Comment> > PostComment(Comment comment, int id) { comment.Date = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest()); } if (_context.Entries.FindAsync(id) == null) { return(BadRequest()); } comment.EntryId = id; _context.Entries.Find(id).CommentsCount++; _context.Comments.Add(comment); await _context.SaveChangesAsync(); return(Ok()); }