Exemplo n.º 1
0
        public async Task <IActionResult> GetLoan(int pageSize = 10, int pageNumber = 1)
        {
            _logger.LogInfo("request contorller:Loan. request func: GetLoan ");
            LoanFilterDto filterRetrievals = new LoanFilterDto();

            filterRetrievals.PageNumber = pageNumber;
            filterRetrievals.PageSize   = pageSize;
            _logger.LogInfo("responce controller:Loan. responce func GetLoan ");
            var loanToReturn = await _loanRepo.GetLoans(filterRetrievals);

            return(Ok(loanToReturn));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PostSearchRetrievals(LoanFilterDto loans)
        {
            var loan = await _loanRepo.GetLoans(loans);

            return(Ok(loan));
        }