Esempio n. 1
0
        public ActionResult BusSearch(string from, string to, DateTime date)
        {
            //string appId = ConfigurationManager.AppSettings["GoibiboAppId"] as string;
            //string appSecret = ConfigurationManager.AppSettings["GoibiboAppKey"] as string;
            //string responseFormat = ConfigurationManager.AppSettings["GoibiboResponseFormat"] as string;
            //string goibiboApiUri = ConfigurationManager.AppSettings["GoibiboApiUri"] as string;
            //var searchHelper = new GoibiboBusSearchHelper(appId, appSecret, goibiboApiUri, responseFormat);
            //var details = searchHelper.GetBusDetails("Hyderabad", "Vijayawada", DateTime.Now.ToString("yyyyMMdd"));
            busRepo = new Repository.BusSearch();
            var details = busRepo.SearchBusses(from, to, date);

            return(View());
            //return JsonConvert.SerializeObject(details);
        }
Esempio n. 2
0
        private async Task ResumeAfterTravelFormDialog(IDialogContext context, IAwaitable <TravelBooking> result)
        {
            var travelInfo = await result;

            if (string.IsNullOrEmpty(travelInfo.TravelType))
            {
                travelInfo.TravelType = "Buses";
            }
            if (!string.IsNullOrEmpty(travelInfo.DateOfTravel) && ParseChronicDate(travelInfo.DateOfTravel).HasValue)
            {
                travelInfo.ConvertedDateTime = ParseChronicDate(travelInfo.DateOfTravel).Value;
            }
            if (travelInfo.ConvertedDateTime == DateTime.MinValue)
            {
                travelInfo.ConvertedDateTime = DateTime.Now.Date;
            }
            //await context.PostAsync($"Now {travelInfo.TravelType} will be searched");
            await context.PostAsync("Now I am going to make some quick calls to get the details... Hold on tight .... It may take a minute since we are using all cheap resources to accumulate the data .");

            Log.Info($"String Entered {travelInfo.DateOfTravel} date Detected : { travelInfo.ConvertedDateTime}");
            BusSearch busSearchHelper = new BusSearch();

            Log.Info("After Bus Search Init");
            var bussesAndFlights = busSearchHelper.SearchBusses(travelInfo.FromLocation, travelInfo.ToLocation, travelInfo.ConvertedDateTime);

            Log.Info("After Bus Search Method");
            if (bussesAndFlights.data == null || bussesAndFlights.data.onwardflights == null || bussesAndFlights.data.onwardflights.Count() == 0)
            {
                await context.PostAsync($"Sorry I cant find any {travelInfo.TravelType} from {travelInfo.FromLocation} to {travelInfo.ToLocation}");
            }
            else
            {
                var busResultAfterSortingLogic = bussesAndFlights.data.onwardflights.AsEnumerable();
                if (!string.IsNullOrEmpty(travelInfo.Class))
                {
                    if (travelInfo.Class.ToLower().Contains("fast"))
                    {
                        busResultAfterSortingLogic = bussesAndFlights.data.onwardflights.OrderBy(x => x.arrdate - x.depdate);
                    }
                    else if (travelInfo.Class.ToLower().Contains("cheap"))
                    {
                        busResultAfterSortingLogic = bussesAndFlights.data.onwardflights.OrderBy(x => x.fare.totalfare);
                    }
                }

                var resultMessage = context.MakeMessage();
                resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments      = new List <Attachment>();
                //var nonAcURL = "";//ToAbsoluteUrl("/Images/Non AC bus.jpg");
                //var acUrl = ""; ToAbsoluteUrl("/Images/AC bus.jpg");
                foreach (var busOrFlight in busResultAfterSortingLogic.Take(5))
                {
                    var      routeType = busOrFlight.RouteSeatTypeDetail.list.FirstOrDefault();
                    HeroCard heroCard  = new HeroCard()
                    {
                        Title    = busOrFlight.TravelsName,
                        Subtitle = $"{busOrFlight.BusType} starts at {busOrFlight.DepartureTime} to {busOrFlight.destination}  @Rs . {busOrFlight.fare.totalfare} ",
                        Text     = $"Departs on {busOrFlight.depdate} at {busOrFlight.DepartureTime} Origin - {busOrFlight.origin} service number - {busOrFlight.BusServiceID} reaches {busOrFlight.destination} at {busOrFlight.arrdate} @Rs . {busOrFlight.fare.totalfare}",
                        //Images = new List<CardImage>()
                        //{
                        //    new CardImage() { Url = routeType == null ? nonAcURL : (routeType.busCondition.Contains("nonac") ? nonAcURL : acUrl) }
                        //},
                        Buttons = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = $"Rs . {busOrFlight.fare.totalfare}",
                                Type  = ActionTypes.OpenUrl,
                                Value = $"https://www.google.com"
                            }
                        }
                    };

                    resultMessage.Attachments.Add(heroCard.ToAttachment());
                }
                await context.PostAsync(resultMessage);
            }
        }