public async Task<IHttpActionResult> PostBranch(Branch branch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Branch.Add(branch); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (BranchExists(branch.BranchId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = branch.BranchId }, branch); }
// PUT api/Branch/5 public async Task<IHttpActionResult> PutBranch(int id, Branch branch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != branch.BranchId) { return BadRequest(); } db.Entry(branch).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BranchExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }