public ActionResult EnrollmentsGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Enrollments item) { if (ModelState.IsValid) { try { // Insert here a code to update the item in your model var ret = unitOfWork.EnrollmentsRepo.Find(x => x.Id == item.Id); ret.StudentId = item.StudentId; ret.AvailableCourseId = item.AvailableCourseId; ret.IsDrop = item.IsDrop; unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.EnrollmentsRepo.Fetch(includeProperties: "AvailableCourses,UserDetails"); //if (item.StudentId != null) // model = model.Where(m => m.StudentId == item.StudentId); ViewBag.StudentId = item.StudentId; return(PartialView("_EnrollmentsGridViewPartial", model.ToList())); }
public ActionResult EnrollmentsGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Enrollments item) { // var model = new object[0]; if (ModelState.IsValid) { try { foreach (var i in item.AvailableSubjectIds) { var availableSubjectId = i.ToInt(); var enrolled = new EnrolledSubject() { AvailableSubjectId = availableSubjectId }; enrolled.Grades.Add(new Grades()); item.EnrolledSubject.Add(enrolled); } // Insert here a code to insert the new item in your model item.DateCreated = DateTime.Now; unitOfWork.EnrollmentsRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.EnrollmentsRepo.Fetch(includeProperties: "AvailableCourses,UserDetails"); //if (item.StudentId != null) // model = model.Where(m => m.StudentId == item.StudentId); ViewBag.StudentId = item.StudentId; return(PartialView("_EnrollmentsGridViewPartial", model.ToList())); }