public ActionResult Create(TrainingAccess training) { if (Request.Form["modules"] == "") { training.ModuleId = 0; } else { training.ModuleId = Convert.ToInt32(Request.Form["modules"]); } TrainingService trainingService = new TrainingService(); TrainingAccess train = training; try { if (trainingService.Add(train)) { TempData["message"] = "New training has been created."; return(RedirectToAction("Index")); } TempData["message"] = "Failed to created new training."; return(View("Create")); } catch (Exception ex) { TempData["message"] = "Failed to created new training. Eorror: " + ex.GetBaseException().Message; return(View("Create")); } }
//Create a new training. public ActionResult Create() { TrainingService trainingService = new TrainingService(); TrainingAccess training = new TrainingAccess(); ModuleService moduleService = new ModuleService(); List <ModuleAccess> modules = new List <ModuleAccess>(); modules = moduleService.GetModuleData(); ViewBag.modules = new SelectList(modules, "moduleId", "moduleName"); SelectListItem allStaff = new SelectListItem() { Text = "Open for all", Value = "allStaff" }; SelectListItem manager = new SelectListItem() { Text = "Managers only", Value = "manager" }; SelectListItem newEmployee = new SelectListItem() { Text = "New staff only", Value = "newStaff" }; ViewBag.Type = new SelectList(new SelectListItem[] { allStaff, manager, newEmployee }, "Value", "Text"); return(View(training)); }
public ActionResult Update(TrainingAccess training) { training.ModuleId = Convert.ToInt32(Request.Form["modules"]); training.Type = Request.Form["Type"]; training.TrainingId = Convert.ToInt32(Request.Form["TrainingId"]); TrainingService trainingService = new TrainingService(); TrainingAccess train = training; trainingService.Update(training); return(RedirectToAction("Index")); }
//Update a training. public ActionResult Update(int id = 0) { TrainingService trainingService = new TrainingService(); List <TrainingAccess> trainings = new List <TrainingAccess>(); TrainingAccess training = new TrainingAccess(); List <ModuleAccess> modules = new List <ModuleAccess>(); ModuleService moduleService = new ModuleService(); modules = moduleService.GetModuleData(); if (id != 0) { Session.Add("trainingId", id); trainings = trainingService.GetTrainingData(); foreach (var item in trainings) { if (item.TrainingId == id) { ViewBag.training = item; training = item; ViewBag.modules = new SelectList(modules, "moduleId", "moduleName", training.ModuleId); SelectListItem allStaff = new SelectListItem() { Text = "Open for all", Value = "allStaff" }; SelectListItem manager = new SelectListItem() { Text = "Managers only", Value = "manager" }; SelectListItem newEmployee = new SelectListItem() { Text = "New staff only", Value = "newStaff" }; ViewBag.Type = new SelectList(new SelectListItem[] { allStaff, manager, newEmployee }, "Value", "Text", item.Type); } } } else if (Session["trainingId"] != null) { id = Convert.ToInt32(Session["trainingId"]); trainings = trainingService.GetTrainingData(); foreach (var item in trainings) { if (item.TrainingId == id) { ViewBag.training = item; training = item; ViewBag.modules = new SelectList(modules, "moduleId", "moduleName", training.ModuleId); SelectListItem allStaff = new SelectListItem() { Text = "Open for all", Value = "allStaff" }; SelectListItem manager = new SelectListItem() { Text = "Managers only", Value = "manager" }; SelectListItem newEmployee = new SelectListItem() { Text = "New staff only", Value = "newStaff" }; ViewBag.Type = new SelectList(new SelectListItem[] { allStaff, manager, newEmployee }, "Value", "Text", item.Type); } } } else { TempData["message"] = "Please selete a training."; } return(View(training)); }