public async Task <AgreementDetailsDTO> ProcessAgreementAsync(AgreementRequest agreementRequest) { Validate(agreementRequest); var agreementId = agreementRequest.Id; var existingAgreement = _agreementService.AgreementExists(agreementId); var currentBaseRateCode = existingAgreement ? await _agreementService.GetBaseRateCodeAsync(agreementId) : agreementRequest.BaseRateCode; var(currentBaseRateValue, newBaseRateValue) = await GetBaseRateValuesAsync(currentBaseRateCode, agreementRequest.BaseRateCode); var agreement = existingAgreement ? await _agreementService.UpdateAgreementAsync(agreementRequest) : await _agreementService.AddAgreementAsync(agreementRequest); var customer = await _customerService.GetCustomerAsync(agreementRequest.CustomerId); var margin = agreementRequest.Margin; var currentInterestRate = GetInterestRate(currentBaseRateValue, margin); var newInterestRate = GetInterestRate(newBaseRateValue, margin); var interestRatesDifference = GetInterestRatesDifferent(currentInterestRate, newInterestRate); return(new AgreementDetailsDTO { Agreement = agreement, Customer = customer, CurrentInterestRate = currentInterestRate, NewInterestRate = newInterestRate, InterestRatesDifference = interestRatesDifference }); }
public async Task <IActionResult> Create([FromBody] AgreementRequest agreementRequest) { if (!BaseRateCodeExists(agreementRequest.BaseRateCode)) { return(new BadRequestResult()); } return(new OkObjectResult(await _agreementService.Create(agreementRequest))); }
private static void Validate(AgreementRequest request) { Ensure.Guid.IsNotEmpty(request.Id, nameof(request.Id)); EnsureArg.IsGt(request.Amount, 0, nameof(request.Amount)); Ensure.Enum.IsDefined(request.BaseRateCode, nameof(request.BaseRateCode)); EnsureArg.IsGt(request.Duration, 0, nameof(request.Duration)); EnsureArg.IsGt(request.Margin, 0, nameof(request.Margin)); Ensure.Guid.IsNotEmpty(request.CustomerId, nameof(request.CustomerId)); }
public static AgreementEntity ToEntity(this AgreementRequest request) => new AgreementEntity { Id = request.Id, Amount = request.Amount, BaseRateCode = request.BaseRateCode, CustomerId = request.CustomerId, Duration = request.Duration, Margin = request.Margin };
private async Task <AgreementResponse> CreateAgreement(CustomerResponse customer) { var agreementRequest = new AgreementRequest() { Amount = 1200, BaseRateCode = "VILIBOR1y", Margin = (decimal)1.6, AgreementDuration = 60, CustomerId = customer.Id, }; StringContent agreementData = new StringContent(JsonConvert.SerializeObject(agreementRequest), Encoding.UTF8, "application/json"); var agreement = await(await _client.PostAsync("/agreement", agreementData)).Content.ReadAsAsync <AgreementResponse>(); Assert.AreEqual(agreementRequest.Amount, agreement.Amount); Assert.AreEqual(agreementRequest.BaseRateCode, agreement.BaseRateCode); Assert.AreEqual(agreementRequest.Margin, agreement.Margin); Assert.AreEqual(agreementRequest.AgreementDuration, agreement.AgreementDuration); Assert.AreEqual(agreementRequest.CustomerId, agreement.CustomerId); return(agreement); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] AgreementRequest agreementRequest) { return(new OkObjectResult(await _agreementService.Update(id, agreementRequest))); }
public Task <AgreementResponse> Update(Guid id, AgreementRequest model) => _agreementRepository.Update(id, model);
public Task <AgreementResponse> Create(AgreementRequest model) => _agreementRepository.Create(model);
public async Task <AgreementDTO> UpdateAgreementAsync(AgreementRequest agreementRequest) => (await _agreementRepository.UpdateAgreementAsync(agreementRequest.ToEntity())).ToDTO();