Exemplo n.º 1
0
        // GET: Agent/Hotel
        public async Task <ActionResult> Index()
        {
            SearchHotelModel searchModel = (SearchHotelModel)Core.GetSession(Enumeration.SessionName.SearchRequest, tripid);

            ESBHotelServiceCall.Search b2BSearch = new ESBHotelServiceCall.Search(searchModel);

            var resp = await b2BSearch.GetB2BHotelListAsync();

            return(View());
        }
        // GET: Agent/SessionSetter
        public async Task <ActionResult> Hotel(string usevs = "0")
        {
            if (searchModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //if (usevs == "1" && searchModel.SearchProgress.Count == 0)
            //{
            //    if (GetCache(searchModel))
            //    {
            //        Core.SetSession(Enumeration.SessionName.SearchRequest, tripid, searchModel);
            //        return Json(true, JsonRequestBehavior.AllowGet);
            //    };
            //}

            ESBHotelServiceCall.Search b2BSearch = new ESBHotelServiceCall.Search(searchModel);
            var supplierReflect = typeof(SearchSupplier).GetProperties();

            if (searchModel.SearchProgress.Count == 0)
            {
                InsertSelectedSearchSupplier(searchModel, supplierReflect, SearchProgress.Progress.New);
            }

            var normalSearch = Task.Run(async() =>
            {
                var _temp = searchModel.DeepCopy();
                _temp.SupplierIncluded = new SearchSupplier
                {
                    Expedia = true,
                };

                return(await ESBHotelServiceCall.GetHotelListAsync(_temp));
            });

            var b2bSearch = Task.Run(async() =>
            {
                return(await b2BSearch.GetB2BHotelListAsync());
            });

            List <Task> searchTask = new List <Task>();

            if (searchTask.Count == 0)
            {
                //searchTask.Add(normalSearch);
                //searchTask.Add(b2bSearch);

                if (searchModel.GetSearchProgress(Suppliers.Expedia) == SearchProgress.Progress.New)
                {
                    searchTask.Add(normalSearch);
                    searchModel.SetSearchProgress(Suppliers.Expedia, SearchProgress.Progress.Searching);
                }

                if (searchModel.SearchProgress.Any(x => x.GetProgress == SearchProgress.Progress.New))
                {
                    searchTask.Add(b2bSearch);
                }
            }

            if (searchTask.Count == 0)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            try
            {
                int _tsk      = Task.WaitAny(searchTask.ToArray());
                var modelType = searchTask[_tsk];


                string fullQName = modelType.GetType().FullName;
                if (fullQName == normalSearch.GetType().FullName)
                {
                    searchModel.Result = normalSearch.Result;
                    searchTask.RemoveAt(_tsk);
                    searchModel.SetSearchProgress(Suppliers.Expedia, SearchProgress.Progress.Complete);
                }
                else if (fullQName == b2bSearch.GetType().FullName)
                {
                    searchModel.B2BResult = b2bSearch.Result;
                    searchTask.RemoveAt(_tsk);
                    InsertSelectedSearchSupplier(searchModel, supplierReflect, SearchProgress.Progress.Complete);
                }

                SetCache(searchModel);

                Core.SetSession(Enumeration.SessionName.SearchRequest, tripid, searchModel);

                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString()));
            }
        }