public ActionResult TrainerUpdate(TrainerEntryVm trainerEntryVm) { HttpPostedFileBase file = Request.Files["Logo"]; if (file == null) { ModelState.AddModelError("Image", "Upload a Image to Update!!"); } else { trainerEntryVm.Image = ConvertToBytes(file); } trainerEntryVm.Organizations = manager.GetOrganizationsById(trainerEntryVm.OrganizationId); trainerEntryVm.Courses = manager.GetCoursesById(trainerEntryVm.CourseId); var trainer = Mapper.Map <Trainer>(trainerEntryVm); if (ModelState.IsValid) { bool isUpdated = manager.UpdateTrainer(trainer); if (isUpdated) { //TrainerEntryVm trainerVm = new TrainerEntryVm(); //trainerVm.OrganizationSelectListItems = GetSelectListItem(); //trainerVm.CourseSelectListItems = GetCourseListItem(); //return PartialView("~\\Views\\Shared\\UpdateTrainer.cshtml", trainerVm); var data = trainer.Name; return(Json(data, JsonRequestBehavior.AllowGet)); } } trainerEntryVm.OrganizationSelectListItems = GetSelectListItem(); trainerEntryVm.CourseSelectListItems = GetCourseListItem(); return(PartialView("~\\Views\\Shared\\UpdateTrainer.cshtml", trainerEntryVm)); }
//Load Trainer Entry Form public ActionResult Entry() { var model = new TrainerEntryVm(); model.OrganizationList = GetOrganizationList(); model.CountryList = GetCountryList(); return(View(model)); }
// GET: Student public ActionResult TrainerEntry() { TrainerEntryVm trainerEntryVm = new TrainerEntryVm(); trainerEntryVm.OrganizationSelectListItems = GetOrganizationListItem(); trainerEntryVm.CourseSelectListItems = GetCourseListItem(); return(View(trainerEntryVm)); }
public ActionResult Edit(TrainerEntryVm model) { if (ModelState.IsValid) { var trainer = Mapper.Map <Trainer>(model); bool isUpdate = _trainerManager.Update(trainer); if (isUpdate) { return(RedirectToAction("Index")); } } return(View()); }
//public ActionResult Entry(TrainerEntryVm model, HttpPostedFileBase Image) public ActionResult Entry(TrainerEntryVm model) { if (ModelState.IsValid) { //if (Image != null && Image.ContentLength > 0) //{ // model.Image = new byte[Image.ContentLength]; // Image.InputStream.Read(model.Image, 0, Image.ContentLength); //} var trainer = Mapper.Map <Trainer>(model); bool isAdded = _trainerManager.Add(trainer); if (isAdded) { return(RedirectToAction("Index")); } } return(RedirectToAction("Entry")); }
public ActionResult TrainerUpdate(TrainerEntryVm trainerEntryVm) { HttpPostedFileBase file = Request.Files["Logo"]; trainerEntryVm.Image = ConvertToBytes(file); var trainer = Mapper.Map <Trainer>(trainerEntryVm); if (ModelState.IsValid) { bool isUpdated = trainerManager.UpdateTrainer(trainer); if (isUpdated) { TrainerEntryVm trainerVm = new TrainerEntryVm(); trainerVm.OrganizationSelectListItems = GetOrganizationListItem(); trainerVm.CourseSelectListItems = GetCourseListItem(); return(PartialView("~\\Views\\Shared\\UpdateTrainer.cshtml", trainerVm)); } } return(Json(new { status = "failure", formErrors = ModelState.Select(kvp => new { key = kvp.Key, errors = kvp.Value.Errors.Select(e => e.ErrorMessage) }) })); }
public ActionResult TrainerEntry(TrainerEntryVm trainerEntryVm) { if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files["Logo"]; trainerEntryVm.Image = ConvertToBytes(file); trainerEntryVm.OrganizationSelectListItems = GetOrganizationListItem(); trainerEntryVm.CourseSelectListItems = GetCourseListItem(); var trainer = Mapper.Map <Trainer>(trainerEntryVm); var organization = trainerManager.GetOrganizationsById(trainerEntryVm.OrganizationId); var course = trainerManager.GetCoursesById(trainerEntryVm.CourseId); trainer.Organizations = organization.ToList(); trainer.Courses = course.ToList(); bool isSaved = trainerManager.SaveStudent(trainer); if (isSaved) { return(View(trainerEntryVm)); } } return(View(trainerEntryVm)); }