public async Task <PagedResultDto <GetAllIncidentsOutput> > GetAll(GetAllIncidentsInput input)
        {
            var query = from o in _incidentRepository.GetAll()
                        .Include(x => x.Locations)
                        .Include(x => x.FloodTypes)
                        .Include(x => x.Pictures)
                        join u in _userRepository.GetAll() on o.CreatorUserId equals u.Id
                        select new GetAllIncidentsOutput
            {
                Incident = ObjectMapper.Map <IncidentDto>(o),
                Username = u.UserName
            };

            var totalCount = await query.CountAsync();

            var incidents = await query
                            .OrderBy(input.Sorting ?? "incident.id asc")
                            .PageBy(input)
                            .ToListAsync();

            return(new PagedResultDto <GetAllIncidentsOutput>(
                       totalCount,
                       incidents
                       ));
        }
        public async Task <PagedResultDto <GetIncidentForViewDto> > GetAll(GetAllIncidentsInput input)
        {
            using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant, AbpDataFilters.MayHaveTenant))  // BYPASS TENANT FILTER to include Users
            {
                var tenantInfo = await TenantManager.GetTenantInfo();

                var crossTenantPermissions = await TenantManager.GetCrossTenantPermissions(tenantInfo, _entityType);

                var filteredIncidents = _incidentRepository.GetAll()
                                        .Include(e => e.IncidentPriorityFk)
                                        .Include(e => e.IncidentStatusFk)
                                        .Include(e => e.CustomerFk)
                                        .Include(e => e.AssetFk)
                                        .Include(e => e.SupportItemFk)
                                        .Include(e => e.IncidentTypeFk)
                                        .Include(e => e.UserFk)
                                        .WhereIf(tenantInfo.Tenant.Id != 0 && crossTenantPermissions != null, e => crossTenantPermissions.Contains((int)e.TenantId)) // CROSS TENANT AUTH
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Description.Contains(input.Filter) || e.Location.Contains(input.Filter) || e.Remarks.Contains(input.Filter))
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description.ToLower() == input.DescriptionFilter.ToLower().Trim())
                                        .WhereIf(input.MinIncidentDateFilter != null, e => e.IncidentDate >= input.MinIncidentDateFilter)
                                        .WhereIf(input.MaxIncidentDateFilter != null, e => e.IncidentDate <= input.MaxIncidentDateFilter)
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.LocationFilter), e => e.Location.ToLower() == input.LocationFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.RemarksFilter), e => e.Remarks.ToLower() == input.RemarksFilter.ToLower().Trim())
                                        .WhereIf(input.MinResolvedAtFilter != null, e => e.ResolvedAt >= input.MinResolvedAtFilter)
                                        .WhereIf(input.MaxResolvedAtFilter != null, e => e.ResolvedAt <= input.MaxResolvedAtFilter)
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.IncidentPriorityPriorityFilter), e => e.IncidentPriorityFk != null && e.IncidentPriorityFk.Priority.ToLower() == input.IncidentPriorityPriorityFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.IncidentStatusStatusFilter), e => e.IncidentStatusFk != null && e.IncidentStatusFk.Status.ToLower() == input.IncidentStatusStatusFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.CustomerNameFilter), e => e.CustomerFk != null && e.CustomerFk.Name.ToLower() == input.CustomerNameFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.AssetReferenceFilter), e => e.AssetFk != null && e.AssetFk.Reference.ToLower() == input.AssetReferenceFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.SupportItemDescriptionFilter), e => e.SupportItemFk != null && e.SupportItemFk.Description.ToLower() == input.SupportItemDescriptionFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.IncidentTypeTypeFilter), e => e.IncidentTypeFk != null && e.IncidentTypeFk.Type.ToLower() == input.IncidentTypeTypeFilter.ToLower().Trim())
                                        .WhereIf(!string.IsNullOrWhiteSpace(input.UserNameFilter), e => e.UserFk != null && e.UserFk.Name.ToLower() == input.UserNameFilter.ToLower().Trim());

                var pagedAndFilteredIncidents = filteredIncidents
                                                .OrderBy(input.Sorting ?? "id asc")
                                                .PageBy(input);

                var incidents = from o in pagedAndFilteredIncidents
                                join o1 in _lookup_incidentPriorityRepository.GetAll() on o.IncidentPriorityId equals o1.Id into j1
                                from s1 in j1.DefaultIfEmpty()

                                join o2 in _lookup_incidentStatusRepository.GetAll() on o.IncidentStatusId equals o2.Id into j2
                                from s2 in j2.DefaultIfEmpty()

                                join o3 in _lookup_customerRepository.GetAll() on o.CustomerId equals o3.Id into j3
                                from s3 in j3.DefaultIfEmpty()

                                join o4 in _lookup_assetRepository.GetAll() on o.AssetId equals o4.Id into j4
                                from s4 in j4.DefaultIfEmpty()

                                join o5 in _lookup_supportItemRepository.GetAll() on o.SupportItemId equals o5.Id into j5
                                from s5 in j5.DefaultIfEmpty()

                                join o6 in _lookup_incidentTypeRepository.GetAll() on o.IncidentTypeId equals o6.Id into j6
                                from s6 in j6.DefaultIfEmpty()

                                join o7 in _lookup_userRepository.GetAll() on o.UserId equals o7.Id into j7
                                from s7 in j7.DefaultIfEmpty()

                                select new GetIncidentForViewDto()
                {
                    Incident = new IncidentDto
                    {
                        Description  = o.Description,
                        IncidentDate = o.IncidentDate,
                        Location     = o.Location,
                        Remarks      = o.Remarks,

                        ResolvedAt = o.ResolvedAt,
                        Id         = o.Id
                    },
                    IncidentPriorityPriority = s1 == null ? "" : s1.Priority.ToString(),
                    IncidentStatusStatus   = s2 == null ? "" : s2.Status.ToString(),
                    CustomerName           = s3 == null ? "" : s3.Name.ToString(),
                    AssetReference         = s4 == null ? "" : s4.Reference.ToString(),
                    SupportItemDescription = s5 == null ? "" : s5.Description.ToString(),
                    IncidentTypeType       = s6 == null ? "" : s6.Type.ToString(),
                    UserName = s7 == null ? "" : s7.Name.ToString()
                };

                var totalCount = await filteredIncidents.CountAsync();

                return(new PagedResultDto <GetIncidentForViewDto>(
                           totalCount,
                           await incidents.ToListAsync()
                           ));
            }
        }
 public async Task <PagedResultDto <GetAllIncidentsOutput> > GetAll(GetAllIncidentsInput input)
 {
     return(await ApiClient.GetAnonymousAsync <PagedResultDto <GetAllIncidentsOutput> >(GetEndpoint(nameof(GetAll)), input));
 }