public async Task <PagedResultDto <GetMachineForViewDto> > GetAll(GetAllMachinesInput input) { var filteredMachines = _machineRepository.GetAll() .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Name.Contains(input.Filter) || e.Description.Contains(input.Filter)); var pagedAndFilteredMachines = filteredMachines .OrderBy(input.Sorting ?? "id asc") .PageBy(input); var machines = from o in pagedAndFilteredMachines select new GetMachineForViewDto() { Machine = new MachineDto { Name = o.Name, Description = o.Description, Id = o.Id } }; var totalCount = await filteredMachines.CountAsync(); return(new PagedResultDto <GetMachineForViewDto>( totalCount, await machines.ToListAsync() )); }
public async Task <PagedResultDto <GetMachineForViewDto> > GetAll(GetAllMachinesInput input) { var filteredMachines = _machineRepository.GetAll() .Include(e => e.OrganizationUnitFk) .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.NameAr.Contains(input.Filter) || e.NameEn.Contains(input.Filter) || e.IpAddress.Contains(input.Filter) || e.SubNet.Contains(input.Filter) || e.Action.Contains(input.Filter) || e.CmdStatus.Contains(input.Filter) || e.Port.Contains(input.Filter)) .WhereIf(!string.IsNullOrWhiteSpace(input.NameArFilter), e => e.NameAr == input.NameArFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.NameEnFilter), e => e.NameEn == input.NameEnFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.IpAddressFilter), e => e.IpAddress == input.IpAddressFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.SubNetFilter), e => e.SubNet == input.SubNetFilter) .WhereIf(input.StatusFilter > -1, e => (input.StatusFilter == 1 && e.Status) || (input.StatusFilter == 0 && !e.Status)) .WhereIf(!string.IsNullOrWhiteSpace(input.OrganizationUnitDisplayNameFilter), e => e.OrganizationUnitFk != null && e.OrganizationUnitFk.DisplayName == input.OrganizationUnitDisplayNameFilter); var pagedAndFilteredMachines = filteredMachines .OrderBy(input.Sorting ?? "id asc") .PageBy(input); var machines = from o in pagedAndFilteredMachines join o1 in _lookup_organizationUnitRepository.GetAll() on o.OrganizationUnitId equals o1.Id into j1 from s1 in j1.DefaultIfEmpty() select new GetMachineForViewDto() { Machine = new MachineDto { NameAr = o.NameAr, NameEn = o.NameEn, IpAddress = o.IpAddress, SubNet = o.SubNet, Status = o.Status, Id = o.Id }, OrganizationUnitDisplayName = s1 == null ? "" : s1.DisplayName.ToString() }; var totalCount = await filteredMachines.CountAsync(); return(new PagedResultDto <GetMachineForViewDto>( totalCount, await machines.ToListAsync() )); }