public async Task<IHttpActionResult> PostReforestation(Reforestation reforestation) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (reforestation.ProjectBase != null) { reforestation.ProjectBase.DateReported = DateTime.Now; } db.Reforestations.Add(reforestation); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ReforestationExists(reforestation.ReforestationId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = reforestation.ReforestationId }, reforestation); }
public async Task<IHttpActionResult> PutReforestation(int id, Reforestation reforestation) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != reforestation.ReforestationId) { return BadRequest(); } db.Entry(reforestation).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReforestationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }