public ActionResult PersonalInformationGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.PersonalInformations item) { if (ModelState.IsValid) { try { // Insert here a code to update the item in your model unitOfWork.PersonalInformationsRepo.TrackModifiedEntities(m => m.Id == item.Id, item); unitOfWork.PersonalInformationsRepo.Update(item); unitOfWork.Save(); var p = unitOfWork.PersonalInformationsRepo.Find(m => m.Id == item.Id); p.Groups.Clear(); foreach (var i in item.GroupIds) { p.Groups.Add(unitOfWork.GroupsRepo.Find(m => m.Id == i)); } unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.PersonalInformationsRepo.Get(); return(PartialView("_PersonalInformationGridViewPartial", model)); }
public ActionResult PersonalInformationGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.PersonalInformations item) { if (ModelState.IsValid) { try { item.Groups = new List <Groups>(); foreach (var i in item.GroupIds) { item.Groups.Add(unitOfWork.GroupsRepo.Find(m => m.Id == i)); } unitOfWork.PersonalInformationsRepo.Insert(item); unitOfWork.Save(); // Insert here a code to insert the new item in your model } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.PersonalInformationsRepo.Get(); return(PartialView("_PersonalInformationGridViewPartial", model)); }