public async Task <IActionResult> Update([FromRoute] int id, [FromBody] Article article) { // 模擬長時間的載入 _delay.Wait(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != article.Id) { return(BadRequest()); } _context.Entry(article).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_context.Articles.Any(e => e.Id == id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Regist([FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Users.Add(user); await _context.SaveChangesAsync(); return(CreatedAtAction("Signin", user)); }