public async Task UpdateTravelAndVisitorAsync(Notification notification, TravelDetails travelDetails, VisitorDetails visitorDetails)
        {
            UpdateTravelDetails(notification, travelDetails);
            UpdateVisitorDetails(notification, visitorDetails);

            await _notificationRepository.SaveChangesAsync();
        }
Example #2
0
        // Validates the user's response for origin and destination
        public static ValidateResult ValidateAirport(TravelDetails state, string value, bool checkOrigDestSame)
        {
            bool isValid = false;

            List <string>  values = new List <string>();
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };

            string city = (value != null) ? value.Trim() : string.Empty;

            if (ProcessUnfollow(city, ref result))
            {
                return(result);
            }

            if (city != string.Empty)
            {
                // Get the IATA code (if any) corresponding to the user input
                isValid = Data.fd.IsIataCode(value.ToString(), ref values);

                if (isValid)
                {
                    // Processes the IATA code response
                    result = ValidateAirportHelpers.ProcessAirportIataResponse(state, checkOrigDestSame, values.ToArray());
                }
                // When multiple airports are found for a given city
                else
                {
                    // Get all the IATA codes for all the airports in a city
                    string[] codes = InternalGetIataCodes(value.ToString().Trim());

                    if (codes.Length == 1)
                    {
                        // When the specific match is found
                        result = ValidateAirportHelpers.ProcessAirportResponse(state, checkOrigDestSame, codes);
                    }
                    else if (codes.Length > 1)
                    {
                        // When multiple options are found
                        result = new ValidateResult {
                            IsValid = isValid, Value = string.Empty
                        };
                        result = ValidateAirportHelpers.GetOriginOptions(codes, result);
                    }
                    else
                    {
                        if (result.Feedback != null)
                        {
                            result = new ValidateResult {
                                IsValid = isValid, Value = string.Empty
                            };
                            result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                        }
                    }
                }
            }

            return(result);
        }
Example #3
0
        // Validates the user's number of passengers response
        public static ValidateResult ValidateNumPassengers(TravelDetails state, string value)
        {
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };

            string numPassengers = (value != null) ? value.Trim() : string.Empty;

            if (ProcessUnfollow(numPassengers, ref result))
            {
                return(result);
            }

            if (numPassengers != string.Empty)
            {
                // Verifies the number of passengers and if it correct
                result = ValidateNumPassengerHelper.ValidateNumPassengers(numPassengers);

                if (!result.IsValid && (result.Feedback == null || result.Feedback == string.Empty))
                {
                    result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                }
            }
            else
            {
                if (result.Feedback != null)
                {
                    result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                }
            }

            return(result);
        }
        private static TravelDetails ExtractTravelDetails(MigrationDbNotification notification)
        {
            var hasTravel         = Converter.GetStatusFromString(notification.HasTravel);
            int?numberOfCountries = Converter.ToNullableInt(notification.travel_TotalNumberOfCountries);
            var countriesRecorded = new List <int?>
            {
                notification.travel_Country1, notification.travel_Country2, notification.travel_Country3
            }.Distinct()
            .Count(c => c != null);
            int?totalNumberOfCountries = hasTravel == Status.Yes && numberOfCountries != null
                ? Math.Max(numberOfCountries.Value, countriesRecorded)
                : (int?)null;

            var details = new TravelDetails();

            details.HasTravel = hasTravel;
            details.TotalNumberOfCountries = totalNumberOfCountries;
            details.Country1Id             = notification.travel_Country1;
            details.Country2Id             = notification.travel_Country2;
            details.Country3Id             = notification.travel_Country3;
            details.StayLengthInMonths1    = notification.travel_StayLengthInMonths1;
            details.StayLengthInMonths2    = notification.travel_StayLengthInMonths2;
            details.StayLengthInMonths3    = notification.travel_StayLengthInMonths3;
            RemoveDuplicateCountries(details);
            return(details);
        }
 private void UpdateTravelDetails(Notification notification, TravelDetails travelDetails)
 {
     if (travelDetails.HasTravel != Status.Yes)
     {
         ClearTravelOrVisitorFields(travelDetails);
     }
     _context.SetValues(notification.TravelDetails, travelDetails);
 }
Example #6
0
        public async Task <IActionResult> PostTravelDetails([FromBody] TravelDetails newTrip)
        {
            var loggedInMember = GetLoggedInMember();

            newTrip.TravelersId = loggedInMember.FirstName + " " + loggedInMember.LastName;
            _context.TravelDetails.Add(newTrip);
            _context.SaveChanges();

            return(Ok());
        }
Example #7
0
        // Part of the validation of the origin and destination checks
        public static ValidateResult ProcessAirportResponse(TravelDetails state, bool checkOrigDestSame, string[] codes)
        {
            string field = string.Empty;

            ValidateResult result = ProcessPrefix(state, checkOrigDestSame, codes, out field);

            result.Feedback = (result.IsValid) ? field : GatherErrors.cStrGatherSameCities;

            return(result);
        }
Example #8
0
        // Checks that the IATA code submitted by the user for origin or destination is a valid code
        public static ValidateResult ProcessAirportIataResponse(TravelDetails state, bool checkOrigDestSame, string[] items)
        {
            string field = string.Empty;

            string[] airport = new string[] { items[0] + "|" + Data.fd.GetAirportCity(items[0]) };

            ValidateResult result = ProcessPrefix(state, checkOrigDestSame, airport, out field);

            result.Feedback = (result.IsValid) ? field : GatherErrors.cStrGatherSameCities;

            return(result);
        }
Example #9
0
        protected override async Task ValidateAndSave()
        {
            TravelDetails.SetValidationContext(Notification);
            VisitorDetails.SetValidationContext(Notification);

            CleanModel();

            TryValidateModel(TravelDetails, TravelDetails.GetType().Name);
            TryValidateModel(VisitorDetails, VisitorDetails.GetType().Name);

            if (ModelState.IsValid)
            {
                await Service.UpdateTravelAndVisitorAsync(Notification, TravelDetails, VisitorDetails);
            }
        }
Example #10
0
        // Part of the validation of the origin and destination checks
        private static ValidateResult ProcessPrefix(TravelDetails state, bool checkOrigDestSame, string[] codes, out string field)
        {
            string[] code = codes[0].Split('|');

            string prefix = !checkOrigDestSame ? "Origin" : "Destination";

            field = $"{prefix}: {code[1]} ({code[0]})";

            ValidateResult result = (checkOrigDestSame) ? CheckOrigDestState(state, code[0]) :
                                    new ValidateResult {
                IsValid = true, Value = code[0]
            };

            return(result);
        }
Example #11
0
        protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted)
        {
            TravelDetails  = Notification.TravelDetails;
            VisitorDetails = Notification.VisitorDetails;
            await SetNotificationProperties(isBeingSubmitted, TravelDetails);
            await SetNotificationProperties(isBeingSubmitted, VisitorDetails);

            if (TravelDetails.ShouldValidateFull)
            {
                TryValidateModel(TravelDetails, TravelDetails.GetType().Name);
            }
            if (VisitorDetails.ShouldValidateFull)
            {
                TryValidateModel(VisitorDetails, VisitorDetails.GetType().Name);
            }

            return(Page());
        }
Example #12
0
        // Checks that the origin and destination are not the same
        private static ValidateResult CheckOrigDestState(TravelDetails state, string field)
        {
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };

            result.Feedback = GatherErrors.cStrGatherSameCities;

            if (state?.OriginIata.ToLower() != field.ToLower())
            {
                result = new ValidateResult {
                    IsValid = true, Value = field
                }
            }
            ;

            return(result);
        }
Example #13
0
        // Validates the user's response for a direct flight (or not)
        public static ValidateResult ValidateDirect(TravelDetails state, string value)
        {
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };

            string direct = (value != null) ? value.Trim() : string.Empty;

            if (ProcessUnfollow(direct, ref result))
            {
                return(result);
            }

            if (direct != string.Empty)
            {
                // If direct flight response is correct
                if (direct.ToLower() == GatherQuestions.cStrYes ||
                    direct.ToLower() == GatherQuestions.cStrNo)
                {
                    return new ValidateResult {
                               IsValid = true, Value = direct.ToUpper()
                    }
                }
                ;
                else
                {
                    if (result.Feedback != null)
                    {
                        result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                    }
                }
            }
            else
            {
                if (result.Feedback != null)
                {
                    result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                }
            }

            return(result);
        }
        // Set the bot's state as the internal state
        public static void AssignStateToFlightData(ValidateResult result, TravelDetails state)
        {
            if (result.IsValid)
            {
                string userId = Data.fd.FlightDetails.UserId;

                Data.fd.FlightDetails = new FlightDetails()
                {
                    OriginIata      = state.OriginIata,
                    DestinationIata = state.DestinationIata,
                    OutboundDate    = state.OutboundDate,
                    InboundDate     = state.InboundDate,
                    NumPassengers   = state.NumPassengers,
                    NumResults      = "1",
                    Direct          = state.Direct,
                    UserId          = userId,
                    Follow          = result.Value.ToString()
                };
            }
        }
Example #15
0
        // Validates the user's response to follow a flight request (for price changes)
        public static ValidateResult ValidateFollow(TravelDetails state, string value)
        {
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };

            string follow = (value != null) ? value.Trim() : string.Empty;

            if (ProcessUnfollow(follow, ref result))
            {
                return(result);
            }

            if (follow != string.Empty)
            {
                // If the response to follow a flight is correct
                if (follow.ToLower() == GatherQuestions.cStrYes ||
                    follow.ToLower() == GatherQuestions.cStrNo)
                {
                    return new ValidateResult {
                               IsValid = true, Value = follow.ToUpper()
                    }
                }
                ;
                else
                {
                    if (result.Feedback != null)
                    {
                        result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                    }
                }
            }
            else
            {
                result.Feedback = GatherQuestions.cStrGatherRequestProcessedNoGuid;
            }

            return(result);
        }
Example #16
0
        // Validates the user's travel date (outbound or inbound) response
        public static ValidateResult ValidateDate(TravelDetails state, string value, bool checkOutInDatesSame)
        {
            ValidateResult result = new ValidateResult {
                IsValid = false, Value = string.Empty
            };
            string date = (value != null) ? value.Trim() : string.Empty;

            if (ProcessUnfollow(date, ref result))
            {
                return(result);
            }

            if (checkOutInDatesSame && value.ToLower().Contains(GatherQuestions.cStrGatherProcessOneWay))
            {
                return new ValidateResult {
                           IsValid = true, Value = GatherQuestions.cStrGatherProcessOneWay
                }
            }
            ;

            if (date != string.Empty)
            {
                DateTime res;

                // If it is a proper date
                if (DateTime.TryParse(value, out res))
                {
                    if (checkOutInDatesSame)
                    {
                        // Performs the actual date validation
                        result = ValidateDateHelper.ValidateGoAndReturnDates(
                            ValidateDateHelper.ToDateTime(state.OutboundDate),
                            ValidateDateHelper.ToDateTime(value),
                            ValidateDateHelper.FormatDate(value));
                    }
                    else
                    {
                        // If it is a date in the future
                        result = ValidateDateHelper.IsFutureDate(
                            ValidateDateHelper.ToDateTime(value), ValidateDateHelper.FormatDate(value));
                    }
                }
                else
                {
                    if (result.Feedback != null)
                    {
                        result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                    }
                }
            }
            // If it is not a proper date
            else
            {
                if (result.Feedback != null)
                {
                    result.Feedback = GatherQuestions.cStrGatherProcessTryAgain;
                }
            }

            return(result);
        }
Example #17
0
 public IActionResult OnPostValidateTravel([FromBody] TravelDetails travelDetails)
 {
     Service.ClearTravelOrVisitorFields(travelDetails);
     return(ValidationService.GetFullModelValidationResult(travelDetails));
 }