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)); }
public double TotalCosts(string tariffKey, PhoneConsumption consumption) { return(TariffCalculator.TotalCosts(tariffKey, consumption)); }