public async Task <IActionResult> GetSpecific(long sinumber, string certificateId) { var certificates = await _service.GetCertificatesAsync(new GetCertificatesRequest { SiNumber = sinumber }); var certificate = certificates?.Value?.Certificates?.FirstOrDefault(c => c.Id == certificateId); var response = await _service.GetPaymentsAsync(new GetPaymentsRequest() { SiNumber = sinumber, ReferenceDate = certificate.From }); if (response.BusinessMessages != null && response.BusinessMessages.Length > 0) { return(BadRequest(response.BusinessMessages)); } var mappedPayments = _mapper.Map <IEnumerable <BobPayment> >(response.Value?.Payments, opt => opt.Items["Id"] = certificateId); return(Ok(mappedPayments)); }
private async Task <decimal> GetCurrentPaymentAmount(long siNumber, DateTime reference) { var response = await _bobService.GetPaymentsAsync(new GetPaymentsRequest() { SiNumber = siNumber, ReferenceDate = reference }); if (response.Value != null && response.Value.Payments != null && response.Value.Payments.Count() > 0) { return(response.Value.Payments.OrderByDescending(p => p.PeriodEnd).FirstOrDefault().Amount); } else if (response.BusinessMessages != null && response.BusinessMessages.Any()) { var errors = response.BusinessMessages.Where(bm => bm.Type == MessageType.Error); if (errors.Any()) { throw new Exception(string.Join("; ", errors.Select(e => e.MessageString))); } } return(0); }