Пример #1
0
        public ResponseResult <bool> SaveRoleMenuPermissions(RoleMenuPermissionViewModel roleMenuPermissionVm)
        {
            var roleMenuList       = roleMenuPermissionVm.RoleMenuViewModel;
            var rolePermissionList = roleMenuPermissionVm.RolePermissionViewModel;

            if ((roleMenuList == null || roleMenuList.Count <= 0) && (rolePermissionList == null || rolePermissionList.Count <= 0))
            {
                return(ResponseResult <bool> .GenSuccessResponse(false));
            }
            var roleId = roleMenuList.FirstOrDefault().RoleId;

            if (roleId <= 0)
            {
                return(ResponseResult <bool> .GenSuccessResponse(false));
            }

            _roleMenuService       = GetService <RoleMenuService>();
            _rolePermissionService = GetService <RolePermissionService>();

            using (TransactionScope ts = new TransactionScope())
            {
                var result = false;
                try
                {
                    //先删除角色菜单记录,再添加新的
                    result = _roleMenuService.DeleteRoleMenus((int)roleId);
                    foreach (var roleMenu in roleMenuList)
                    {
                        result &= _roleMenuService.Add(roleMenu) > 0;
                    }

                    //先删除角色操作记录,在添加新的
                    result &= _rolePermissionService.DeleteRolePermissions((int)roleId);
                    foreach (var rolePermission in rolePermissionList)
                    {
                        result &= _rolePermissionService.Add(rolePermission) > 0;
                    }

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    result = false;
                    ts.Dispose();
                }

                return(ResponseResult <bool> .GenSuccessResponse(result));
            }
        }
Пример #2
0
        public IActionResult Add([FromRoute] string roleId, [FromBody] AddRolePermissionRequest addGroupRolePermission)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result result = _groupRolePermissionService.Add(roleId, addGroupRolePermission);

            if (result.Failure)
            {
                ModelState.AddErrors(result);
                return(BadRequest(ModelState));
            }

            return(Ok(new EmptyResult()));
        }
Пример #3
0
        public IHttpActionResult Post([FromBody] RolePermissionDTO rolePermission)
        {
            var rolePermissionAdded = _rolePermissionService.Add(rolePermission);

            return(CreatedAtRoute("DefaultApi", new { id = rolePermission.RolePermissionId }, rolePermissionAdded));
        }
 public Task <IResultModel> Add(RolePermissionAddModel model)
 {
     return(_service.Add(model));
 }