public ActionResult PermiteeGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Permitees item) { if (ModelState.IsValid) { try { unitOfWork.PermiteesRepo.Update(item); unitOfWork.Save(); var permitees = unitOfWork.PermiteesRepo.Find(m => m.Id == item.Id, includeProperties: "Quarries"); permitees.Quarries.Clear(); foreach (var i in item.QuarrySites) { var id = Convert.ToInt32(i); permitees.Quarries.Add(unitOfWork.QuarriesRepo.Find(m => m.Id == id)); } unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; ViewData["Model"] = item; } var model = unitOfWork.PermiteesRepo.Get(includeProperties: "Quarries"); return(PartialView("_PermiteeGridViewPartial", model)); }
public ActionResult PermiteeGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.Permitees item) { if (ModelState.IsValid) { try { // Insert here a code to insert the new item in your model foreach (var i in item.QuarrySites) { var id = Convert.ToInt32(i); item.Quarries.Add(unitOfWork.QuarriesRepo.Find(m => m.Id == id)); } item.EntryBy = User.Identity.GetUserId(); item.LastEditedBy = User.Identity.GetUserId(); unitOfWork.PermiteesRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; ViewData["Model"] = item; } var model = unitOfWork.PermiteesRepo.Get(); return(PartialView("_PermiteeGridViewPartial", model)); }