/// <summary> /// Adds tour charge foreach vehicle type available /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult AddCharge(int id) { try { List<TourChargeModel> model = new List<TourChargeModel>(); // ViewBag.VehicleList = CommonRepository.GetVehicles(false); TourModel tour = TourRepository.GetTour(id); if (tour == null) throw new TourNotFoundException(); IEnumerable<VehicleEntity> vehicles = CommonRepository.GetVehicles(true); foreach (var vehicle in vehicles) { TourChargeModel tourCharge = new TourChargeModel(); tourCharge.TourId = tour.TourId; tourCharge.TourTitle = tour.TourTitle; tourCharge.VehicleId = vehicle.VehicleId; tourCharge.VehicleName = vehicle.VehicleName; model.Add(tourCharge); } return View(model); } catch (Exception) { throw; } }
public ActionResult EditCharge(int id) { try { TourModel tour = TourRepository.GetTour(id); if (tour == null) throw new TourNotFoundException(); ICollection<TourChargeModel> model = TourRepository.GetTourCharges(id); if (model.Count == 0) { //If no records found for charges the redirect to add charges RedirectToAction("AddCharge", new { id = id }); } IEnumerable<VehicleEntity> vehicles = CommonRepository.GetVehicles(true); foreach (var vehicle in vehicles) { if (!model.Where(x => x.VehicleId == vehicle.VehicleId).Any()) { TourChargeModel tourCharge = new TourChargeModel(); tourCharge.TourId = tour.TourId; tourCharge.TourTitle = tour.TourTitle; tourCharge.VehicleId = vehicle.VehicleId; tourCharge.VehicleName = vehicle.VehicleName; model.Add(tourCharge); } } return View(model); } catch (Exception) { throw; } }