public async Task <IHttpActionResult> PutCommercialFlight(string id, CommercialFlight commercialFlight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != commercialFlight.IdFlight) { return(BadRequest()); } db.Entry(commercialFlight).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommercialFlightExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostCommercialFlight(CommercialFlight commercialFlight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CommercialFlights.Add(commercialFlight); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CommercialFlightExists(commercialFlight.IdFlight)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = commercialFlight.IdFlight }, commercialFlight)); }
public async Task <IHttpActionResult> GetCommercialFlight(string id) { CommercialFlight commercialFlight = await db.CommercialFlights.FindAsync(id); if (commercialFlight == null) { return(NotFound()); } return(Ok(commercialFlight)); }
public async Task <IHttpActionResult> DeleteCommercialFlight(string id) { CommercialFlight commercialFlight = await db.CommercialFlights.FindAsync(id); if (commercialFlight == null) { return(NotFound()); } db.CommercialFlights.Remove(commercialFlight); await db.SaveChangesAsync(); return(Ok(commercialFlight)); }
public IHttpActionResult PutPreBooks(string id, int cant) { CommercialFlight vuelo = db.CommercialFlights.Find(id); if (id != vuelo.IdFlight) { return(BadRequest()); } vuelo.Disponible_Places = vuelo.Disponible_Places - cant; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(vuelo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommercialFlightExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }