/// <summary>
        /// 添加或修改菜单
        /// </summary>
        /// <param name="model"></param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public ActionResult Save(MenuInputDto model, string appid)
        {
            model.ParentId = model.ParentId == 0 ? null : model.ParentId;
            if (string.IsNullOrEmpty(model.IconUrl) || !model.IconUrl.Contains("/"))
            {
                model.IconUrl = null;
            }

            Menu m = MenuBll.GetById(model.Id);

            if (m == null)
            {
                if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
                {
                    ClientApp app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                    app.Menus.Add(model.Mapper <Menu>());
                    bool saved = ClientAppBll.UpdateEntitySaved(app);
                    return(ResultData(null, saved, saved ? "添加成功" : "添加失败"));
                }

                var menu = MenuBll.AddEntitySaved(model.Mapper <Menu>());
                return(menu != null?ResultData(menu, true, "添加成功") : ResultData(null, false, "添加失败"));
            }

            Mapper.Map(model, m);
            bool b = MenuBll.UpdateEntitySaved(m);

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
        /// <summary>
        /// 添加或修改用户组
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="GroupName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid">appid</param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string GroupName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            UserGroup group = UserGroupBll.GetById(Id);

            if (group != null)
            {
                //修改
                if (UserGroupBll.Any(a => a.GroupName.Equals(GroupName) && !a.GroupName.Equals(group.GroupName)))
                {
                    return(ResultData(null, false, $"{GroupName} 用户组已经存在!"));
                }
                group.GroupName = GroupName;
                group.ParentId  = ParentId;
                bool b = UserGroupBll.UpdateEntitySaved(@group);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }
            //添加
            if (UserGroupBll.Any(a => a.GroupName.Equals(GroupName)))
            {
                return(ResultData(null, false, $"{GroupName} 用户组已经存在!"));
            }
            group = new UserGroup {
                GroupName = GroupName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.UserGroup.Add(group);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "用户组添加成功!" : "用户组添加失败!"));
            }
            group = UserGroupBll.AddEntitySaved(group);
            return(@group != null?ResultData(@group, true, "用户组添加成功!") : ResultData(null, false, "用户组添加失败!"));
        }
Example #3
0
        /// <summary>
        /// 修改子系统信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name">新名字</param>
        /// <returns></returns>
        public ActionResult Update(int id, string name)
        {
            ClientApp app = ClientAppBll.GetById(id);

            if (app != null)
            {
                if (ClientAppBll.Any(a => a.AppName.Equals(name) && !a.AppName.Equals(app.AppName)))
                {
                    return(ResultData(null, false, $"{name} 应用已经存在!"));
                }

                app.AppName = name;
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            return(ResultData(null, false, "未找到该应用程序!"));
        }
Example #4
0
        /// <summary>
        /// 添加客户端子系统
        /// </summary>
        /// <param name="name">子系统名字</param>
        /// <returns></returns>
        public ActionResult Add(string name, string domain)
        {
            if (ClientAppBll.Any(a => a.AppName.Equals(name)))
            {
                return(ResultData(null, false, $"{name} 应用已经存在!"));
            }

            string    appid = Guid.NewGuid().ToString().MDString();
            ClientApp app   = new ClientApp()
            {
                AppName = name, Domain = domain, AppId = appid, AppSecret = appid.MDString(ConfigurationManager.AppSettings["BaiduAK"])
            };

            app = ClientAppBll.AddEntitySaved(app);
            if (app != null)
            {
                return(ResultData(app, true, "应用程序添加成功!"));
            }

            return(ResultData(null, false, "应用程序添加失败!"));
        }
Example #5
0
        /// <summary>
        /// 添加或修改角色
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="RoleName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid">appid</param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string RoleName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            Role role = RoleBll.GetById(Id);

            if (role != null)
            {
                //修改
                if (RoleBll.Any(a => a.RoleName.Equals(RoleName) && !a.RoleName.Equals(role.RoleName)))
                {
                    return(ResultData(null, false, $"{RoleName} 角色已经存在!"));
                }

                role.RoleName = RoleName;
                role.ParentId = ParentId;
                bool b = RoleBll.UpdateEntitySaved(role);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            //添加
            if (RoleBll.Any(a => a.RoleName.Equals(RoleName)))
            {
                return(ResultData(null, false, $"{RoleName} 角色已经存在!"));
            }

            role = new Role()
            {
                RoleName = RoleName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.Roles.Add(role);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "角色添加成功!" : "角色添加失败!"));
            }

            role = RoleBll.AddEntitySaved(role);
            return(role != null?ResultData(role, true, "角色添加成功!") : ResultData(null, false, "角色添加失败!"));
        }
Example #6
0
        /// <summary>
        /// 添加或修改权限
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="PermissionName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string PermissionName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            Permission permission = PermissionBll.GetById(Id);

            if (permission != null)
            {
                //修改
                if (PermissionBll.Any(a => a.PermissionName.Equals(PermissionName) && !a.PermissionName.Equals(permission.PermissionName)))
                {
                    return(ResultData(null, false, $"{PermissionName} 权限已经存在!"));
                }

                permission.PermissionName = PermissionName;
                permission.ParentId       = ParentId;
                bool b = PermissionBll.UpdateEntitySaved(permission);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            //添加
            if (PermissionBll.Any(a => a.PermissionName.Equals(PermissionName)))
            {
                return(ResultData(null, false, $"{PermissionName} 权限已经存在!"));
            }

            permission = new Permission {
                PermissionName = PermissionName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.Permissions.Add(permission);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "权限添加成功!" : "权限添加失败!"));
            }

            permission = PermissionBll.AddEntitySaved(permission);
            return(permission != null?ResultData(permission, true, "权限添加成功!") : ResultData(null, false, "权限添加失败!"));
        }