public async Task <IHttpActionResult> PutWell(int id, Models.Well well) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != well.Id) { return(BadRequest()); } _database.Entry(well).State = EntityState.Modified; try { await _database.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WellExists(id)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostWell(Models.Well well) { if (!ModelIsValid(well)) { return(BadRequest(ModelState)); } _database.Wells.Add(well); await _database.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = well.Id }, well)); }
private bool ModelIsValid(Models.Well well) { if (well.DbGeography == null) { if (!(Math.Abs(well.Latitude) < 0.0 || Math.Abs(well.Longitude) < 0.0)) { well.DbGeography = GeoUtils.CreatePoint(well.Latitude, well.Longitude); } else { return(false); } } return(ModelState.IsValid); }