Example #1
0
        public async Task <IActionResult> FlightReservationStepThree([FromBody] FlightStepThree 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.Name     = model.Name;
                        reservation.Surname  = model.Surname;
                        reservation.Passport = model.Passport;

                        await ReservationService.UpdateFlightReservation(reservation);

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

            return(BadRequest("Not enough data provided."));
        }
Example #2
0
        public async Task <IActionResult> FlightReservationStepThree([FromBody] FlightStepThree 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.Name     = model.Name;
                        reservation.Surname  = model.Surname;
                        reservation.Passport = model.Passport;

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

                        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."));
        }