Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        public async Task <IHttpActionResult> GetCommercialFlight(string id)
        {
            CommercialFlight commercialFlight = await db.CommercialFlights.FindAsync(id);

            if (commercialFlight == null)
            {
                return(NotFound());
            }

            return(Ok(commercialFlight));
        }
Example #4
0
        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));
        }
Example #5
0
        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));
        }