public IEnumerable<AccidentRecordDto> SearchWithEverthing(SearchAccidentRecordsRequest request)
        {
            var accidentRecords = _accidentRecordRepository.Search(
               request.AllowedSiteIds,
               request.CompanyId,
               request.SiteId,
               request.Title,
               request.CreatedFrom,
               request.CreatedTo,
               request.ShowDeleted,
               request.InjuredPersonForename,
               request.InjuredPersonSurname,
               request.Page,
               request.PageSize,
               AccidentRecordstOrderByColumn.None, 
               true);

            return new AccidentRecordDtoMapper().MapWithEverything(accidentRecords);
        }
        public int Count(SearchAccidentRecordsRequest request)
        {
            var count = _accidentRecordRepository.Count(
                request.AllowedSiteIds,
                request.CompanyId,
                request.SiteId,
                request.Title,
                request.CreatedFrom,
                request.CreatedTo,
                request.ShowDeleted,
                request.InjuredPersonForename,
                request.InjuredPersonSurname
                );

            return count;
        }
        public void Setup()
        {
            // set up repositiories
             _accidentRecordRepository = new Mock<IAccidentRecordRepository>();
            _jurisdictionRepository = new Mock<IJurisdictionRepository>();

            _userRepository = new Mock<IUserForAuditingRepository>();
            _user = new UserForAuditing {Id = new Guid()};
            _log = new Mock<IPeninsulaLog>();

            _userRepository
                .Setup(curUserRepository => curUserRepository.GetById(It.IsAny<Guid>()))
                .Returns(_user);

            _countriesRepository = new Mock<ICountriesRepository>();
            _employeeRepository = new Mock<IEmployeeRepository>();


            _returnedAccidentRecords = new List<BusinessSafe.Domain.Entities.AccidentRecord>()
                                           {
                                               new BusinessSafe.Domain.Entities.AccidentRecord()
                                                   {
                                                       CompanyId = 12345L,
                                                       Title = "Some Title 111",
                                                       Reference = "",

                                                       EmployeeInjured = new Employee() {EmployeeReference = "Test"},
                                                       CreatedBy = new UserForAuditing() {Id = Guid.NewGuid()},
                                                       SiteWhereHappened = new Site() {Id = 1346624L},
                                                       Jurisdiction =
                                                           new Jurisdiction {Id = 1, Name = JurisdictionNames.GB}
                                                   },

                                               new BusinessSafe.Domain.Entities.AccidentRecord()
                                                   {
                                                       CompanyId = 12345L,
                                                       Title = "Some Title 222",
                                                       Reference = "",

                                                       EmployeeInjured = new Employee() {EmployeeReference = "Test"},
                                                       CreatedBy = new UserForAuditing() {Id = Guid.NewGuid()},
                                                       SiteWhereHappened = new Site() {Id = 1346624L},
                                                       Jurisdiction =
                                                           new Jurisdiction {Id = 1, Name = JurisdictionNames.GB}
                                                   },

                                               new BusinessSafe.Domain.Entities.AccidentRecord()
                                                   {
                                                       CompanyId = 12345L,
                                                       Title = "Some Title 333",
                                                       Reference = "",

                                                       EmployeeInjured = new Employee() {EmployeeReference = "Test"},
                                                       CreatedBy = new UserForAuditing() {Id = Guid.NewGuid()},

                                                       SiteWhereHappened = new Site() {Id = 1346624L},
                                                       Jurisdiction =
                                                           new Jurisdiction {Id = 1, Name = JurisdictionNames.GB}
                                                   }
                                           };


            _accidentRecordRepository
                .Setup(x => x.Search(
                    It.IsAny<Guid>(),               // currentUserId
                    It.IsAny<IList<long>>(),        // allowedSiteIds
                    It.IsAny<long>(),               // companyId
                    It.IsAny<long?>(),              // siteId
                    It.IsAny<long?>(),              // siteGroupId                   
                    It.IsAny<string>(),             // title
                    It.IsAny<DateTime?>(),          // createdFrom
                    It.IsAny<DateTime?>(),          // createdTo
                    It.IsAny<bool>(),               // showDeleted
                    It.IsAny<string>(),             // injuredPersonForename
                    It.IsAny<string>()              // injuredPersonSurname
                ))
                .Returns(_returnedAccidentRecords);

            // set up request
            _request = new SearchAccidentRecordsRequest()
                           {
                                CompanyId = 12345L,

                                Title = "",
        
                                CreatedFrom =  DateTime.Now.AddDays(-10),
                                CreatedTo =  DateTime.Now.AddDays(-2),

                                SiteGroupId = 498L,
                                SiteId = 123L,

                                ShowDeleted  = false,
                                ShowArchived = false,

                                //IList<long> AllowedSiteIds =
                                CurrentUserId = Guid.NewGuid(), 

                                InjuredPersonForename = "",
                                InjuredPersonSurname = ""
                           };



        }
        public IEnumerable<AccidentRecordDto> Search(SearchAccidentRecordsRequest request)
        {
            var accidentRecords = _accidentRecordRepository.Search(
               request.AllowedSiteIds,
               request.CompanyId,
               request.SiteId,
               request.Title,
               request.CreatedFrom,
               request.CreatedTo,
               request.ShowDeleted,
               request.InjuredPersonForename,
               request.InjuredPersonSurname,
               request.Page,
               request.PageSize,
               request.OrderBy,
               request.Ascending
               );

            return new AccidentRecordDtoMapper().MapWithSiteAndCreatedAndEmployeeInjured(accidentRecords);
        }
        public ViewModels.AccidentRecordsIndexViewModel GetViewModel()
        {
            var request = new SearchAccidentRecordsRequest()
                              {
                                  CompanyId = _companyId,
                                  ShowDeleted = _showDeleted,
                                  SiteId = _siteId,
                                  Title = _title,
                                  CreatedFrom =
                                      string.IsNullOrEmpty(_createdFrom)
                                          ? (DateTime?) null
                                          : DateTime.Parse(_createdFrom),
                                  CreatedTo = string.IsNullOrEmpty(_createdTo) ? (DateTime?) null : DateTime.Parse(_createdTo),
                                  InjuredPersonForename = _injuredPersonForename,
                                  InjuredPersonSurname = _injuredPersonSurname,
                                  Page = _page != default(int) ? _page : 1,
                                  PageSize = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                                  OrderBy = GetOrderBy(),
                                  Ascending = Ascending(),
                                  AllowedSiteIds = _sites
                              };

            var count = _accidentRecordsService.Count(request);
            var DTOs = _accidentRecordsService.Search(request);

            var viewModel = new AccidentRecordsIndexViewModel()
            {
                CreatedFrom = _createdFrom,
                CreatedTo = _createdTo,
                IsShowDeleted = _showDeleted,
                SiteId = _siteId,
                Title = _title,
                
                InjuredPersonForename = _injuredPersonForename,
                InjuredPersonSurname = _injuredPersonSurname,
                Size = _pageSize != default(int) ? _pageSize : DEFAULT_PAGE_SIZE,
                Total = count
            };

            
            viewModel.AccidentRecords  = DTOs.Select( x => new SearchAccidentRecordResultViewModel()
                                                        {
                                                            Id              = x.Id,
                                                            Reference       = x.Reference,
                                                            Title           = x.Title,                                                                                                                
                                                            Description     = x.DescriptionHowAccidentHappened != null ? x.DescriptionHowAccidentHappened.TruncateWithEllipsis(50) : null,
                                                            InjuredPerson   = x. InjuredPersonFullName,
                                                            Severity        = x.SeverityOfInjury == null    ? String.Empty : EnumHelper.GetEnumDescription( x.SeverityOfInjury ),
                                                            Site            = GetSiteDisplay(x),
                                                            ReportedBy      = x.CreatedBy == null           ? String.Empty : x.CreatedBy.Name,
                                                            DateCreated     = x.CreatedOn == null           ? String.Empty : x.CreatedOn.Value.ToShortDateString(),
                                                            DateOfAccident  = x.DateAndTimeOfAccident == null ? String.Empty : x.DateAndTimeOfAccident.Value.ToShortDateString(),
                                                            IsDeleted       = x.IsDeleted,
                                                            Status          = x.Status ? AccidentRecordStatusEnum.Open : AccidentRecordStatusEnum.Closed
                                                        }

                                                    ).ToList();

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

            viewModel.Sites = sites.Select(AutoCompleteViewModel.ForSite)
                                    .AddDefaultOption(String.Empty)
                                    .WithOtherOption( new AutoCompleteViewModel("Off-site", "-1") )
                                    .ToList();
        
            return viewModel;
        }