public async Task<ActionResult> Create(Create roleViewModel) { if (ModelState.IsValid) { var role = new IdentityRole(roleViewModel.RoleName); var roleresult = await RoleManager.CreateAsync(role); if (!roleresult.Succeeded) { ModelState.AddModelError("", roleresult.Errors.First()); return View(roleViewModel); } roleViewModel.RoleId = role.Id; ResourceOperationPermission rop = new ResourceOperationPermission(); rop.SaveCurrentRolePermission(roleViewModel); return RedirectToAction("Index").WithSuccess("新增群組成功"); } return View(roleViewModel); }
/// <summary> /// 儲存設定的權限 /// </summary> /// <param name="viewModel">新增的ViewModel</param> public void SaveCurrentRolePermission(Create viewModel) { // 因為是新增,因此不會有任何目前已有的權限 SaveRolePermissionToTable(viewModel.RoleId, viewModel.ResourceOperation, new List<RolesOperationPermission>()); }
// // GET: /Roles/Create public ActionResult Create() { var resourceOperation = ResourceCollection.ResourceOperation.DistinctBy(x => x.ResourceName) .ToList(); resourceOperation.ForEach(x => x.Operation = ResourceOperationEnum.None); var viewModel = new Create() { ResourceOperation = resourceOperation }; return View(viewModel); }