public async Task<IHttpActionResult> PostAccount(Account account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } account.Id = Guid.NewGuid(); account.active = false; account.validation_token = Guid.NewGuid(); account.date_created = DateTime.Today; account.date_updated = DateTime.Today; db.Accounts.Add(account); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (AccountAliasExists(account.alias)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = account.Id }, account); }
public async Task<IHttpActionResult> PutAccount(Account account) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //if (id != account.Id) //{ // return BadRequest(); //} db.Entry(account).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountAliasExists(account.alias)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }