Exemplo n.º 1
0
        public override Task <GetLoansResponse> GetByAccounts(GetLoansRequest request, ServerCallContext context)
        {
            var loans = loansRepository.GetByAccounts(request.Ids)
                        .Select(loan => mapper.Map <Loan>(loan));

            return(Task.FromResult(new GetLoansResponse {
                Loans = { loans }
            }));
        }
        public async Task <LoansContainer> GetLoansAsync(GetLoansRequest getLoansRequest)
        {
            var client  = new RestClient(GetBaseURLFromRequest(getLoansRequest));
            var request = new RestRequest(Method.GET);

            request.AddHeader(authorization, _apiKey);
            IRestResponse response = await client.ExecuteTaskAsync(request);

            return(JsonConvert.DeserializeObject <LoansContainer>(response.Content));
        }
Exemplo n.º 3
0
        public override Task <GetLoansResponse> Get(GetLoansRequest request, ServerCallContext context)
        {
            var loans = request.Ids.Select(id => loansRepository.Get(id))
                        .Where(loan => loan != null)
                        .Select(loan => mapper.Map <Loan>(loan));

            return(Task.FromResult(new GetLoansResponse {
                Loans = { loans }
            }));
        }
        private string GetBaseURLFromRequest(GetLoansRequest getLoansRequest)
        {
            StringBuilder baseUrlStringBuilder = new StringBuilder();
            var           showAll = getLoansRequest.ShowAll ? "true" : "false";

            baseUrlStringBuilder.Append(baseUrl + "?showAll=" + showAll);

            if (getLoansRequest.FilterId.HasValue)
            {
                baseUrlStringBuilder.Append("&filterId=" + getLoansRequest.FilterId);
            }
            return(baseUrlStringBuilder.ToString());
        }
Exemplo n.º 5
0
        private async Task <GetPaymentsWithLoansResult> WithLoans(Repository.Payment[] payments, Metadata headers)
        {
            var mapped = payments.Where(payment => payment != null)
                         .Select(p => mapper.Map <Payment>(p))
                         .ToArray();

            var paymentsIds  = payments.Select(p => p.Id);
            var loansRequest = new GetLoansRequest {
                Ids = { paymentsIds }
            };
            var loansResult = await loansClient.GetByPaymentsAsync(loansRequest, headers);

            return(new GetPaymentsWithLoansResult {
                Payments = { mapped }, Loans = { loansResult.Loans }
            });
        }
Exemplo n.º 6
0
        public List <Loan> All(uint offset = 0, uint limit = 0, string ordering = "-created", string loanOfficer = null)
        {
            var         result       = new GetLoansRequest(offset, limit, ordering, loanOfficer).Execute(Api.Client);
            var         fetchedLoans = result.Data.Loans;
            List <Loan> loans        = new List <Loan>();

            if (result.Status == 200)
            {
                for (int i = 0; i < fetchedLoans.Count; i++)
                {
                    Loan tempLoan = new Loan();
                    tempLoan.UpdateFromRequest(Utils.DictionaryOfJsonFields(fetchedLoans[i]));
                    loans.Add(tempLoan);
                }
            }
            return(loans);
        }