Exemplo n.º 1
0
        public static bool HasFilters(JobSearchResultsFilterModel filterModel)
        {
            bool hasFilters = false;

            if (filterModel.Filters != null && filterModel.Filters.Count > 0)
            {
                foreach (var filter in filterModel.Filters)
                {
                    if (filter.values != null && filter.values.Count > 0)
                    {
                        hasFilters = true;
                        break;
                    }
                }
            }
            if (filterModel != null && !hasFilters && (!filterModel.Keywords.IsNullOrEmpty() || filterModel.Salary != null))
            {
                hasFilters = true;
            }

            return(hasFilters);
        }
Exemplo n.º 2
0
        public static JXTNext_SearchJobsRequest ProcessInputToSearchRequest(JobSearchResultsFilterModel filterModel, int?pageSize, int pageSizeDefaultValue = 5)
        {
            JXTNext_SearchJobsRequest request = new JXTNext_SearchJobsRequest();

            if (filterModel != null)
            {
                if (!string.IsNullOrEmpty(filterModel.Keywords))
                {
                    request.KeywordsSearchCriteria = new List <KeywordSearch> {
                        new KeywordSearch {
                            Keyword = filterModel.Keywords
                        }
                    }
                }
                ;

                if (filterModel.ConsultantSearch != null && (!string.IsNullOrEmpty(filterModel.ConsultantSearch.Email) || !string.IsNullOrEmpty(filterModel.ConsultantSearch.FirstName) || !string.IsNullOrEmpty(filterModel.ConsultantSearch.LastName)))
                {
                    request.ConsultantSearchCriteria = new ConsultantSearch()
                    {
                        Email = filterModel.ConsultantSearch.Email, FirstName = filterModel.ConsultantSearch.FirstName, LastName = filterModel.ConsultantSearch.LastName
                    }
                }
                ;

                List <IClassificationSearch> classificationSearches = new List <IClassificationSearch>();
                bool isFiltersExists = false;
                if (filterModel.Salary != null)
                {
                    isFiltersExists = true;
                    Classification_RangeSearch cateRangeSearch = new Classification_RangeSearch()
                    {
                        ClassificationRootName = filterModel.Salary.RootName,
                        TargetValue            = filterModel.Salary.TargetValue,
                        UpperRange             = filterModel.Salary.UpperRange,
                        LowerRange             = filterModel.Salary.LowerRange
                    };
                    classificationSearches.Add(cateRangeSearch);
                }

                if (filterModel.Filters != null && filterModel.Filters.Count() > 0)
                {
                    isFiltersExists = true;
                    for (int i = 0; i < filterModel.Filters.Count(); i++)
                    {
                        var filter = filterModel.Filters[i];
                        if (filter != null && filter.values != null && filter.values.Count > 0)
                        {
                            if (filter.rootId == "CompanyName")
                            {
                                dynamic fieldSearch = new ExpandoObject();
                                fieldSearch.Status = 1;
                                if (int.TryParse(filter.values[0].ItemID, out int num))
                                {
                                    fieldSearch.CompanyId = int.Parse(filter.values[0].ItemID);
                                }
                                request.FieldSearches = fieldSearch;
                            }
                            else
                            {
                                Classification_CategorySearch cateSearch = new Classification_CategorySearch
                                {
                                    ClassificationRootName = filter.rootId,
                                    TargetClassifications  = new List <Classification_CategorySearchTarget>()
                                };

                                foreach (var filterItem in filter.values)
                                {
                                    var targetCategory = new Classification_CategorySearchTarget()
                                    {
                                        SubTargets = new List <Classification_CategorySearchTarget>()
                                    };
                                    ProcessFilterLevels(targetCategory, filterItem);
                                    cateSearch.TargetClassifications.Add(targetCategory);
                                }

                                classificationSearches.Add(cateSearch);
                            }
                        }
                    }
                }

                if (isFiltersExists)
                {
                    request.ClassificationsSearchCriteria = classificationSearches;
                }

                if (pageSize.HasValue && pageSize.Value > 0)
                {
                    request.PageSize = pageSize.Value;
                }
                else
                {
                    request.PageSize = pageSizeDefaultValue;
                }

                if (filterModel.Page <= 0)
                {
                    filterModel.Page = 1;
                }

                request.PageNumber = filterModel.Page - 1;
            }

            return(request);
        }
