Esempio n. 1
0
        protected override IQuery <Company> ApplyWhereClause(IQuery <Company> query, CompanyFilterDto filter)
        {
            if (string.IsNullOrWhiteSpace(filter.Name))
            {
                return(query);
            }

            return(query.Where(new SimplePredicate(nameof(Company.Name), ValueComparingOperator.StringContains, filter.Name)));
        }
Esempio n. 2
0
        protected override IQuery <Company> ApplyWhereClause(IQuery <Company> query, CompanyFilterDto filter)
        {
            if (filter.Ico < 0)
            {
                return(query);
            }

            return(query.Where(new SimplePredicate(nameof(Company.Ico), ValueComparingOperator.Equal, filter.Ico)));
        }
Esempio n. 3
0
        public IResponseDTO SearchCompanies(CompanyFilterDto filterDto)
        {
            try
            {
                var query = _appDbContext.Companies
                            .Include(x => x.Country)
                            .Include(x => x.Creator)
                            .Include(x => x.Updator)
                            .Where(x => !x.IsDeleted);

                if (filterDto != null)
                {
                    if (!string.IsNullOrEmpty(filterDto.Name))
                    {
                        query = query.Where(x => x.Name.Trim().ToLower().Contains(filterDto.Name.Trim().ToLower()));
                    }
                    if (!string.IsNullOrEmpty(filterDto.Email))
                    {
                        query = query.Where(x => x.Email.Trim().ToLower().Contains(filterDto.Email.Trim().ToLower()));
                    }
                    if (!string.IsNullOrEmpty(filterDto.BusinessRegisterationNumber))
                    {
                        query = query.Where(x => x.BusinessRegisterationNumber.Trim().ToLower().Contains(filterDto.BusinessRegisterationNumber.Trim().ToLower()));
                    }
                    if (!string.IsNullOrEmpty(filterDto.TaxRegisterationNumber))
                    {
                        query = query.Where(x => x.TaxRegisterationNumber.Trim().ToLower().Contains(filterDto.TaxRegisterationNumber.Trim().ToLower()));
                    }
                    if (filterDto.CountryId != null)
                    {
                        query = query.Where(x => x.Country.Id == filterDto.CountryId);
                    }
                }

                //Check Sort Property
                if (!string.IsNullOrEmpty(filterDto?.SortProperty))
                {
                    //query = query.OrderBy(
                    //    string.Format("{0} {1}", filterDto.SortProperty, filterDto.IsAscending ? "ASC" : "DESC"));
                }
                else
                {
                    query = query.OrderByDescending(x => x.Id);
                }

                // Pagination
                var total = query.Count();
                if (filterDto.PageIndex.HasValue && filterDto.PageSize.HasValue)
                {
                    query = query.Skip((filterDto.PageIndex.Value - 1) * filterDto.PageSize.Value).Take(filterDto.PageSize.Value);
                }

                var datalist = _mapper.Map <List <CompanyDto> >(query.ToList());

                _response.IsPassed = true;
                _response.Data     = new
                {
                    List  = datalist,
                    Total = total,
                };
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Errors.Add($"Error: {ex.Message}");
            }

            return(_response);
        }
Esempio n. 4
0
 public IResponseDTO SearchCompanies([FromQuery] CompanyFilterDto filterDto)
 {
     _response = _companyService.SearchCompanies(filterDto);
     return(_response);
 }
        /// <summary>
        /// Gets companies according to filter
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public async Task <QueryResultDto <CompanyDto, CompanyFilterDto> > GetCompaniesAsync(CompanyFilterDto filter)
        {
            using (UnitOfWorkProvider.Create())
            {
                var companyListQueryResult = await companyService.ListCompaniesAsync(filter);

                return(companyListQueryResult);
            }
        }