public async Task <LoanSearchResultDto> GetLoans(LoanFilterDto filter, bool isDownload = false) { var currentUserRole = _commonRepo.CurrentRole(); IEnumerable <NameValue> loanStatuses = _enumRepo.GetItems <Domain.Enumerations.RoleType>().Result; LoanSearchResultDto loanSearchResult = new LoanSearchResultDto(); IQueryable <LoanSearchDto> result = Enumerable.Empty <LoanSearchDto>().AsQueryable(); if (currentUserRole == (int)Domain.Enumerations.RoleType.Admin) { result = _context.Loans.Where(c => c.LoanStatus != (int)Domain.Enumerations.LoanStatuses.Saved) .Include(c => c.LoanType) .Include(c => c.User) .Select(c => new LoanSearchDto { Id = c.Id, Amount = c.Amount, LoanTypeId = c.LoanTypeId, LoanTypeName = c.LoanType.Name, StartDate = c.StartDate, EndDate = c.EndDate, UserName = c.User.Name, CreateDate = c.CreateDate, LastUpdateDate = c.LastUpdateDate, ValutaName = _enumRepo.GetItemsByString <Domain.Enumerations.Currency>((int)c.Valuta), LoanStatus = c.LoanStatus, LoanStatusName = _enumRepo.GetItemsByString <Domain.Enumerations.LoanStatuses>((int)c.LoanStatus), }); } else { result = _context.Loans .Include(c => c.LoanType) .Include(c => c.User) .Select(c => new LoanSearchDto { Id = c.Id, Amount = c.Amount, LoanTypeId = c.LoanTypeId, LoanTypeName = c.LoanType.Name, StartDate = c.StartDate, EndDate = c.EndDate, UserName = c.User.Name, CreateDate = c.CreateDate, LastUpdateDate = c.LastUpdateDate, ValutaName = _enumRepo.GetItemsByString <Domain.Enumerations.Currency>((int)c.Valuta), LoanStatus = c.LoanStatus, LoanStatusName = _enumRepo.GetItemsByString <Domain.Enumerations.LoanStatuses>((int)c.LoanStatus), }); } if (result == null) { return(null); } loanSearchResult.TotalRecords = result.Count(); if (filter.PageNumber > 1) { int skipRecord = (filter.PageNumber - 1) * filter.PageSize; result = result.Skip(skipRecord).Take(filter.PageSize); } else { result = result.Take(filter.PageSize == 0 ? 10 : filter.PageSize); } loanSearchResult.PageNumber = filter.PageNumber; loanSearchResult.PageSize = filter.PageSize; loanSearchResult.LoanResult = loanSearchResult.TotalRecords == 0 ? new List <LoanSearchDto>() : result.ToList(); return(loanSearchResult); }