public AgreementExtended(Agreement agreement, BaseRate.RateType newBaseRateType) : base(agreement.Amount, agreement.BaseRateType, agreement.Margin, agreement.Duration, agreement.Customer) { this.Id = agreement.Id; this.CustomerId = this.Customer.Id; // this line is required as we are not using EF to map to foreign key this.NewBaseRateType = newBaseRateType; }
public Agreement(int amount, BaseRate.RateType baseRateType, float margin, int duration, Customer customer) { this.Amount = amount; this.BaseRateType = baseRateType; this.Margin = margin; this.Duration = duration; this.Customer = customer; }
public static Agreement GetTestAgreement2(Customer customer, BaseRate.RateType baseRateType) { var agreement = new Agreement(200, baseRateType, 2.5f, 20, customer); agreement.Id = 2; agreement.CustomerId = customer.Id; return(agreement); }
public static Agreement GetTestAgreement1(Customer customer, BaseRate.RateType baseRateType) { var agreement = new Agreement(100, baseRateType, 1.5f, 10, customer); agreement.Id = 1; agreement.CustomerId = customer.Id; return(agreement); }
public static AgreementExtended GetExtendedAgreement(Agreement agreement, BaseRate.RateType newBaseRateType, float oldBaseRateValue, float newBaseRateValue) { var agremeentExtended = new AgreementExtended(agreement, newBaseRateType); agremeentExtended.CurrentInterestRate = CalculateInterestRate(oldBaseRateValue, agremeentExtended.Margin); agremeentExtended.NewInterestRate = CalculateInterestRate(newBaseRateValue, agremeentExtended.Margin); agremeentExtended.DifferenceBetweenInterestRates = CalculateDifference(agremeentExtended.CurrentInterestRate, agremeentExtended.NewInterestRate); return(agremeentExtended); }
public IHttpActionResult UpdateAgreement(int id, [FromBody] BaseRate.RateType newBaseRateType) { Agreement agreement = db.Agreements.Include("Customer").SingleOrDefault(x => x.Id == id); if (agreement == null) { return(NotFound()); } BaseRate.RateType oldBaseRateType = agreement.BaseRateType; agreement.BaseRateType = newBaseRateType; db.MarkAsModified(agreement); try { db.SaveChanges(); } catch (Exception ex) { return(InternalServerError(ex)); } // check if base rate record exists BaseRate currentBaseRate = db.BaseRates.SingleOrDefault(x => x.Code == oldBaseRateType); BaseRate newBaseRate = db.BaseRates.SingleOrDefault(x => x.Code == newBaseRateType); if (currentBaseRate == null || newBaseRate == null) { // Better solution would be to throw a custom exception with an error message return(InternalServerError(new ArgumentNullException("Base Rate record was not found"))); } // to client we need to return an agreement with an old base rate type agreement.BaseRateType = oldBaseRateType; var agremeentExtended = Agreements.GetExtendedAgreement(agreement, newBaseRateType, currentBaseRate.Value, newBaseRate.Value); return(Ok(agremeentExtended)); }
public static async Task <AgreementExtended> UpdateAgreementBaseRate(string path, BaseRate.RateType newBaseRateType) { HttpResponseMessage response = null; using (HttpClient client = ConfigureHttpClient()) { response = await client.PutAsJsonAsync(path, newBaseRateType); } AgreementExtended result = null; if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsAsync <AgreementExtended>(); } return(result); }
public async Task <ActionResult> EditAgreement(int id, BaseRate.RateType newBaseRateType) { AgreementExtended agreementExtended = await ApiCalls.UpdateAgreementBaseRate($"api/rates/{id}", newBaseRateType); return(View("AgreementExtended", agreementExtended)); }