public async Task<IHttpActionResult> PostHabitatRestoration(HabitatRestoration habitatRestoration) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (habitatRestoration.ProjectBase != null) { habitatRestoration.ProjectBase.DateReported = DateTime.Now; } db.HabitatRestorations.Add(habitatRestoration); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (HabitatRestorationExists(habitatRestoration.HabitatRestorationId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = habitatRestoration.HabitatRestorationId }, habitatRestoration); }
public async Task<IHttpActionResult> PutHabitatRestoration(int id, HabitatRestoration habitatRestoration) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != habitatRestoration.HabitatRestorationId) { return BadRequest(); } db.Entry(habitatRestoration).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HabitatRestorationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }