/// <summary>
        /// Prepares the person search result.
        /// </summary>
        /// <param name="searchFor">The search for.</param>
        /// <param name="isAll">The is all.</param>
        /// <param name="searchPresenter">The search presenter.</param>
        /// <param name="searchFilter">The search filter.</param>
        /// <returns>The Task.</returns>
        private async Task PreparePersonSearchResult(string searchFor, bool? isAll, GlobalSearchPresenter searchPresenter, SearchFilters searchFilter)
        {
            var personSearchResult = await this.personManager.GetPersonsAsync(searchFilter, searchPresenter.AuthenticationToken);
            searchPresenter.GuestTotalResults = personSearchResult.GuestTotalResults;
            searchPresenter.CrewTotalResults = personSearchResult.CrewTotalResults;
            searchPresenter.VisitorTotalResults = personSearchResult.VisitorTotalResults;

            SessionData.Instance.PersonItemListResult.Clear();
            SessionData.Instance.AssignPersonSearchResult(personSearchResult.Items.ToList());

            searchPresenter.IsAll = isAll;
            if (!string.IsNullOrEmpty(searchFor))
            {
                if (!searchFor.Equals(AllConstant, StringComparison.OrdinalIgnoreCase))
                {
                    searchPresenter.SelectedPersonType = searchFor;
                    searchPresenter.SelectedOptionType = searchFor;
                }
                else if (string.IsNullOrEmpty(searchPresenter.SelectedPersonType) && searchFor.Equals(AllConstant, StringComparison.OrdinalIgnoreCase))
                {
                    searchPresenter.SelectedOptionType = searchPresenter.GuestTotalResults > 0 ? GuestConstant : searchPresenter.CrewTotalResults > 0 ? CrewConstant : searchPresenter.VisitorTotalResults > 0 ? VisitorConstant : string.Empty;
                }
            }

            if (personSearchResult.Items.Count > 0)
            {
                searchPresenter.AssignPersonSearchResult(personSearchResult);
            }
        }
        /// <summary>
        /// Paging the specified alert presenter.
        /// </summary>
        /// <param name="searchPresenter">The alert presenter.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="searchText">The search text.</param>
        /// <param name="searchType">Type of the search.</param>
        /// <param name="searchFor">The search for.</param>
        /// <param name="isAll">The is all.</param>
        /// <returns>
        /// The Action Result.
        /// </returns>
        public async Task<ActionResult> Paging(GlobalSearchPresenter searchPresenter, string pageNumber, string searchText, string searchType, string searchFor, bool? isAll)
        {
            if (searchPresenter != null && !string.IsNullOrEmpty(pageNumber) && !pageNumber.Equals(UndefinedConstant) && !string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(searchType))
            {
                var pagingPageNumber = Convert.ToInt32(pageNumber) > 0 ? Convert.ToInt32(pageNumber) / ApplicationSettings.MaxPageSize : 1;
                var searchFilter = string.IsNullOrEmpty(searchType) ? new SearchFilters() : new SearchFilters { IsAlertCount = true, IsMessageCount = true, IsAll = isAll };
                searchFilter = this.SetSearchFilters(searchFilter, searchType, searchText, searchFor, Convert.ToInt32(pagingPageNumber, CultureInfo.InvariantCulture));

                if (searchType.Equals(Birthdate, StringComparison.InvariantCultureIgnoreCase) && searchFilter.PersonTypeId != null && (searchFilter.PersonTypeId.Equals(GuestPersonTypeId, StringComparison.OrdinalIgnoreCase) || searchFilter.PersonTypeId.Equals(CrewPersonTypeId, StringComparison.OrdinalIgnoreCase)))
                {
                    return this.View(new GlobalSearchPresenter());
                }

                await this.PreparePersonSearchResult(searchFor, isAll, searchPresenter, searchFilter);
            }

            return this.PartialView(PagingPartialView, searchPresenter);
        }
        /// <summary>
        /// Indexes the specified search term.
        /// </summary>
        /// <param name="searchText">The search text.</param>
        /// <param name="searchType">Type of the search.</param>
        /// <param name="searchFor">The search for.</param>
        /// <param name="isAll">The is all.</param>
        /// <returns>
        /// View as per action result
        /// </returns>
        public async Task<ActionResult> Index(string searchText, string searchType, string searchFor, bool? isAll)
        {
            var searchPresenter = new GlobalSearchPresenter();
            
            if (string.IsNullOrEmpty(searchType))
            {
                searchType = LastName;
            }

            if (!string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(searchType))
            {
                var searchFilter = string.IsNullOrEmpty(searchType) ? new SearchFilters() : new SearchFilters { IsAlertCount = true, IsMessageCount = true, IsAll = isAll };
                searchFilter = this.SetSearchFilters(searchFilter, searchType, searchText, searchFor, 1);
                if (searchType.Equals(Birthdate, StringComparison.InvariantCultureIgnoreCase) && searchFilter.PersonTypeId != null && (searchFilter.PersonTypeId.Equals(GuestPersonTypeId, StringComparison.OrdinalIgnoreCase) || searchFilter.PersonTypeId.Equals(CrewPersonTypeId, StringComparison.OrdinalIgnoreCase)))
                {
                    return this.View(new GlobalSearchPresenter());
                }

                if (!string.IsNullOrEmpty(searchFor))
                {
                    SessionData.Instance.PersonType = searchFor;
                }

                await this.PreparePersonSearchResult(searchFor, isAll, searchPresenter, searchFilter);

                SessionData.Instance.IsMessageMode = string.Empty;

                SessionData.Instance.AlertData = null;
                SessionData.Instance.GlobalAlertPersonList.Clear();
                SessionData.Instance.GlobalMessagePersonList.Clear();
                SessionData.Instance.SelectedPersonIds.Clear();
                SessionData.Instance.FilterPersonList.Clear();
            }

            return this.View(searchPresenter);
        }
 /// <summary>
 /// Assigns the search result.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 /// <param name="projectList">The project list.</param>
 /// <param name="developerList">The developer list.</param>
 /// <param name="taskList">The task list.</param>
 private static void AssignSearchResult(GlobalSearchPresenter presenter, IList<ProjectListItem> projectList, IList<DeveloperListItem> developerList, IList<TaskResult> taskList)
 {
     IList<SearchResultItem> searchResultToDisplay = new List<SearchResultItem>();
     var filteredProjectsList = MapProjectToSearchResults(projectList);
     var filteredDevelopersList = MapDeveloperToSearchResult(developerList);
     var filteredTaskList = MapTaskToSearchResults(taskList);
     var searchResult = filteredProjectsList.Concat(filteredDevelopersList).Concat(filteredTaskList).ToList();
     presenter.AssignAllSearchRecordList(searchResult);
     searchResultToDisplay = searchResult.Take(InitialNumberOfRecords).ToList<SearchResultItem>();
     presenter.AssignSearchResultList(searchResultToDisplay);
     presenter.RecordCount = presenter.AllSearchRecordList.Count < InitialNumberOfRecords ? presenter.AllSearchRecordList.Count : InitialNumberOfRecords;
 }
        /// <summary>
        /// Function to get more search records.
        /// </summary>
        /// <param name="presenter">The presenter</param>
        /// <param name="numberOfRecords">The number of records.</param>
        /// <param name="searchText">The search text.</param>
        /// <returns>
        /// The partial view
        /// </returns>
        public ActionResult ShowMoreRecords(GlobalSearchPresenter presenter, int numberOfRecords, string searchText)
        {
            if (presenter != null)
            {
                IList<SearchResultItem> searchResult = new List<SearchResultItem>();
                if (SessionData.Instance.GlobalSearchItems != null)
                {
                    IList<SearchResultItem> searchRecordList = new List<SearchResultItem>();
                    searchRecordList = SessionData.Instance.GlobalSearchItems;
                    presenter.AssignAllSearchRecordList(searchRecordList);
                    int totalCount = presenter.RecordCount + numberOfRecords;
                    presenter.RecordCount = totalCount < searchRecordList.Count ? totalCount : searchRecordList.Count;
                    searchResult = searchRecordList.Take(presenter.RecordCount).ToList<SearchResultItem>();
                    presenter.AssignSearchResultList(searchResult);
                }
            }

            return this.PartialView(SearchRecordsPartialView, presenter);
        }
        /// <summary>
        /// Function to retrieve index page.
        /// </summary>
        /// <param name="searchText">search text</param>
        /// <returns>Index page</returns>
        public ActionResult Index(string searchText)
        {
            if (string.IsNullOrWhiteSpace(searchText))
            {
                var result = this.RetrieveSearchResultList();
                return new JsonResult { Data = result.Select(l => l.Name) };
            }
            else
            {
                GlobalSearchPresenter presenter = new GlobalSearchPresenter();
                searchText = System.Web.HttpUtility.HtmlDecode(searchText);
                presenter.GlobalSearch = searchText;
                var projectList = this.projectService.RetrieveList(searchText, null, null, null, SessionData.Instance.UserInfo.Developer.DeveloperID);
                var developerList = this.developerService.RetrieveListByDeveloperName(searchText, SessionData.Instance.UserInfo.Developer.DeveloperID);

                int taskId;
                string searchTaskTitle = null;
                int? searchTaskId = null;
                int.TryParse(searchText, out taskId);

                if (taskId == Zero)
                {
                    searchTaskId = null;
                    searchTaskTitle = searchText;
                }
                else
                {
                    searchTaskId = taskId;
                    searchTaskTitle = null;
                }

                var taskList = this.taskService.SearchTask(searchTaskId, searchTaskTitle, SessionData.Instance.UserInfo.Developer.DeveloperID);
                var userId = SessionData.Instance.UserInfo.Developer.DeveloperID;
                var taskFirst = taskList.FirstOrDefault();
                var count = projectList.Count + developerList.Count + taskList.Count;
                if (count > MaximumCount)
                {
                    AssignSearchResult(presenter, projectList, developerList, taskList);
                    SessionData.Instance.GlobalSearchItems = presenter.AllSearchRecordList;
                    return this.View(presenter);
                }
                else if (taskList.Count == MaximumCount && SessionData.Instance.UserInfo.Developer.UserType == UserType.Admin)
                {
                    var taskDetailUrl = string.Format(CultureInfo.CurrentCulture, TaskUrlFormat, Url.TaskDetailsAction(), string.Format(CultureInfo.CurrentCulture, TaskUrl, taskList.FirstOrDefault().TaskID), string.Format(CultureInfo.CurrentCulture, TaskDeveloperUrl, taskList.FirstOrDefault().AssignedToDeveloperID));
                    return this.Redirect(taskDetailUrl);
                }
                else if (taskList.Count == MaximumCount && SessionData.Instance.UserInfo.Developer.UserType == UserType.Normal && (taskFirst.AssignedToDeveloperID == userId || taskFirst.CreatedBy == userId || taskFirst.AccessFlag == 1))
                {
                    var taskDetailUrl = string.Format(CultureInfo.CurrentCulture, TaskUrlFormat, Url.TaskDetailsAction(), string.Format(CultureInfo.CurrentCulture, TaskUrl, taskList.FirstOrDefault().TaskID), string.Format(CultureInfo.CurrentCulture, TaskDeveloperUrl, taskList.FirstOrDefault().AssignedToDeveloperID));
                    return this.Redirect(taskDetailUrl);
                }
                else if (projectList.Count == MaximumCount && SessionData.Instance.UserInfo.Developer.UserType == UserType.Admin)
                {
                    var projectDashboardUrl = string.Format(CultureInfo.CurrentCulture, CommonUrlFormat, Url.ProjectDashboardAction(), string.Format(CultureInfo.CurrentCulture, ViewProjectUrl, projectList.FirstOrDefault().ProjectID));
                    return this.Redirect(projectDashboardUrl);
                }
                else if (developerList.Count == MaximumCount && SessionData.Instance.UserInfo.Developer.UserType == UserType.Admin)
                {
                    var teamDashboardUrl = string.Format(CultureInfo.CurrentCulture, CommonUrlFormat, Url.TeamDashboardAction(), string.Format(CultureInfo.CurrentCulture, TeamDashboardUrl, developerList.FirstOrDefault().DeveloperID));
                    return this.Redirect(teamDashboardUrl);
                }
                else if ((projectList.Count == MaximumCount || developerList.Count == MaximumCount || taskList.Count == MaximumCount) && SessionData.Instance.UserInfo.Developer.UserType == UserType.Normal)
                {
                    AssignSearchResult(presenter, projectList, developerList, taskList);
                    SessionData.Instance.GlobalSearchItems = presenter.AllSearchRecordList;
                    return this.View(presenter);
                }

                return this.View(presenter);
            }
        }