public ActionResult CalculateAsync(TariffCalculatorModel model) { if (!tariffCalculator.GetAllTariffs().Any(t => t.Id == model.SelectedTariff)) { ModelState.AddModelError(nameof(model.SelectedTariff), "invalid tarif"); } if (ModelState.IsValid) { var consumption = new PhoneConsumption(); consumption.SetConsumption( "NAH", model.LocalDuration * model.LocalPeakPercent / 100.0, model.LocalDuration * (100 - model.LocalPeakPercent) / 100.0); consumption.SetConsumption( "FERN", model.NationalDuration * model.NationalPeakPercent / 100.0, model.NationalDuration * (100 - model.NationalPeakPercent) / 100.0); var totalCost = tariffCalculator.TotalCosts(model.SelectedTariff, consumption); return(Json(totalCost.ToString("C2"))); } return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); }
private async void ComputeTotal() { double localDuration, nationalDuration; if (ParseTextBox(txtLocalDuration, out localDuration) && ParseTextBox(txtNationalDuration, out nationalDuration)) { PhoneConsumption consumption = new PhoneConsumption(); double localPerc = tbLocalDuration.Value / 100.0; double natPerc = tbNationalDuration.Value / 100.0; consumption.SetConsumption("NAH", localDuration * localPerc, localDuration * (1 - localPerc)); consumption.SetConsumption("FERN", nationalDuration * natPerc, nationalDuration * (1 - natPerc)); string tariffKey = ((Tariff)cmbTariff.SelectedValue).Id; txtTotal.Text = (await tariffCalculator.TotalCostsAsync(tariffKey, consumption)).ToString("C2"); } else { ResetTotal(); } }
public ActionResult Index(TariffCalculatorModel model) { if (!tariffCalculator.GetAllTariffs().Any(t => t.Id == model.SelectedTariff)) { ModelState.AddModelError(nameof(model.SelectedTariff), "invalid tarif"); } if (ModelState.IsValid) { var consumption = new PhoneConsumption(); consumption.SetConsumption( "NAH", model.LocalDuration * model.LocalPeakPercent / 100.0, model.LocalDuration * (100 - model.LocalPeakPercent) / 100.0); consumption.SetConsumption( "FERN", model.NationalDuration * model.NationalPeakPercent / 100.0, model.NationalDuration * (100 - model.NationalPeakPercent) / 100.0); model.TotalCost = tariffCalculator.TotalCosts(model.SelectedTariff, consumption); } model.TariffList = tariffCalculator.GetAllTariffs() .Select(tariff => new SelectListItem() { Value = tariff.Id, Text = tariff.Name, Selected = false }); return(View(model)); }
public ActionResult Index(TariffCalculatorModel model) { PhoneConsumption consumption = new PhoneConsumption(); consumption.SetConsumption("NAH", model.LocalDuration * model.LocalPeakPercent / 100.0, model.LocalDuration * (100 - model.LocalPeakPercent) / 100.0); consumption.SetConsumption("FERN", model.NationalDuration * model.NationalPeakPercent / 100.0, model.NationalDuration * (100 - model.NationalPeakPercent) / 100.0); // Compute the costs for the specified phone profile model.TotalCost = tariffCalculator.TotalCosts(model.SelectedTariff, consumption); model.TariffList = tariffCalculator.GetAllTariffs().Select(x => new SelectListItem { Text = x.Name, Value = x.Id }); return(View(model)); }