public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.ProductId) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostTeacher([FromBody] Teacher teacher) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Teachers.Add(teacher); await _context.SaveChangesAsync(); return(Ok(teacher)); } catch (Exception ex) { throw ex; } }