Beispiel #1
0
        public async Task <MessageModel <string> > Assign([FromBody] AssignView assignView)
        {
            var data = new MessageModel <string>();


            if (assignView.rid > 0)
            {
                data.success = true;

                var roleModulePermissions = await _roleModulePermissionServices.Query(d => d.RoleId == assignView.rid);

                var remove = roleModulePermissions.Where(d => !assignView.pids.Contains(d.PermissionId.ObjToInt())).Select(c => (object)c.Id);
                data.success &= remove.Any() ? await _roleModulePermissionServices.DeleteByIds(remove.ToArray()) : true;

                foreach (var item in assignView.pids)
                {
                    var rmpitem  = roleModulePermissions.Where(d => d.PermissionId == item);
                    var moduleid = (await _permissionServices.Query(p => p.Id == item)).FirstOrDefault()?.Mid;
                    if (!rmpitem.Any())
                    {
                        RoleModulePermission roleModulePermission = new RoleModulePermission()
                        {
                            IsDeleted    = false,
                            RoleId       = assignView.rid,
                            ModuleId     = moduleid.ObjToInt(),
                            PermissionId = item,
                        };


                        roleModulePermission.CreateId = _user.ID;
                        roleModulePermission.CreateBy = _user.Name;

                        data.success &= (await _roleModulePermissionServices.Add(roleModulePermission)) > 0;
                    }
                    else
                    {
                        foreach (var role in rmpitem)
                        {
                            if (!role.ModuleId.Equals(moduleid))
                            {
                                role.ModuleId = moduleid.Value;
                                await _roleModulePermissionServices.Update(role, new List <string> {
                                    "ModuleId"
                                });
                            }
                        }
                    }
                }

                if (data.success)
                {
                    _requirement.Permissions.Clear();
                    data.response = "";
                    data.msg      = "保存成功";
                }
            }


            return(data);
        }
Beispiel #2
0
        public async Task <MessageModel <string> > Put([FromBody] RoleModulePermission request)
        {
            var data = new MessageModel <string>();

            if (request.Id > 0)
            {
                data.success = await _roleModulePermissionServices.Update(request);

                if (data.success)
                {
                    data.msg      = "更新成功";
                    data.response = request?.Id.ObjToString();
                }
            }

            return(data);
        }