public ActionResult Cost() { ModelState.Clear(); var vm = new TourLeadCostViewModel(); ConfigureViewModel(vm); return(View(vm)); }
private void ConfigureViewModel(TourLeadCostViewModel vm) { var repo = new DBTourLeader(); IEnumerable <TourLeader> tourLeads = repo.GetTourLeads(); foreach (var lead in tourLeads) { var idAndName = $"{lead.Name} (ID: {lead.TourleaderId})"; lead.Name = idAndName; } vm.TourLeads = new SelectList(tourLeads, "TourleaderId", "Name"); }
public ActionResult Cost(TourLeadCostViewModel vm) { if (!ModelState.IsValid) { ConfigureViewModel(vm); return(View(vm)); } double cost = 0.0; try { cost = CostCalculator.CalculateTourLeadCost(vm.SelectedTourLead, Convert.ToInt32(vm.NoOfDays)); } catch (Exception e) { TempData["msg"] = "<script>alert('Sorry! Fail to calculate cost. Please try again.');</script>"; } ConfigureViewModel(vm); ViewBag.Cost = cost; return(View(vm)); }