Esempio n. 1
0
        public ActionResult Edit(Guid?id, SysRole collection, IEnumerable <Guid> sysControllerSysActionsId)
        {
            var area = (string)Request.RequestContext.RouteData.DataTokens["area"];

            if (!ModelState.IsValid)
            {
                Edit(id);
                return(View(collection));
            }

            if (id.HasValue)
            {
                //清除原有数据
                _sysRoleSysControllerSysActionService.Delete(a => a.SysRoleId.Equals(id.Value) && a.SysControllerSysAction.SysController.SysArea.AreaName.Equals(area));
            }

            _sysRoleService.Save(id, collection);

            if (sysControllerSysActionsId != null)
            {
                foreach (var sysControllerSysActionId in sysControllerSysActionsId)
                {
                    _sysRoleSysControllerSysActionService.Save(null, new SysRoleSysControllerSysAction
                    {
                        SysRoleId = collection.Id,
                        SysControllerSysActionId = sysControllerSysActionId
                    });
                }
            }

            _unitOfWork.Commit();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public async Task <ActionResult> Edit(string id, SysRole collection, IEnumerable <string> sysControllerSysActionsId)
        {
            if (string.IsNullOrEmpty(collection.RoleName))
            {
                ModelState.AddModelError("RoleName", "请填写角色名称");
            }

            if (!ModelState.IsValid)
            {
                Edit(id);
                return(View(collection));
            }

            collection.Name = Guid.NewGuid().ToString();

            if (!string.IsNullOrEmpty(id))
            {
                //清除原有数据
                _sysRoleSysControllerSysActionService.Delete(a => a.RoleId.Equals(id));
            }

            _iSysRoleService.Save(id, collection);

            if (sysControllerSysActionsId != null)
            {
                foreach (var sysControllerSysActionId in sysControllerSysActionsId)
                {
                    _sysRoleSysControllerSysActionService.Save(null, new SysRoleSysControllerSysAction
                    {
                        RoleId = collection.Id,
                        SysControllerSysActionId = sysControllerSysActionId
                    });
                }
            }

            await _unitOfWork.CommitAsync();

            return(new EditSuccessResult(id));
        }