public async Task <ActionResult <Task> > PostTask([FromBody] Task task) { _context.Tasks.Add(task); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTask", new { id = task.Id }, task)); }
public async Task <ActionResult <Task> > PutTask(int id, [FromBody] Task task) { if (id != task.Id) { return(BadRequest()); } _context.Entry(task).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(Ok(task)); } catch (DbUpdateConcurrencyException) { if (!TaskExists(id)) { return(BadRequest()); } else { throw; } } }