예제 #1
0
        public IResponseDTO SearchCurrencies(CurrencyFilterDto filterDto)
        {
            try
            {
                var query = _appDbContext.Countries.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.Code))
                    {
                        query = query.Where(x => x.Code.Trim().ToLower().Contains(filterDto.Code.Trim().ToLower()));
                    }
                    if (filterDto.IsActive != null)
                    {
                        query = query.Where(x => x.IsActive == filterDto.IsActive);
                    }
                }

                //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 <CurrencyDto> >(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);
        }
예제 #2
0
        public virtual async Task <PagedResultDto <CurrencyDto> > GetAll(CurrencyFilterDto input)
        {
            var query = repository
                        .GetAll()
                        .Where(p => !p.IsDeleted)
                        .WhereIf(input.Name != null, p => p.Name == input.Name)
                        .WhereIf(input.CurrencyCode != null, p => p.CurrencyCode == input.CurrencyCode);

            var totalCount = await query.CountAsync();

            query = ApplySorting(query, input);
            query = ApplyPaging(query, input);

            var entities = await query.ToListAsync();

            return(new PagedResultDto <CurrencyDto>(
                       totalCount,
                       entities.Select(p => p.MapTo <CurrencyDto>())
                       .ToList()
                       ));
        }
예제 #3
0
 public IResponseDTO SearchCurrencies([FromQuery] CurrencyFilterDto filterDto)
 {
     _response = _currencyService.SearchCurrencies(filterDto);
     return(_response);
 }
예제 #4
0
        protected virtual IQueryable <Currency> ApplyPaging(IQueryable <Currency> query, CurrencyFilterDto input)
        {
            var pagedInput = input as IPagedResultRequest;

            if (pagedInput != null)
            {
                return(query.PageBy(pagedInput));
            }

            var limitedInput = input as ILimitedResultRequest;

            if (limitedInput != null)
            {
                return(query.Take(limitedInput.MaxResultCount));
            }

            return(query);
        }
예제 #5
0
        protected virtual IQueryable <Currency> ApplySorting(IQueryable <Currency> query, CurrencyFilterDto input)
        {
            var sortInput = input as ISortedResultRequest;

            if (sortInput != null)
            {
                if (sortInput.Sorting.IsNotNullOrEmpty())
                {
                    return(query.OrderBy(sortInput.Sorting));
                }
            }

            if (input is ILimitedResultRequest)
            {
                return(query.OrderByDescending(e => e.Id));
            }

            return(query);
        }
예제 #6
0
        protected override IQuery <Currency> ApplyWhereClause(IQuery <Currency> query, CurrencyFilterDto filter)
        {
            if (filter.CodeName.IsNullOrEmpty())
            {
                return(query);
            }

            var predicate = new SimplePredicate(nameof(Currency.Code), ValueComparingOperator.Equal, filter.CodeName);

            return(query.Where(predicate));
        }