public ActionResult UserRolesGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.UserRoles item) { if (ModelState.IsValid) { try { // Insert here a code to update the item in your model var role = unitOfWork.UserRolesRepo.Find(x => x.Id == item.Id); role.Functions.Clear(); foreach (var i in item.Actions.Split(',')) { var action = i.Trim(); role.Functions.Add(unitOfWork.FunctionsRepo.Find(x => x.Action == action)); } role.Name = item.Name; role.Description = item.Description; unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UserRolesRepo.Get(); return(PartialView("_UserRolesGridViewPartial", model)); }
public ActionResult UserRolesGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.UserRoles item) { if (ModelState.IsValid) { try { // Insert here a code to insert the new item in your model List <Functions> functions = new List <Functions>(); foreach (var i in item.Actions.Split(',')) { var action = i.Trim(); functions.Add(unitOfWork.FunctionsRepo.Find(x => x.Action == action)); } item.Id = Guid.NewGuid().ToString(); unitOfWork.UserRolesRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UserRolesRepo.Get(); return(PartialView("_UserRolesGridViewPartial", model)); }
public ActionResult UserRolesGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.UserRoles item, [ModelBinder(typeof(DevExpressEditorsBinder))] List <string> actionName) { //var model = new object[0]; if (ModelState.IsValid) { try { item.Id = Guid.NewGuid().ToString(); foreach (var i in actionName) { item.UserRolesInActions.Add(new UserRolesInActions() { RoleId = item.Id, Action = i }); } unitOfWork.UserRolesRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UserRolesRepo.Get(includeProperties: "UserRolesInActions"); return(PartialView("_UserRolesGridViewPartial", model)); }
public ActionResult UserRolesGridViewPartialUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.UserRoles item, [ModelBinder(typeof(DevExpressEditorsBinder))] List <string> actionName) { if (ModelState.IsValid) { try { var userRole = unitOfWork.UserRolesRepo.Find(m => m.Id == item.Id, includeProperties: "UserRolesInActions"); userRole.Name = item.Name; userRole.Description = item.Description; userRole.UserRolesInActions.Clear(); foreach (var i in actionName) { userRole.UserRolesInActions.Add(new UserRolesInActions() { RoleId = item.Id, Action = i, UserRoles = userRole }); } unitOfWork.Save(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } var model = unitOfWork.UserRolesRepo.Get(includeProperties: "UserRolesInActions"); return(PartialView("_UserRolesGridViewPartial", model)); }
public ActionResult Index() { var roles = new Models.UserRoles(); roles.Id = Guid.NewGuid().ToString(); roles.Name = ""; ModelDb db = new ModelDb(); db.UserRoles.Add(roles); db.SaveChanges(); return(View()); }