Beispiel #1
0
        public SearchResponseModel GetAllByCompanyModel(CompanyModel model, List <string> States)
        {
            IQueryable <Data.statecountycode> StateCountyCollection = _unit3.statecountycodes;
            List <long?> countyArray = new List <long?>();

            foreach (var state in States)
            {
                countyArray.AddRange(StateCountyCollection.Where(p => p.State_Description == state.Trim()).Select(p => p.County_Number).ToList().ConvertAll <long?>(p => p));
            }
            countyArray.AddRange(model.CountyCodes);
            model.CountyCodes = countyArray.ToArray();

            List <int?> empsizeArray = new List <int?>();

            foreach (var range in model.EmpSize)
            {
                empsizeArray.Add(int.Parse(range));
            }

            int totalItems = 0;
            var items      = GetSearchResults(model, empsizeArray, out totalItems);

            var response = new SearchResponseModel
            {
                Companies = items,
                Showed    = 200,
                Total     = totalItems,
            };

            return(response);
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //app.UseHttpsRedirection();
            app.UseExceptionHandler(new ExceptionHandlerOptions()
            {
                ExceptionHandler = async(context) =>
                {
                    var ex    = context.Features.Get <IExceptionHandlerPathFeature>();
                    var model = new SearchResponseModel
                    {
                        Message = $"Fail - {ex.Error.Message}",
                        Success = false
                    };
                    context.Response.ContentType = "application/json";
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(model));
                }
            });

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #3
0
        private async Task <DialogTurnResult> IntroQuestionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var message = string.Empty;
            var state   = await(stepContext.Context.TurnState[nameof(NexoBotAccessors)] as NexoBotAccessors).NexoBotStateStateAccessor.GetAsync(stepContext.Context);

            if (stepContext.Result != null)
            {
                state.Messages.Add(stepContext.Result.ToString());
            }

            //Qna
            var response = await _services.QnAServices[QnaMakerServiceConfiguration.QnaKey].GetAnswersAsync(stepContext.Context);

            if (response != null && response.Length > 0)
            {
                message = response[0].Answer;
            }
            else
            {
                //Bing Web Search
                SearchResponseModel searchResponse = await _searchService.GetResultFromSearch(stepContext.Context.Activity.Text);

                if (searchResponse != null)
                {
                    message = _lgEngine.Evaluate("Answer", searchResponse).ToString();
                }
            }

            await stepContext.Context.SendActivityAsync(message);

            return(await stepContext.NextAsync());
        }
        public async Task <ConnectorResult> SearchAsync(FullPath path, string query, IEnumerable <string> mimeTypes)
        {
            var response = new SearchResponseModel();

            if (!query.Any(Path.GetInvalidFileNameChars().Contains))
            {
                foreach (var item in await path.Directory.GetFilesAsync(mimeTypes, string.Concat("*", query, "*")))
                {
                    if (!item.Attributes.HasFlag(FileAttributes.Hidden) && !item.Directory.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        response.Files.Add(await BaseModel.CreateAsync(item, path.RootVolume));
                    }
                }

                if (!mimeTypes.Any())
                {
                    foreach (var item in await path.Directory.GetDirectoriesAsync(string.Concat("*", query, "*")))
                    {
                        if (!item.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            response.Files.Add(await BaseModel.CreateAsync(item, path.RootVolume));
                        }
                    }
                }
            }

            return(new ConnectorResult(response));
        }
Beispiel #5
0
        public static string RenderSearchResponse(string key, SearchResponseModel model)
        {
            if (model.Datas.Any())
            {
                var infos     = model.Datas.Select(x => x.Name + "\n" + x.Url).ToArray();
                var data_info = string.Join("\n", infos);
                return($"为保证观看效果,请用手机浏览器打开以下链接。\n" +
                       $"您好,您搜索的 {key} 共有 {model.Count} 条数据,本次展示 {model.Datas.Count} 条:\n{data_info}");
            }

            return($"您好,您搜索的 {key} 不存在,请10秒之后再试,如果仍然没有我们会进行记录,会尽快添加此资源!");
        }
 public static IEnumerable <RepositoryInfo> ToEntity(this SearchResponseModel model) =>
 model?.Items?.Select(x => new RepositoryInfo()
 {
     AuthorAvatar = x.Owner.Avatar,
     AuthorLogin  = x.Owner.Login,
     CodeLanguage = x.CodeLanguage,
     Description  = x.Description,
     Forks        = x.Forks,
     LastUpdate   = x.LastUpdated,
     Link         = x.Link,
     Stars        = x.Stars,
     Title        = x.Title,
 });
Beispiel #7
0
        public ActionResult Search([FromBody] SearchRequestModel request)
        {
            SearchResponseModel model;
            var resposnse = _searchService.Search(request.Query, request.Markets, request.Limit);

            model = new SearchResponseModel()
            {
                SearchResult = resposnse,
                Total        = resposnse.SearchResultItems.Count,
                Success      = resposnse?.SearchResultItems?.Count >= 0 ? true : false,
                Message      = "Success"
            };
            return(Ok(model));
        }
Beispiel #8
0
        public async Task <IActionResult> Search(SearchModel model)
        {
            if (ModelState.IsValid)
            {
                InitUserCredentials();
                var results  = _mapper.Map(_commentService.Search(model, CompanyGuid), new List <CommentResponseModel>());
                var response = new SearchResponseModel()
                {
                    Data = results
                };
                return(Ok(response));
            }

            return(new NoContentResult());
        }
        public async Task <SearchResponseModel> Search([FromQuery] string query)
        {
            var tasks = new List <Task> {
                _searchJokes.Handle(query),
                _searchCharacters.Handle(query)
            };

            await Task.WhenAll(tasks);

            SearchResponseModel searchResponseModel = new SearchResponseModel
            {
                Chuck = (tasks[0] as Task <List <ChuckNorrisJoke> >).Result,
                Swapi = (tasks[1] as Task <List <StarWarCharacter> >).Result
            };


            return(searchResponseModel);
        }
Beispiel #10
0
        public static List <SearchResultItemViewModel> ToSearchResultItemViewModel(this SearchResponseModel model)
        {
            var res = new List <SearchResultItemViewModel>();

            if (model.Success && model.SearchResult.SearchResultItems.Count > 0)
            {
                foreach (var item in model.SearchResult.SearchResultItems)
                {
                    res.Add(new SearchResultItemViewModel()
                    {
                        Id   = item.Id,
                        Text = item.Name,
                        Type = item.Type
                    });
                }
            }
            return(res);
        }
Beispiel #11
0
        public async Task <SearchResponseModel> getSearchItems(string token, SearchRequestModel searchRequestModel)
        {
            var uriBuilder = new UriBuilder(Constants.RestUrl + "/api/search");
            var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

            query["keyword"] = searchRequestModel.Keywords;

            if (searchRequestModel.SearchDistance > 0)
            {
                query["distance"]  = searchRequestModel.SearchDistance.ToString();
                query["latitude"]  = searchRequestModel.CurrentLocation?.Latitude.ToString();
                query["longitude"] = searchRequestModel.CurrentLocation?.Latitude.ToString();
            }
            uriBuilder.Query = query.ToString();

            string authToken             = Preferences.Get("api_key", "null");
            SearchResponseModel response = await _requestService.GetAsync <SearchResponseModel>(uriBuilder.Uri.AbsoluteUri, authToken);

            return(response);
        }
