コード例 #1
0
        public async Task <ActionResult <Entry> > NewEntry(Entry entry)
        {
            _context.Entries.Add(entry);
            await _context.SaveChangesAsync();

            return(entry);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }