Esempio n. 1
0
        public async Task <MessageModel <string> > Post([FromBody] Permission permission)
        {
            var data = new MessageModel <string>();

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

            var id = (await _permissionServices.Add(permission));

            data.success = id > 0;
            if (data.success)
            {
                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
Esempio n. 2
0
        public async Task <MessageModel <string> > Post([FromBody] Permission permission)
        {
            //var data = new MessageModel<string>();

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

            var id = (await _permissionServices.Add(permission));

            //data.success = id > 0;
            //if (data.success)
            //{
            //    data.response = id.ObjToString();
            //    data.msg = "添加成功";
            //}


            return(id > 0 ? Success(id.ObjToString(), "添加成功") : Failed("添加失败"));
        }
Esempio n. 3
0
        private async Task SavePermissionTreeAsync(List <Permission> permissionsTree, List <PM> pms, int permissionId = 0)
        {
            var parendId = permissionId;

            foreach (var item in permissionsTree)
            {
                PM pm = new PM();
                // 保留原始主键id
                pm.PidOld = item.Id;
                pm.MidOld = (item.Module?.Id).ObjToInt();

                var mid = 0;
                // 接口
                if (item.Module != null)
                {
                    var moduleModel = (await _moduleServices.Query(d => d.LinkUrl == item.Module.LinkUrl)).FirstOrDefault();
                    if (moduleModel != null)
                    {
                        mid = moduleModel.Id;
                    }
                    else
                    {
                        mid = await _moduleServices.Add(item.Module);
                    }
                    pm.MidNew = mid;
                    Console.WriteLine($"Moudle Added:{item.Module.Name}");
                }
                // 菜单
                if (item != null)
                {
                    var permissionModel = (await _permissionServices.Query(d => d.Name == item.Name && d.Pid == item.Pid && d.Mid == item.Mid)).FirstOrDefault();
                    item.Pid = parendId;
                    item.Mid = mid;
                    if (permissionModel != null)
                    {
                        permissionId = permissionModel.Id;
                    }
                    else
                    {
                        permissionId = await _permissionServices.Add(item);
                    }

                    pm.PidNew = permissionId;
                    Console.WriteLine($"Permission Added:{item.Name}");
                }
                pms.Add(pm);

                await SavePermissionTreeAsync(item.Children, pms, permissionId);
            }
        }
Esempio n. 4
0
        public async Task <MessageModel <string> > Post([FromBody] Permission permission)
        {
            var data = new MessageModel <string>();

            var id = (await _permissionServices.Add(permission));

            data.success = id > 0;
            if (data.success)
            {
                data.msg  = "添加成功";
                data.data = id.ObjToString();
            }

            return(data);
        }
        public async Task <MessageModel <string> > Post([FromBody] Permission request)
        {
            var data = new MessageModel <string>();

            var id = await _permissionServices.Add(request);

            data.success = id > 0;

            if (data.success)
            {
                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
        /// <summary>
        /// 添加权限菜单
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <ActionResult> AddPermissionInfo(string param)
        {
            JsonResponse result = new JsonResponse();

            try
            {
                PermissionEntity entity = JsonConvert.DeserializeObject <PermissionEntity>(param);
                entity.CreationTime = DateTime.Now;
                var res = await _permissionServices.Add(entity);

                await _logServices.WriteSystemLog(LoginUser.Id, "添加权限菜单", string.Format("信息={0},结果:{1}", param, res));
            }
            catch (Exception ex)
            {
                await _logServices.WriteExceptionLog(LoginUser.Id, "添加权限菜单", ex.ToString());

                result.code = ResponseCode.Fail;
                result.msg  = "添加菜单失败," + ex.ToString();
            }
            return(Json(result));
        }
Esempio n. 7
0
        public async Task <MessageModel <string> > DataMigrateFromOld2New()
        {
            var data = new MessageModel <string>()
            {
                success = true, msg = ""
            };

            if (_env.IsDevelopment())
            {
                try
                {
                    // 获取权限集合数据
                    var rmps = await _roleModulePermissionServices.GetRMPMaps();

                    // 当然,你可以做个where查询
                    //rmps = rmps.Where(d => d.ModuleId > 88).ToList();

                    // 开启事务,保证数据一致性
                    _unitOfWork.BeginTran();

                    var rid   = 0;
                    var pid   = 0;
                    var mid   = 0;
                    var rpmid = 0;

                    // 注意信息的完整性,不要重复添加,确保主库没有要添加的数据
                    foreach (var item in rmps)
                    {
                        // 角色信息,防止重复添加,做了判断
                        if (item.Role != null)
                        {
                            var isExit = (await _roleServices.Query(d => d.Name == item.Role.Name && d.IsDeleted == false)).FirstOrDefault();
                            if (isExit == null)
                            {
                                rid = await _roleServices.Add(item.Role);

                                Console.WriteLine($"Role Added:{item.Role.Name}");
                            }
                            else
                            {
                                rid = isExit.Id;
                            }
                        }

                        // 菜单
                        if (item.Permission != null)
                        {
                            pid = await _permissionServices.Add(item.Permission);

                            Console.WriteLine($"Permission Added:{item.Permission.Name}");
                        }

                        // 接口
                        if (item.Module != null)
                        {
                            mid = await _moduleServices.Add(item.Module);

                            Console.WriteLine($"Module Added:{item.Module.LinkUrl}");
                        }

                        // 关系
                        if (rid > 0 && pid > 0 && mid > 0)
                        {
                            rpmid = await _roleModulePermissionServices.Add(new RoleModulePermission()
                            {
                                IsDeleted    = false,
                                CreateTime   = DateTime.Now,
                                ModifyTime   = DateTime.Now,
                                ModuleId     = mid,
                                PermissionId = pid,
                                RoleId       = rid,
                            });

                            Console.WriteLine($"RMP Added:{rpmid}");
                        }
                    }


                    _unitOfWork.CommitTran();

                    data.success = true;
                    data.msg     = "导入成功!";
                }
                catch (Exception)
                {
                    _unitOfWork.RollbackTran();
                }
            }
            else
            {
                data.success = false;
                data.msg     = "当前不处于开发模式,代码生成不可用!";
            }

            return(data);
        }