Beispiel #12
0
        public IEnumerable <SearchResponseModel> GetStatusSearch(List <Searcher> searchers)
        {
            if (searchers == null || searchers.Count < 1)
            {
                return(null);
            }
            var list = new List <SearchResponseModel>(searchers.Capacity);

            foreach (var s in searchers)
            {
                var model = new SearchResponseModel()
                {
                    SearchText    = s.SearchText,
                    CountItems    = s.CountItems,
                    CountPages    = s.CountPages,
                    PageLoadSpeed = s.PageLoadSpeed,
                    LostTime      = s.LostTime.ToString("---"),
                    CurrentPage   = s.CurrentPage,
                    IsCanceled    = !s.IsNext || s.ErrorExist
                };
                list.Add(model);
            }

            if (list.Count > 1)
            {
                var model = new SearchResponseModel()
                {
                    SearchText    = "Summary:",
                    CountItems    = list.Sum(a => a.CountItems),
                    CountPages    = list.Sum(a => a.CountPages),
                    PageLoadSpeed = null,
                    LostTime      = ((Time)searchers.Sum(a => a.LostTime)).ToStringNull("---"),
                    CurrentPage   = list.Sum(a => a.CurrentPage),
                    IsCanceled    = !list.Any(a => !a.IsCanceled),
                    IsSummary     = true
                };
                list.Add(model);
            }

            return(list);
        }
        async public void  GetItems(SearchRequestModel searchRequestModel)
        {
            IsLoading   = true;
            SearchItems = null;
            try
            {
                SearchResponseModel GetDetails = await _service.getSearchItems("abs", searchRequestModel);

                SearchItems = new ObservableCollection <SearchItemModel>(GetDetails.ReturnItems);
            }
            catch (System.OperationCanceledException ex)
            {
                Console.WriteLine($"Text load cancelled: {ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            IsLoading = false;
        }
Beispiel #14
0
        /*****
         * This is a sample method to call API and Search shipments.
         * This is just a sample and not final code.
         * ****/
        public List <ShipmentModel> SearchShipment()
        {
            System.Diagnostics.Debug.WriteLine("===========SearchShipment Inside==========");
            SearchRequestModel srm = new SearchRequestModel();

            srm.metroId    = 12;
            srm.shipmentNo = 3333;
            srm.custmerId  = 1234;
            string apiResp = CallApi(srm, "Shipment", "SearchShipment").Result;

            System.Diagnostics.Debug.WriteLine("Call API Complete");
            if (apiResp != null)
            {
                SearchResponseModel resp = JsonConvert.DeserializeObject <SearchResponseModel>(apiResp);
                return(resp.listObjects);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// To Call Get Searches Api..
        /// </summary>
        /// <param name="request"></param>
        /// <param name="success"></param>
        /// <param name="failed"></param>
        /// <returns></returns>
        public async Task <SearchResponseModel> SearchesApi(ProfileRequestModel request, Action <object> success, Action <object> failed)
        {
            SearchResponseModel resmodel = new SearchResponseModel();

            try
            {
                var    url        = string.Format("{0}/api/appconnect/Searches", WebServiceDetails.BasUri);
                string randomGuid = Guid.NewGuid().ToString();
                var    dic        = new Dictionary <string, string>();
                dic.Add("randomguid", randomGuid);
                dic.Add("hash", randomGuid + WebServiceDetails.AppKey + request.profiletoken + Helpers.LocalStorage.GeneralSecretkey);

                var result = await _apiProvider.Post <SearchResponseModel, ProfileRequestModel>(url, request, dic);

                var response = result.RawResult;
                Helpers.LocalStorage.GeneralSearches = result.RawResult;
                resmodel = JsonConvert.DeserializeObject <SearchResponseModel>(response);

                if (result.IsSuccessful == true)
                {
                    if (resmodel.responsecode == 100)
                    {
                        success.Invoke(resmodel);
                    }
                    else
                    {
                        failed.Invoke(resmodel);
                    }
                }
                else
                {
                    failed.Invoke(resmodel);
                }
            }
            catch (Exception exception)
            {
                UserDialogs.Instance.HideLoading();
            }
            return(resmodel);
        }
Beispiel #16
0
        public ActionResult Query(string value, bool skip = false)
        {
            var deviceId  = GetDeviceId();
            var accountId = GetAccountId();

            var response = new SearchResponseModel(value);

            try
            {
                response.Phrases = _phraseService.GetPhrases(value, deviceId, accountId, skip);
                response.Success = true;
            }
            catch (SoapException e)
            {
                response.SetError(e);
            }
            catch (Exception e)
            {
                response.SetError(e);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public async Task <SearchResponseModel> Process(SearchRequestModel searchRequestModel)
        {
            SearchResponseModel response = new SearchResponseModel();
            var    tasks     = new List <Task>(searchRequestModel.SearchEngines.Count());
            string positions = "0";

            foreach (var engine in searchRequestModel.SearchEngines)
            {
                _memoryCache.TryGetValue(AppHelper.GetKey(engine, searchRequestModel.Keyword, searchRequestModel.TargetUrl), out positions);
                if (!string.IsNullOrEmpty(positions))
                {
                    response.Result.Add(new SearchResult
                    {
                        Engine        = engine,
                        PagePositions = positions,
                    });
                }
                else
                {
                    tasks.Add(Task.Run(async() =>
                    {
                        var _botService = _botProvider.GetBotService(engine);
                        positions       = await _botService?.GetPositions(searchRequestModel.TargetUrl, searchRequestModel.Keyword, _settings.NoOfResultsToScan);
                        _memoryCache.Set(AppHelper.GetKey(engine, searchRequestModel.Keyword, searchRequestModel.TargetUrl), positions);
                        response.Result.Add(new SearchResult
                        {
                            Engine        = engine,
                            PagePositions = positions,
                        });
                    }));
                }
            }
            if (tasks.Any())
            {
                Task.WaitAll(tasks.ToArray());
            }
            return(response);
        }
Beispiel #18
0
        private static List <SearchResponseModel> GetMoviesRatingByUserId(long userId)
        {
            ComcastEntities            db          = new ComcastEntities();
            List <SearchResponseModel> movieRating = null;

            var result = (from movie in db.MOVIESTABLEs
                          join Rating in db.RATINGTABLEs on movie.ID equals Rating.MOVIEID
                          where Rating.CUSTOMERID.Equals(userId)
                          select new SearchResponseModel()
            {
                Id = movie.ID,
                AverageRating = Rating.RATING
            });

            if (result.Any())
            {
                movieRating = new List <SearchResponseModel>();
            }

            foreach (long id in result.Select(x => x.Id).Distinct())
            {
                if (movieRating != null && movieRating.Where(x => x.Id.Equals(id)).Any())
                {
                    continue;
                }

                var totalRows = result.Where(x => x.Id.Equals(id)).ToList().Count;

                var Rating = (result.Where(x => x.Id.Equals(id)).Sum(x => x.AverageRating) / totalRows);

                SearchResponseModel model = result.Where(x => x.Id.Equals(id)).FirstOrDefault <SearchResponseModel>();
                model.AverageRating = Math.Round(Rating * 2, MidpointRounding.AwayFromZero) / 2;

                movieRating.Add(model);
            }

            return(movieRating);
        }
Beispiel #19
0
        public async Task <SearchResponseModel> GetResultFromSearch(string messageToSearch)
        {
            SearchResponseModel searchResponse = new SearchResponseModel();

            messageToSearch = messageToSearch + " site:unex.es";

            var webData = await _webSearchClient.Web.SearchAsync(query : messageToSearch, market : "es-ES", safeSearch : "strict");

            if (webData?.WebPages?.Value?.Count > 0)
            {
                // find the first web page
                var firstWebPagesResult = webData.WebPages.Value.FirstOrDefault();

                if (firstWebPagesResult != null)
                {
                    searchResponse.Title       = firstWebPagesResult.Name;
                    searchResponse.Url         = firstWebPagesResult.Url;
                    searchResponse.Description = firstWebPagesResult.Snippet;
                }
            }

            return(searchResponse);
        }
Beispiel #20
0
        private static List <SearchResponseModel> GetGenres()
        {
            ComcastEntities            db          = new ComcastEntities();
            List <SearchResponseModel> movieGenres = null;

            var result = (from movie in db.MOVIESTABLEs
                          join mGenres in db.MOVIEGENRESTABLEs on movie.ID equals mGenres.MOVIEID
                          join genres in db.GENRESTABLEs on mGenres.GENRESID equals genres.ID
                          select new SearchResponseModel()
            {
                Id = movie.ID,
                Genres = genres.GENRES
            });


            if (result.Any())
            {
                movieGenres = new List <SearchResponseModel>();
            }

            foreach (long id in result.Select(x => x.Id).Distinct())
            {
                if (movieGenres != null && movieGenres.Where(x => x.Id.Equals(id)).Any())
                {
                    continue;
                }

                var genres = string.Join(",", result.Where(x => x.Id.Equals(id)).Select(x => x.Genres).ToList());

                SearchResponseModel model = result.Where(x => x.Id.Equals(id)).FirstOrDefault <SearchResponseModel>();
                model.Genres = genres;

                movieGenres.Add(model);
            }

            return(movieGenres);
        }
Beispiel #21
0
        public ResponseModel Get(RequestModel model)
        {
            SearchResponseModel retData = new SearchResponseModel();

            try
            {
                SearchQuery search = JsonConvert.DeserializeObject <SearchQuery>("" + model.Id + "");
                if (search == null)
                {
                    search.Query = "";
                }
                if (search.Query.Length > 2)
                {
                    using (var client = new HttpClient())
                    {
                        var responseTask = client.GetAsync("https://api.chucknorris.io/jokes/search?query=" + search.Query);
                        responseTask.Wait();

                        var result = responseTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var data = JsonConvert.DeserializeObject <JokeSearchModel>(result.Content.ReadAsStringAsync().Result);
                            retData.CnJokes = new ResponseModel()
                            {
                                Data    = data.Result.OrderBy(o => o.Id).Take(model.PageSize).Skip((model.Page - 1) * model.PageSize).ToList(),
                                Message = "Success",
                                Status  = (int)result.StatusCode,
                                Total   = data.Total
                            };
                        }
                        else
                        {
                            retData.CnJokes = new ResponseModel()
                            {
                                Message = "Failed",
                                Status  = (int)result.StatusCode,
                                Total   = 0
                            };
                        }
                    }
                }
                else
                {
                    retData.CnJokes = new ResponseModel()
                    {
                        Message = "Search query must be at least be 3 characters",
                        Status  = 400,
                        Total   = 0
                    };
                }
                using (var client = new HttpClient())
                {
                    var responseTask = client.GetAsync("https://swapi.dev/api/people/?search=" + search.Query);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var data = JsonConvert.DeserializeObject <SwapiModel>(result.Content.ReadAsStringAsync().Result);
                        retData.SwPeople = new ResponseModel()
                        {
                            Data    = data.Results,
                            Message = "Success",
                            Status  = (int)result.StatusCode,
                            Total   = data.Count
                        };
                    }
                    else
                    {
                        retData.SwPeople = new ResponseModel()
                        {
                            Message = "Failed",
                            Status  = (int)result.StatusCode,
                            Total   = 0
                        };
                    }
                }
            }
            catch (Exception error)
            {
                return(new ResponseModel()
                {
                    Status = 500,
                    Message = error.Message,
                    Data = error.StackTrace
                });
            }
            return(new ResponseModel()
            {
                Data = retData,
                Message = "Success",
                Status = 200
            });
        }
Beispiel #22
0
        public static List <SearchResponseModel> GetSearchResult(string searchText)
        {
            ComcastEntities            db       = new ComcastEntities();
            List <SearchResponseModel> response = null;
            //  db.Database.Connection.Open();
            var result = (from movies in db.MOVIESTABLEs
                          join movieGenres in db.MOVIEGENRESTABLEs on movies.ID equals movieGenres.MOVIEID
                          join genres in db.GENRESTABLEs on movieGenres.GENRESID equals genres.ID

                          where (string.IsNullOrEmpty(searchText) || movies.TITLE.Contains(searchText) ||
                                 movies.YEAROFRELEASE.ToString().Contains(searchText) ||
                                 genres.GENRES.Contains(searchText))

                          select new SearchResponseModel()
            {
                Id = movies.ID,
                Title = movies.TITLE,
                Genres = genres.GENRES,
                RunningTime = movies.RUNNINGTIME,
                YearOfRelease = movies.YEAROFRELEASE
            });

            if (result.Any())
            {
                response = new List <SearchResponseModel>();
            }
            else
            {
                return(response);
            }

            List <SearchResponseModel> lstMovieRating = GetMoviesRating();
            List <SearchResponseModel> lstMovieGenres = GetGenres();

            foreach (long id in result.Select(x => x.Id).Distinct())
            {
                if (response != null)
                {
                    if (response.Where(x => x.Id.Equals(id)).Any())
                    {
                        continue;
                    }
                }

                SearchResponseModel model = result.Where(x => x.Id.Equals(id)).FirstOrDefault <SearchResponseModel>();

                if (lstMovieRating != null)
                {
                    if (lstMovieRating.Where(x => x.Id.Equals(model.Id)).Any())
                    {
                        model.AverageRating = lstMovieRating.Where(x => x.Id.Equals(model.Id)).FirstOrDefault <SearchResponseModel>().AverageRating;
                    }
                }

                if (lstMovieGenres != null)
                {
                    if (lstMovieGenres.Where(x => x.Id.Equals(model.Id)).Any())
                    {
                        model.Genres = lstMovieGenres.Where(x => x.Id.Equals(model.Id)).FirstOrDefault <SearchResponseModel>().Genres;
                    }
                }

                response.Add(model);
            }

            return(response);
        }
Beispiel #23
0
        public static List <SearchResponseModel> GetTop5MoviesByUserRating(long userId)
        {
            ComcastEntities            db       = new ComcastEntities();
            List <SearchResponseModel> response = null;

            var result = (from movies in db.MOVIESTABLEs
                          join ra in db.RATINGTABLEs on movies.ID equals ra.MOVIEID
                          join movieGenres in db.MOVIEGENRESTABLEs on movies.ID equals movieGenres.MOVIEID
                          join genres in db.GENRESTABLEs on movieGenres.GENRESID equals genres.ID

                          where ra.CUSTOMERID.Equals(userId)

                          select new SearchResponseModel()
            {
                Id = movies.ID,
                Title = movies.TITLE,
                Genres = genres.GENRES,
                RunningTime = movies.RUNNINGTIME,
                YearOfRelease = movies.YEAROFRELEASE
            });

            if (result.Any())
            {
                response = new List <SearchResponseModel>();
            }
            else
            {
                return(response);
            }

            List <SearchResponseModel> lstMovieRating = GetMoviesRatingByUserId(userId);
            List <SearchResponseModel> lstMovieGenres = GetGenres();

            foreach (long id in result.Select(x => x.Id).Distinct())
            {
                if (response != null)
                {
                    if (response.Where(x => x.Id.Equals(id)).Any())
                    {
                        continue;
                    }
                }

                SearchResponseModel model = result.Where(x => x.Id.Equals(id)).FirstOrDefault <SearchResponseModel>();

                if (lstMovieRating != null)
                {
                    if (lstMovieRating.Where(x => x.Id.Equals(model.Id)).Any())
                    {
                        model.AverageRating = lstMovieRating.Where(x => x.Id.Equals(model.Id)).FirstOrDefault <SearchResponseModel>().AverageRating;
                    }
                }

                if (lstMovieGenres != null)
                {
                    if (lstMovieGenres.Where(x => x.Id.Equals(model.Id)).Any())
                    {
                        model.Genres = lstMovieGenres.Where(x => x.Id.Equals(model.Id)).FirstOrDefault <SearchResponseModel>().Genres;
                    }
                }

                response.Add(model);
            }

            return(response);
        }