Esempio n. 1
0
        public bool AddFlightOrder(FlightOrder flightOrder)
        {
            int rowsEffected = -1;

            using (var context = new DataContext(DataContext.ops.dbOptions))
            {
                User          user          = context.User.Where(theUser => theUser.UserId == flightOrder.User.UserId).SingleOrDefault();
                Flight        flight        = context.Flight.Where(theFlight => theFlight.FlightId == flightOrder.Flight.FlightId).SingleOrDefault();
                FlightLuggage flightLuggage = context.FlightLuggage.Where(theFlightLuggage => theFlightLuggage.FlightLuggageId == flightOrder.FlightLuggage.FlightLuggageId).SingleOrDefault();
                Seat          seat          = context.Seat.Where(theSeat => theSeat.SeatId == flightOrder.Seat.SeatId).SingleOrDefault();
                FlightTicket  flightTicket  = context.FlightTicket.Where(theFlightTicket => theFlightTicket.FlightTicketId == flightOrder.FlightTicket.FlightTicketId).SingleOrDefault();

                flightOrder.User          = user;
                flightOrder.Flight        = flight;
                flightOrder.FlightLuggage = flightLuggage;
                flightOrder.Seat          = seat;
                flightOrder.FlightTicket  = flightTicket;



                context.FlightOrder.Add(flightOrder);

                rowsEffected = context.SaveChanges();

                if (rowsEffected > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        public FlightLuggage GetFlightLuggage(int id)
        {
            FlightLuggage flightLuggage = new FlightLuggage();

            using (var context = new DataContext(DataContext.ops.dbOptions))
            {
                flightLuggage = context.FlightLuggage.Where(theLuggage => theLuggage.FlightLuggageId == id).SingleOrDefault();
            }

            return(flightLuggage);
        }
Esempio n. 3
0
        public async Task <IActionResult> AddLuggage(FlightLuggage lugg)
        {
            try
            {
                await context.Luggages.AddAsync(lugg);

                await context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(NoContent());
            }
        }
Esempio n. 4
0
        public bool AddFlightLuggage(FlightLuggage flightLuggage)
        {
            int rowsEffected = -1;

            using (var context = new DataContext(DataContext.ops.dbOptions))
            {
                context.Add(flightLuggage);
                try {
                    rowsEffected = context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            return(rowsEffected > 0 ? true : false);
        }
Esempio n. 5
0
        public async Task <IActionResult> ChangeLuggageForCompany(FlightLuggage lugg)
        {
            try
            {
                FlightLuggage fl = await context.Luggages.SingleOrDefaultAsync(x => x.IdCompany == lugg.IdCompany);

                fl.CarryOnPrice = lugg.CarryOnPrice;
                fl.DuffelPrice  = lugg.DuffelPrice;
                context.Luggages.Update(fl);
                await context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(NoContent());
            }
        }
Esempio n. 6
0
        public Holder <FlightLuggage> AddFlightLuggage(FlightLuggage flightLuggage)
        {
            List <FlightLuggage> flightLuggageList = _airlineDatabase.GetFlightLuggage();

            if (flightLuggage.FlightLuggageType.GetType() == typeof(DBNull))
            {
                return(CheckFlightLuggage(flightLuggage, 400, "Flight luggage must have type"));
            }

            foreach (FlightLuggage luggageInstance in flightLuggageList)
            {
                if (luggageInstance.FlightLuggageType == flightLuggage.FlightLuggageType)
                {
                    return(CheckFlightLuggage(flightLuggage, 403, "Flight luggage with this type already exists"));
                }
            }

            if (_airlineDatabase.AddFlightLuggage(flightLuggage))
            {
                return(CheckFlightLuggage(flightLuggage, 200, ""));
            }

            return(CheckFlightLuggage(flightLuggage, 500, "Unable to add flight luggage"));
        }
Esempio n. 7
0
 public Holder <FlightLuggage> AddFlightLuggage([FromBody] FlightLuggage flightLuggage)
 {
     return(_airlineBusiness.AddFlightLuggage(flightLuggage));
 }
Esempio n. 8
0
 Holder <FlightLuggage> CheckFlightLuggage(FlightLuggage flightLuggage, int errorCode, string description) =>
 errorCode == 200 ? Holder <FlightLuggage> .Success(flightLuggage) : Holder <FlightLuggage> .Fail(errorCode, description);