public async Task <IActionResult> Edit(DynmicRoleViewModel model) { if (string.IsNullOrEmpty(model.NodeSelected)) { ModelState.AddModelError("JsonJSTree", "حداقل باید یک سطح دسترسی انتخاب کنید."); } if (ModelState.IsValid) { var role = await _roleManager.FindByIdAsync(model.Guid.ToString()); if (role == null) { ModelState.AddModelError(string.Empty, "چنین سطحدسترسی در سیستم تعریف نشده است."); } else { role.ActionArray = model.NodeSelected; role.Name = role.Title = model.Title; role.Description = model.Description; role.Enable = model.Enable; var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { await _roleManager.AddOrUpdateRoleClaims(model.Guid, GlobalEnum.DynamicRole, model.NodeSelected); return(RedirectToAction(nameof(Index))); } else { ModelState.AddErrorsFromResult(result); } } } model.JsonJSTree = JsonConvert.SerializeObject(_mvcControllerDiscovery.GetAdminActionInTree(model.NodeSelected)); return(View(model)); }
public async Task <IActionResult> Add(DynmicRoleViewModel model) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(model.NodeSelected)) { var guid = Guid.NewGuid(); var role = new Role { Id = guid, Name = model.Title, Title = model.Title, Enable = model.Enable, Description = model.Description, ActionArray = model.NodeSelected, }; var result = await _roleManager.CreateAsync(role); if (result.Succeeded) { await _roleManager.AddOrUpdateRoleClaims(guid, GlobalEnum.DynamicRole, model.NodeSelected); return(RedirectToAction(nameof(Index))); } else { ModelState.AddErrorsFromResult(result); } } else { ModelState.AddModelError("JsonJSTree", "حداقل باید یک سطح دسترسی انتخاب کنید."); } } return(View(model)); }