public static async Task <CalculationReport> Build(SebCustomerAgreement agreement, string oldBaseRateCode) { using (var calculator = new InterestRateCalculator(new ViliborSource())) { var a = agreement; var c = a.Customer; var margin = agreement.Margin; var currentRate = await calculator.Calculate((decimal)margin, oldBaseRateCode).ConfigureAwait(false); var newBaseRateCode = a.BaseRateCode; var newRate = await calculator.Calculate((decimal)margin, newBaseRateCode).ConfigureAwait(false); var report = new CalculationReport { CustomerAgreementDescription = $"{c.FirstName} {c.LastName} / {a.Amount} / {a.Margin} / {a.Duration}", CurrentBaseRateCode = oldBaseRateCode, CurrentInterestRate = currentRate, NewBaseRateCode = newBaseRateCode, NewInterestRate = newRate }; return(report); } }
private static Agreement ToAgreement(SebCustomerAgreement entry) => new Agreement { Id = entry.Id, Amount = entry.Amount, BaseRateCode = entry.BaseRateCode, Duration = entry.Duration, Margin = entry.Margin };
public ActionResult CreatePost(int?SelectedCustomer) { var vm = new ViewModels.NewAgreement(); try { if (TryUpdateModel(vm, "", new string[] { "CustomerId", "Amount", "BaseRateCode", "Margin", "Duration" })) { var masterCustomer = db.Customers.Find(vm.CustomerId); if (masterCustomer != null) { var agreement = new SebCustomerAgreement { Amount = vm.Amount, BaseRateCode = vm.BaseRateCode, Margin = vm.Margin, Duration = vm.Duration, Customer = masterCustomer }; db.Agreements.Add(agreement); db.SaveChanges(); return(RedirectToAction("Index", new { SelectedCustomer = masterCustomer.Id })); } } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } PopulateBaseRateCodes(null); return(View(vm)); }