public IHttpActionResult PostAlternativeSource(AlternativeSource alternativeSource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.AlternativeSources.Add(alternativeSource); try { db.SaveChanges(); } catch (DbUpdateException) { if (AlternativeSourceExists(alternativeSource.AlternativeSourceAvailableIfWapdaNotAvailable)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = alternativeSource.AlternativeSourceAvailableIfWapdaNotAvailable }, alternativeSource)); }
public IHttpActionResult PutAlternativeSource(string id, AlternativeSource alternativeSource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != alternativeSource.AlternativeSourceAvailableIfWapdaNotAvailable) { return(BadRequest()); } db.Entry(alternativeSource).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AlternativeSourceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetAlternativeSource(string id) { AlternativeSource alternativeSource = db.AlternativeSources.Find(id); if (alternativeSource == null) { return(NotFound()); } return(Ok(alternativeSource)); }
public IHttpActionResult DeleteAlternativeSource(string id) { AlternativeSource alternativeSource = db.AlternativeSources.Find(id); if (alternativeSource == null) { return(NotFound()); } db.AlternativeSources.Remove(alternativeSource); db.SaveChanges(); return(Ok(alternativeSource)); }