public ActionResult Index(ActionPlanIndexViewModel model)
        {
            var result = _searchActionPlanViewModelFactory
                .WithAllowedSiteIds(CurrentUser.GetSitesFilter())
                .WithCompanyId(CurrentUser.CompanyId)
                .WithSiteGroupId(model.SiteGroupId)
                .WithSiteId(model.SiteId)
                .WithSubmittedFrom(model.SubmittedFrom)
                .WithSubmittedTo(model.SubmittedTo)
                .WithAllowedSiteIds(CurrentUser.GetSitesFilter())
                .WithPageNumber(model.Page)
                .WithPageSize(model.Size)
                .WithShowArchived(model.IsShowArchived)
                .WithOrderBy(model.OrderBy)
                .GetViewModel();

            return View(result);
        }
        public ActionPlanIndexViewModel GetViewModel()
        {

            var request = new SearchActionPlanRequest
            {
                CompanyId = _companyId,
                SiteId = _siteId,
                SiteGroupId = _siteGroupId,
                SubmittedFrom = string.IsNullOrEmpty(_submittedFrom) ? (DateTime?)null : DateTime.Parse(_submittedFrom),
                SubmittedTo = string.IsNullOrEmpty(_submittedTo) ? (DateTime?)null : DateTime.Parse(_submittedTo),
                Page = _page != default(int) ? _page : 1,
                PageSize = _size != default(int) ? _size : 10,
                OrderBy = string.IsNullOrEmpty(_orderBy) ? ActionPlanOrderByColumn.SubmittedOn : GetOrderBy(),
                Ascending = !string.IsNullOrEmpty(_orderBy) && Ascending(),
                ShowArchived = _showArchived,
                AllowedSiteIds = _allowedSiteIds
            };
            
            var count = _actionPlanService.Count(request);
            var actionPlans = _actionPlanService.Search(request);

            var viewModel = new ActionPlanIndexViewModel()
                                {
                                    Size = _size != default(int) ? _size : 10,
                                    Total = count,
                                    IsShowArchived = _showArchived
                                };

            var siteGroups = _siteGroupService.GetByCompanyId(_companyId);

            var sites = _siteService.Search(new SearchSitesRequest
            {
                CompanyId = _companyId,
                AllowedSiteIds = _allowedSiteIds
            });

            viewModel.Sites = sites.Select(AutoCompleteViewModel.ForSite).AddDefaultOption().ToList();
            viewModel.SiteGroups = siteGroups.Select(AutoCompleteViewModel.ForSiteGroup).AddDefaultOption().ToList();
            
            viewModel.ActionPlans = actionPlans.Select(x=> new SearchActionPlanResultViewModel()
            {
                Id = x.Id,
                Title = x.Title,
                Site = (x.Site != null) ? x.Site.Name : null,
                VisitDate = x.DateOfVisit,
                VisitBy = x.VisitBy,
                SubmittedDate = x.SubmittedOn,
                Status = x.Status == DerivedTaskStatusForDisplay.NoLongerRequired ? "Archived" : EnumHelper.GetEnumDescription(x.Status),
                EvaluationReportId = x.ExecutiveSummaryDocumentLibraryId
            });
            return viewModel;
        }