public async Task<IHttpActionResult> PutSite(int id, Site site) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != site.Id) { return BadRequest(); } db.Entry(site).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SiteExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostSite(Site site) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = UserManager.FindById(User.Identity.GetUserId()); site.Owner = user.Id; db.Sites.Add(site); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = site.Id }, site); }