Esempio n. 1
0
        public async Task <IActionResult> FlightReservationStepTwo([FromBody] FlightStepTwo model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserService.GetCurrentUser();

                if (user != null)
                {
                    var reservation = user.ReservedFlights.SingleOrDefault(rf => rf.FlightReservationId == model.ReservationId);

                    if (reservation != null)
                    {
                        bool finished = true;
                        if (!reservation.Finished)
                        {
                            finished = false;
                        }

                        reservation.SeatNumber = model.Seat;
                        await ReservationService.UpdateFlightReservation(reservation);

                        if (!finished && reservation.Finished)
                        {
                            var flight = await FlightService.GetFlight(reservation.FlightId);

                            var sCoord = new GeoCoordinate(flight.DepartureLocation.Latitude, flight.DepartureLocation.Longitude);
                            var eCoord = new GeoCoordinate(flight.ArrivalLocation.Latitude, flight.ArrivalLocation.Longitude);

                            user.Bonus += (int)(sCoord.GetDistanceTo(eCoord) / 100000);
                            await UserService.UpdateUser(user);
                        }

                        return(Ok(new { reservation }));
                    }
                }
            }

            return(BadRequest("Not enough data provided."));
        }
Esempio n. 2
0
        public async Task <IActionResult> FlightReservationStepTwo([FromBody] FlightStepTwo model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserService.GetCurrentUser();

                if (user != null)
                {
                    var reservation = user.ReservedFlights.SingleOrDefault(rf => rf.FlightReservationId == model.ReservationId);

                    if (reservation != null)
                    {
                        reservation.SeatNumber = model.Seat;
                        await ReservationService.UpdateFlightReservation(reservation);

                        return(Ok(new { reservation }));
                    }
                }
            }

            return(BadRequest("Not enough data provided."));
        }