public void When_Search_Then_map_request_to_repository_call()
        {
            //given
            var target = GetTarget();
            var companyId = 1233L;
            var page = 1;
            var pageSize = 10;
            var orderyBy = ActionPlanOrderByColumn.Title;

            var request = new SearchActionPlanRequest
                              {
                                  CompanyId = companyId,
                                  Page = page,
                                  PageSize = pageSize,
                                  OrderBy = orderyBy,
                                  Ascending = true
                              };
            //when
            target.Search(request);
            //then
            _actionPlanRepository.Verify(x=>x.Search(null, It.Is<long>(c=>c ==companyId), null, null, null, null, false, 
                It.Is<int>(pg=>pg == page),
                It.Is<int>(pgz=>pgz == pageSize),
                It.Is<ActionPlanOrderByColumn>(o=> o == orderyBy),
                It.Is<bool>(asc=>asc)));
        }
 public IEnumerable<ActionPlanDto> Search(SearchActionPlanRequest request)
 {
     var actionPlans = _actionPlanRepository.Search(request.AllowedSiteIds, request.CompanyId, 
                                                    request.SiteGroupId, request.SiteId, request.SubmittedFrom,
                                                    request.SubmittedTo, request.ShowArchived,
                                                    request.Page, request.PageSize, request.OrderBy, 
                                                    request.Ascending);
     return new ActionPlanDtoMapper()
         .WithSites()
         .WithActions()
         .WithStatus()
         .Map(actionPlans);
 }
        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;
        }
 public int Count(SearchActionPlanRequest request)
 {
     return _actionPlanRepository.Count(request.AllowedSiteIds, request.CompanyId, request.SiteGroupId, request.SiteId, request.SubmittedFrom, request.SubmittedTo, request.ShowArchived);
 }