public async Task <FileDto> GetCustomersToExcel(GetAllCustomersForExcelInput input) { var filteredCustomers = _customerRepository.GetAll() .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.FirstName.Contains(input.Filter) || e.SurName.Contains(input.Filter) || e.Email.Contains(input.Filter) || e.Address.Contains(input.Filter) || e.Phone.Contains(input.Filter)) .WhereIf(!string.IsNullOrWhiteSpace(input.FirstNameFilter), e => e.FirstName == input.FirstNameFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.SurNameFilter), e => e.SurName == input.SurNameFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.EmailFilter), e => e.Email == input.EmailFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.AddressFilter), e => e.Address == input.AddressFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.PhoneFilter), e => e.Phone == input.PhoneFilter) .WhereIf(input.MinBirthDateFilter != null, e => e.BirthDate >= input.MinBirthDateFilter) .WhereIf(input.MaxBirthDateFilter != null, e => e.BirthDate <= input.MaxBirthDateFilter); var query = (from o in filteredCustomers select new GetCustomerForViewDto() { Customer = new CustomerDto { FirstName = o.FirstName, SurName = o.SurName, Email = o.Email, Address = o.Address, Phone = o.Phone, BirthDate = o.BirthDate, Id = o.Id } }); var customerListDtos = await query.ToListAsync(); return(_customersExcelExporter.ExportToFile(customerListDtos)); }
public async Task <FileDto> GetCustomersToExcel(GetAllCustomersForExcelInput input) { var filteredCustomers = _customerRepository.GetAll() .Include(e => e.CustomerTypeFk) .Include(e => e.CurrencyFk) .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Reference.Contains(input.Filter) || e.Name.Contains(input.Filter) || e.Identifier.Contains(input.Filter) || e.LogoUrl.Contains(input.Filter) || e.Website.Contains(input.Filter) || e.CustomerLoc8UUID.Contains(input.Filter)) .WhereIf(!string.IsNullOrWhiteSpace(input.ReferenceFilter), e => e.Reference.ToLower() == input.ReferenceFilter.ToLower().Trim()) .WhereIf(!string.IsNullOrWhiteSpace(input.NameFilter), e => e.Name.ToLower() == input.NameFilter.ToLower().Trim()) .WhereIf(!string.IsNullOrWhiteSpace(input.IdentifierFilter), e => e.Identifier.ToLower() == input.IdentifierFilter.ToLower().Trim()) .WhereIf(!string.IsNullOrWhiteSpace(input.CustomerLoc8UUIDFilter), e => e.CustomerLoc8UUID.ToLower() == input.CustomerLoc8UUIDFilter.ToLower().Trim()) .WhereIf(!string.IsNullOrWhiteSpace(input.CustomerTypeTypeFilter), e => e.CustomerTypeFk != null && e.CustomerTypeFk.Type.ToLower() == input.CustomerTypeTypeFilter.ToLower().Trim()) .WhereIf(!string.IsNullOrWhiteSpace(input.CurrencyCodeFilter), e => e.CurrencyFk != null && e.CurrencyFk.Code.ToLower() == input.CurrencyCodeFilter.ToLower().Trim()); var query = (from o in filteredCustomers join o1 in _lookup_customerTypeRepository.GetAll() on o.CustomerTypeId equals o1.Id into j1 from s1 in j1.DefaultIfEmpty() join o2 in _lookup_currencyRepository.GetAll() on o.CurrencyId equals o2.Id into j2 from s2 in j2.DefaultIfEmpty() select new GetCustomerForViewDto() { Customer = new CustomerDto { Reference = o.Reference, Name = o.Name, Identifier = o.Identifier, LogoUrl = o.LogoUrl, Website = o.Website, CustomerLoc8UUID = o.CustomerLoc8UUID, Id = o.Id }, CustomerTypeType = s1 == null ? "" : s1.Type.ToString(), CurrencyCode = s2 == null ? "" : s2.Code.ToString() }); var customerListDtos = await query.ToListAsync(); return(_customersExcelExporter.ExportToFile(customerListDtos)); }