public async Task<IHttpActionResult> PostPhotoResistance(PhotoResistance photoResistance) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if(photoResistance.CollectionTime == null) { photoResistance.CollectionTime = DateTime.UtcNow; } db.PhotoResistances.Add(photoResistance); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (PhotoResistanceExists(photoResistance.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = photoResistance.Id }, photoResistance); }
public async Task<IHttpActionResult> PutPhotoResistance(int id, PhotoResistance photoResistance) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != photoResistance.Id) { return BadRequest(); } db.Entry(photoResistance).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhotoResistanceExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }