示例#1
0
        public ActionResult Cost()
        {
            ModelState.Clear();
            var vm = new TourLeadCostViewModel();

            ConfigureViewModel(vm);
            return(View(vm));
        }
示例#2
0
        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");
        }
示例#3
0
        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));
        }