Exemplo n.º 3
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request  = controllerContext.HttpContext.Request;
            string          keywords = request.Params["Keywords"];

            int page = 1;

            if (request.Params["Page"] != null)
            {
                page = Int32.Parse(request.Params["Page"]);
            }

            string sortBy = request.Params["SortBy"];

            JobSearchSalaryFilterReceiver salary = null;

            if (request.Params["Salary.TargetValue"] != null && request.Params["Salary.LowerRange"] != null && request.Params["Salary.UpperRange"] != null)
            {
                string salaryTargetValue = request.Params["Salary.TargetValue"];
                int    salaryLowerRange  = 0;
                Int32.TryParse(request.Params["Salary.LowerRange"], out salaryLowerRange);
                int salaryUpperRange = 0;
                Int32.TryParse(request.Params["Salary.UpperRange"], out salaryUpperRange);
                salary = new JobSearchSalaryFilterReceiver()
                {
                    RootName = "Salary", TargetValue = salaryTargetValue, LowerRange = salaryLowerRange, UpperRange = salaryUpperRange
                };
            }

            /*
             * Input samples
             * Filters[0].rootId = 0
             * Filters[0].values = 1, 1_2, 1_2_3, 1_2_4, 1_3_18
             * Filters[1].rootId = A
             * Filters[1].values = B, B_C, B_C_D, B_C_E
             */

            Dictionary <string, FilterNode> tracker = new Dictionary <string, FilterNode>();

            List <string> filterKeys = request.QueryString.AllKeys.Where(c => c.ToUpper().Contains("FILTERS")).OrderBy(c => c).ToList();
            var           reqParams  = request.QueryString;

            if (filterKeys == null || filterKeys.Count <= 0)
            {
                filterKeys = request.Params.AllKeys.Where(c => c.ToUpper().Contains("FILTER")).OrderBy(c => c).ToList();
                reqParams  = request.Params;
            }

            foreach (string k in filterKeys)
            {
                string thisFilterKey = ExtractFilterNodeID(k);
                if (thisFilterKey != null)
                {
                    if (tracker.Keys.Contains(thisFilterKey))
                    {
                        FilterNode thisNode = tracker[thisFilterKey];
                        if (k.ToUpper().Contains("ROOTID"))
                        {
                            thisNode.RootId = reqParams[k];
                        }
                        else if (k.ToUpper().Contains("VALUES"))
                        {
                            thisNode.Values = reqParams[k].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        }
                    }
                    else
                    {
                        FilterNode newNode = new FilterNode();
                        if (k.ToUpper().Contains("ROOTID"))
                        {
                            newNode.RootId = reqParams[k];
                        }
                        else if (k.ToUpper().Contains("VALUES"))
                        {
                            newNode.Values = reqParams[k].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        }

                        tracker.Add(thisFilterKey, newNode);
                    }
                }
            }

            /*
             * Output Sample
             * tracker["Filter[0]"] = FilterNode { RootId ="0", Values = ["1","1_2","1_2_3" ]}
             * tracker["Filter[1]"] = FilterNode { RootId = "A", Values = ["B","B_C","B_C_E" ]}
             */

            //process tracker into target model
            JobSearchResultsFilterModel targetModel = new JobSearchResultsFilterModel()
            {
                Keywords = keywords, Page = page, Filters = new List <JobSearchFilterReceiver>(), Salary = salary, SortBy = sortBy
            };

            foreach (string trackerKey in tracker.Keys)
            {
                FilterNode thisFilterNode        = tracker[trackerKey];
                JobSearchFilterReceiver receiver = new JobSearchFilterReceiver {
                    rootId = thisFilterNode.RootId, values = new List <JobSearchFilterReceiverItem>()
                };
                if (thisFilterNode.Values != null && thisFilterNode.Values.Count() > 0)
                {
                    foreach (string value in thisFilterNode.Values)
                    {
                        AssignNodeRoot(receiver, value);
                    }
                }

                targetModel.Filters.Add(receiver);
            }

            return(targetModel);
        }