Exemple #1
0
        public IResponseDTO SearchPolicyInsurers(PolicyInsurerFilterDto filterDto)
        {
            try
            {
                var query = _appDbContext.PolicyInsurers.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 (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 <PolicyInsurerDto> >(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);
        }
Exemple #2
0
 public IResponseDTO SearchPolicyInsurers([FromQuery] PolicyInsurerFilterDto filterDto)
 {
     _response = _policyInsurerService.SearchPolicyInsurers(filterDto);
     return(_response);
 }