public ActionResult Index()
 {
     var searchModel = new SearchModel();
     var actionTypes = Enum.GetValues(typeof(SearchTypeEnum))
                                                .Cast<SearchTypeEnum>();
     searchModel.Type = from action in actionTypes
                        select new SelectListItem
                        {
                            Text = action.ToString(),
                            Value = ((int)action).ToString()
                        };
     return PartialView("Advanced", searchModel);
 }
        public ActionResult ShowSearchResult(FormCollection formCollection)
        {
            var submit = formCollection.Get(string.IsNullOrEmpty(formCollection.Get("submit")) ? "search_param" : "submit");
            var searchInput = formCollection.Get("searchInput");
            var currentPage = Convert.ToInt16(formCollection.Get("hdnCurrentPage"));
            var previousPage = Convert.ToInt16(formCollection.Get("hdnPreviousPage"));
            var previous = formCollection.Get("previous");
            int totalRecords;
            var recordsPerPage = Convert.ToInt16(formCollection.Get("hdnRecordsPerPage"));
            var typeId = 0;

            switch (submit.ToUpper())
            {
                case "EVERYWHERE":
                    typeId = 2;
                    break;
                case "DIRECTORY":
                    typeId = 3;
                    break;
                case "DOCUMENTS":
                    typeId = 1;
                    break;
            }

            var output = LegacySearchService.GetSearchResult(searchInput + "*", typeId, string.IsNullOrEmpty(previous) ? currentPage : previousPage, out totalRecords, recordsPerPage);
            var model = new SearchModel
                        {
                            Children = CreateSearchList(output, searchInput, totalRecords, "false"),
                            TotalRecords = totalRecords,
                            TotalPages =
                                (int)
                                Math.Ceiling(totalRecords / (double)ApplicationConfiguration.RecordsPerPage),
                            SearchInput = searchInput,
                            SearchType = submit
                        };

            var pageList = new List<PageList>();
            for (var i = 1; i <= model.TotalPages; i++)
            {
                pageList.Add(new PageList { Id = i, Name = Convert.ToString(i) });
            }

            if (output.Count > 0)
                model.Children[0].AllPages = pageList;

            ViewBag.ShowResult = model.Children.Count <= 0 ? @" for <span style='background-color: yellow'>""\" + searchInput + "\"</span>: 0 items" : "";
            ViewBag.ResultCount = @" for <span style='background-color: yellow'>""\" + searchInput + "\"</span> ";
            return View("SearchResult", model);
        }
        public ActionResult PeopleSearch()
        {
            var searchInput = Request.QueryString[0];
            const int currentPage = 1;
            const int previousPage = 0;
            var previous = string.Empty;
            int totalRecords;
            const int recordsPerPage = 20;

            var output = LegacySearchService.GetSearchResult(searchInput + "*", 3, string.IsNullOrEmpty(previous) ? currentPage : previousPage, out totalRecords, recordsPerPage);
            
            var model = new SearchModel
                        {
                            Children = CreateSearchList(output, searchInput, totalRecords, "false"),
                            TotalRecords = totalRecords,
                            TotalPages =
                                (int)
                                Math.Ceiling(totalRecords / (double)ApplicationConfiguration.RecordsPerPage)
                        };
            
            return PartialView("_PeopleSearchResults", model);
        }
        public ActionResult SearchPaging(FormCollection formCollection)
        {
            var submit = formCollection.Get(string.IsNullOrEmpty(formCollection.Get("TypeId")) ? "search_param" : "submit");
            var searchInput = formCollection.Get("searchInput");
            var isAdvance = formCollection.Get("hdnIsAdvance");
            var previous = formCollection.Get("previous");
            var first = formCollection.Get("first");
            var last = formCollection.Get("last");
            var next = formCollection.Get("next");
            var pageNumber = Convert.ToInt16(formCollection.Get("firstRecordDefault.CurrentPage"));
            var totalPages = Convert.ToInt16(formCollection.Get("TotalPages"));
            int totalRecords;
            var recordsPerPage = Convert.ToInt16(formCollection.Get("hdnRecordsPerPage"));
            var typeId = 0;
            switch (submit.ToUpper())
            {
                case "EVERYWHERE":
                    typeId = 2;
                    break;
                case "DIRECTORY":
                    typeId = 3;
                    break;
                case "DOCUMENTS":
                    typeId = 1;
                    break;
            }

            int currentPageSelected = 0;
            if (!string.IsNullOrEmpty(next))
                currentPageSelected = pageNumber + 1;
            else if (!string.IsNullOrEmpty(previous))
                currentPageSelected = pageNumber - 1;
            else if (!string.IsNullOrEmpty(first))
                currentPageSelected = 1;
            else if (!string.IsNullOrEmpty(last))
                currentPageSelected = totalPages;
            else
                currentPageSelected = pageNumber;

            var output = LegacySearchService.GetSearchResult(Convert.ToBoolean(isAdvance) ? searchInput : searchInput + "*", typeId, currentPageSelected, out totalRecords, recordsPerPage);

            var model = new SearchModel
                        {
                            Children = CreateSearchList(output, searchInput, totalRecords, isAdvance),
                            TotalRecords = totalRecords,
                            TotalPages =
                                (int)
                                Math.Ceiling(totalRecords / (double)ApplicationConfiguration.RecordsPerPage),
                            SearchInput = Convert.ToBoolean(isAdvance) ? string.Empty : searchInput,
                            SearchType = submit
                        };

            var pageList = new List<PageList>();
            for (var i = 1; i <= model.TotalPages; i++)
            {
                pageList.Add(new PageList { Id = i, Name = Convert.ToString(i) });
            }

            if (output.Count > 0)
                model.Children[0].AllPages = pageList;

            ViewBag.ShowResult = model.Children.Count <= 0 ? @"Search Results for <span style='background-color: yellow'>""\" + searchInput + "\"</span>: 0 items" : "";
            ViewBag.ResultCount = @"Search Results for <span style='background-color: yellow'>""\" + searchInput + "\"</span> ";
            if (isAdvance == "true")
            {
                model.AllOfTheseWords = formCollection.Get("AllOfTheseWords");
                model.ExactPhrase = formCollection.Get("ExactPhrase");
                model.AnyOfTheseWords = formCollection.Get("AnyOfTheseWords");
                model.NoneOfTheseWords = formCollection.Get("NoneOfTheseWords");
                model.LastName = formCollection.Get("LastName");
                model.FirstName = formCollection.Get("FirstName");
                model.JobTitle = formCollection.Get("JobTitle");
                model.Keywords = formCollection.Get("Keywords");
                var actionTypes = Enum.GetValues(typeof(SearchTypeEnum))
                                                       .Cast<SearchTypeEnum>();
                model.Type = from action in actionTypes
                             select new SelectListItem
                             {
                                 Text = action.ToString(),
                                 Value = ((int)action).ToString(CultureInfo.InvariantCulture)
                             };
                model.TypeId = typeId;
                return View("Advanced", model);
            }
            else
                return View("SearchResult", model);
        }
        public ActionResult SearchAdvanced(SearchModel searchModel)
        {
            int totalRecords;
            var searchString = string.Empty;
            if (searchModel.TypeId == 3)
            {
                if (!string.IsNullOrEmpty(searchModel.LastName))
                    searchString = searchString + @"LastName:""\" + searchModel.LastName + "\"";
                if (!string.IsNullOrEmpty(searchModel.FirstName))
                    searchString = searchString + @" FirstName:""\" + searchModel.FirstName + "\"";
                if (!string.IsNullOrEmpty(searchModel.JobTitle))
                    searchString = searchString + @" JobTitle:""\" + searchModel.JobTitle + "\"";
                if (!string.IsNullOrEmpty(searchModel.Keywords))
                {
                    searchString = searchString + " (";
                    searchString = searchString + @"Responsibility:""\" + searchModel.Keywords + "\"";
                    searchString = searchString + @" OR Skills:""\" + searchModel.Keywords + "\"";
                    searchString = searchString + @" OR Interests:""\" + searchModel.Keywords + "\"";
                    searchString = searchString + ")";
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(searchModel.AllOfTheseWords))
                    searchString = searchString + @"ALL(" + searchModel.AllOfTheseWords + ")";
                if (!string.IsNullOrEmpty(searchModel.ExactPhrase))
                    searchString = searchString + @" ""\" + searchModel.ExactPhrase + "\" ";
                if (!string.IsNullOrEmpty(searchModel.AnyOfTheseWords))
                    searchString = searchString + @" ANY(" + searchModel.AnyOfTheseWords + ")";
                if (!string.IsNullOrEmpty(searchModel.NoneOfTheseWords))
                {
                    searchString = searchString + @" NONE(" + searchModel.NoneOfTheseWords + ")";
                }
            }

            var output = LegacySearchService.GetSearchResult(searchString, searchModel.TypeId, 1, out totalRecords, Convert.ToInt16(ApplicationConfiguration.RecordsPerPage));
            if (output.Count > 0)
            {
                output[0].AllOfTheseWords = searchModel.AllOfTheseWords;
                output[0].ExactPhrase = searchModel.ExactPhrase;
                output[0].AnyOfTheseWords = searchModel.AnyOfTheseWords;
                output[0].NoneOfTheseWords = searchModel.NoneOfTheseWords;
                output[0].LastName = searchModel.LastName;
                output[0].FirstName = searchModel.FirstName;
                output[0].JobTitle = searchModel.JobTitle;
                output[0].Keywords = searchModel.Keywords;
            }

            var actionTypes = Enum.GetValues(typeof(SearchTypeEnum))
                                                       .Cast<SearchTypeEnum>();
            searchModel.Type = from action in actionTypes
                               select new SelectListItem
                               {
                                   Text = action.ToString(),
                                   Value = ((int)action).ToString(CultureInfo.InvariantCulture)
                               };
            searchModel.SearchType = "Advanced";
            searchModel.Children = CreateSearchList(output, searchString, totalRecords, "true");
            searchModel.TotalRecords = totalRecords;
            searchModel.TotalPages = (int)Math.Ceiling(totalRecords / (double)ApplicationConfiguration.RecordsPerPage);

            var pageList = new List<PageList>();
            for (var i = 1; i <= searchModel.TotalPages; i++)
            {
                pageList.Add(new PageList { Id = i, Name = Convert.ToString(i) });
            }

            if (output.Count > 0)
                searchModel.Children[0].AllPages = pageList;

            ViewBag.ShowResult = searchModel.Children.Count <= 0 ? " for <span style='background-color: yellow'>" + searchString + "</span>: 0 items" : "";
            ViewBag.ResultCount = @" for <span style='background-color: yellow'>""\" + searchString + "\"</span> ";

            return View("Advanced", searchModel);
        }
        public ActionResult Advanced(string searchType)
        {
            var searchModel = new SearchModel();
            if (string.IsNullOrEmpty(searchType))
            {
                searchType = "Everywhere";
            }
            if (searchType.ToUpper() == "EVERYWHERE")
            {
                searchModel.SearchType = "Everywhere";
            }
            else if (searchType.ToUpper() == "DIRECTORY")
            {
                searchModel.SearchType = "Directory";
            }
            else if (searchType.ToUpper() == "DOCUMENTS")
            {
                searchModel.SearchType = "Documents";
            }

            var actionTypes = Enum.GetValues(typeof(SearchTypeEnum))
                                                       .Cast<SearchTypeEnum>();

            searchModel.Type = from action in actionTypes
                               select new SelectListItem
                               {
                                   Text = action.ToString(),
                                   Value = ((int)action).ToString()
                               };
            searchModel.TypeId = (int)Enum.Parse(typeof(SearchTypeEnum), searchType);
            return View(searchModel);
        }