Exemplo n.º 1
0
        public IHttpActionResult PostFlightScheduleDetail(FlightScheduleDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flights = new FlightScheduleDetail()
                    {
                        JourneyDate      = flight.JourneyDate,
                        Price            = flight.Price,
                        SeatAvailability = flight.SeatAvailability,
                        FlightDetailId   = flight.FlightDetailId
                    };
                    ctx.FlightScheduleDetails.Add(flights);

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult PutFlightScheduleDetail(FlightScheduleDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flighttobeUpdated = ctx.FlightScheduleDetails.Where(x => x.Id == flight.Id).FirstOrDefault <FlightScheduleDetail>();
                    if (flighttobeUpdated != null)
                    {
                        flighttobeUpdated.JourneyDate      = flight.JourneyDate;
                        flighttobeUpdated.Price            = flight.Price;
                        flighttobeUpdated.SeatAvailability = flight.SeatAvailability;
                    }

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }