public IHttpActionResult PostAccount(AccountsModel account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbPostAccount = new Account(); dbPostAccount.Update(account); db.Accounts.Add(dbPostAccount); db.SaveChanges(); account.CustomerID = dbPostAccount.CustomerID; return CreatedAtRoute("DefaultApi", new { id = dbPostAccount.CustomerID }, account); }
public IHttpActionResult PutAccount(int id, AccountsModel account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != account.AccountID) { return BadRequest(); } var dbPutAccount = db.Accounts.Find(account.CustomerID); dbPutAccount.Update(account); db.Entry(dbPutAccount).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }