public async Task<IHttpActionResult> PostRenewableEnergy(RenewableEnergy renewableEnergy) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (renewableEnergy.ProjectBase != null) { renewableEnergy.ProjectBase.DateReported = DateTime.Now; } db.RenewableEnergies.Add(renewableEnergy); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (RenewableEnergyExists(renewableEnergy.RenewableEnergyId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = renewableEnergy.RenewableEnergyId }, renewableEnergy); }
public async Task<IHttpActionResult> PutRenewableEnergy(int id, RenewableEnergy renewableEnergy) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != renewableEnergy.RenewableEnergyId) { return BadRequest(); } db.Entry(renewableEnergy).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RenewableEnergyExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }