Beispiel #1
0
        public void Add(Module model)
        {
            var loginContext = _auth.GetCurrentUser();

            if (loginContext == null)
            {
                throw new CommonException("登錄已過期", Define.INVALID_TOKEN);
            }

            CaculateCascade(model);

            Repository.Add(model);

            AddDefaultMenus(model);
            //當前登錄使用者的所有角色自動分配模組
            loginContext.Roles.ForEach(u =>
            {
                _revelanceApp.Assign(new AssignReq
                {
                    type    = Define.ROLEMODULE,
                    firstId = u.Id,
                    secIds  = new[] { model.Id }
                });
            });
        }
Beispiel #2
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="org">The org.</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
        public string Add(Org org)
        {
            var loginContext = _auth.GetCurrentUser();

            if (loginContext == null)
            {
                throw new CommonException("登录已过期", Define.INVALID_TOKEN);
            }
            CaculateCascade(org);

            UnitWork.ExecuteWithTransaction(() =>
            {
                UnitWork.Add(org);
                UnitWork.Save();

                //如果当前账号不是SYSTEM,则直接分配
                if (loginContext.User.Account != Define.SYSTEM_USERNAME)
                {
                    _revelanceApp.Assign(new AssignReq
                    {
                        type    = Define.USERORG,
                        firstId = loginContext.User.Id,
                        secIds  = new[] { org.Id }
                    });
                }
            });

            return(org.Id);
        }
Beispiel #3
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="org">The org.</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
        public string Add(Org org)
        {
            var loginContext = _auth.GetCurrentUser();

            if (loginContext == null)
            {
                throw new CommonException("登录已过期", Define.INVALID_TOKEN);
            }
            ChangeModuleCascade(org);

            Repository.Add(org);

            //如果当前账号不是SYSTEM,则直接分配
            var loginUser = _auth.GetCurrentUser();

            if (loginUser.User.Account != Define.SYSTEM_USERNAME)
            {
                _revelanceApp.Assign(new AssignReq
                {
                    type    = Define.USERORG,
                    firstId = loginContext.User.Id,
                    secIds  = new[] { org.Id }
                });
            }

            return(org.Id);
        }
        public void AddOrUpdate(UserView view)
        {
            if (string.IsNullOrEmpty(view.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }
            User user = view;

            if (string.IsNullOrEmpty(view.Id))
            {
                if (UnitWork.IsExist <User> (u => u.Account == view.Account))
                {
                    throw new Exception("用户账号已存在");
                }
                user.CreateTime = DateTime.Now;
                user.Password   = user.Account; //初始密码与账号相同
                UnitWork.Add(user);
                view.Id = user.Id;              //要把保存后的ID存入view
            }
            else
            {
                UnitWork.Update <User> (u => u.Id == view.Id, u => new User {
                    Account = user.Account,
                    BizCode = user.BizCode,
                    Name    = user.Name,
                    Sex     = user.Sex,
                    Status  = user.Status
                });
            }
            UnitWork.Save();
            string[] orgIds = view.OrganizationIds.Split(',').ToArray();

            _revelanceApp.DeleteBy(Define.USERORG, user.Id);
            _revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => user.Id));
        }
Beispiel #5
0
        public void AddOrUpdate(UpdateUserReq request)
        {
            request.ValidationEntity(u => new { u.Account, u.Name, u.OrganizationIds });

            if (string.IsNullOrEmpty(request.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }
            User requser = request;

            requser.CreateId = _auth.GetCurrentUser().User.Id;

            UnitWork.ExecuteWithTransaction(() =>
            {
                if (string.IsNullOrEmpty(request.Id))
                {
                    if (UnitWork.Any <User>(u => u.Account == request.Account))
                    {
                        throw new Exception("用户账号已存在");
                    }

                    if (string.IsNullOrEmpty(requser.Password))
                    {
                        requser.Password = requser.Account;   //如果客户端没提供密码,默认密码同账号
                    }

                    requser.CreateTime = DateTime.Now;

                    UnitWork.Add(requser);
                    request.Id = requser.Id; //要把保存后的ID存入view
                }
                else
                {
                    UnitWork.Update <User>(u => u.Id == request.Id, u => new User
                    {
                        Account = requser.Account,
                        BizCode = requser.BizCode,
                        Name    = requser.Name,
                        Sex     = requser.Sex,
                        Status  = requser.Status
                    });
                    if (!string.IsNullOrEmpty(requser.Password))  //密码为空的时候,不做修改
                    {
                        UnitWork.Update <User>(u => u.Id == request.Id, u => new User
                        {
                            Password = requser.Password
                        });
                    }
                }

                UnitWork.Save();
                string[] orgIds = request.OrganizationIds.Split(',').ToArray();

                _revelanceApp.DeleteBy(Define.USERORG, requser.Id);
                _revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id));
            });
        }
Beispiel #6
0
        public void Add(Module model)
        {
            var loginContext = _auth.GetCurrentUser();

            if (loginContext == null)
            {
                throw new CommonException("登录已过期", Define.INVALID_TOKEN);
            }
            ChangeModuleCascade(model);

            Repository.Add(model);
            //当前登录用户的所有角色自动分配模块
            loginContext.Roles.ForEach(u =>
            {
                _revelanceApp.Assign(new AssignReq
                {
                    type    = Define.ROLEMODULE,
                    firstId = u.Id,
                    secIds  = new[] { model.Id }
                });
            });
        }
Beispiel #7
0
        public void Add(RoleView obj)
        {
            Role role = obj;

            role.CreateTime = DateTime.Now;
            Repository.Add(role);
            obj.Id = role.Id;   //要把保存后的ID存入view

            //如果当前账号不是SYSTEM,则直接分配
            var loginUser = _auth.GetCurrentUser();

            if (loginUser.User.Account != Define.SYSTEM_USERNAME)
            {
                _revelanceApp.Assign(new AssignReq
                {
                    type    = Define.USERROLE,
                    firstId = loginUser.User.Id,
                    secIds  = new[] { role.Id }
                });
            }
        }
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="org">The org.</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
        public string Add(OpenAuth.Repository.Domain.Org org)
        {
            var loginContext = _auth.GetCurrentUser();

            if (loginContext == null)
            {
                throw new CommonException("登录已过期", Define.INVALID_TOKEN);
            }
            ChangeModuleCascade(org);

            Repository.Add(org);

            //当前登录用户自动添加该部门
            _revelanceApp.Assign(new AssignReq
            {
                type    = Define.USERORG,
                firstId = loginContext.User.Id,
                secIds  = new[] { org.Id }
            });

            return(org.Id);
        }
Beispiel #9
0
        /// <summary>
        /// 新增角色,如果當前登錄使用者不是System,則直接把新角色分配給當前登錄使用者
        /// </summary>
        public void Add(RoleView obj)
        {
            UnitWork.ExecuteWithTransaction(() =>
            {
                Role role       = obj;
                role.CreateTime = DateTime.Now;
                UnitWork.Add(role);
                UnitWork.Save();
                obj.Id = role.Id;  //要把儲存后的ID存入view

                //如果當前賬號不是SYSTEM,則直接分配
                var loginUser = _auth.GetCurrentUser();
                if (loginUser.User.Account != Define.SYSTEM_USERNAME)
                {
                    _revelanceApp.Assign(new AssignReq
                    {
                        type    = Define.USERROLE,
                        firstId = loginUser.User.Id,
                        secIds  = new[] { role.Id }
                    });
                }
            });
        }
Beispiel #10
0
 /// <summary>
 /// 更新相应的多对多关系
 /// </summary>
 /// <param name="view"></param>
 private void UpdateRele(RoleView view)
 {
     string[] orgIds = view.OrganizationIds.Split(',').ToArray();
     _revelanceApp.DeleteBy(Define.ROLEORG, view.Id);
     _revelanceApp.Assign(Define.ROLEORG, orgIds.ToLookup(u => view.Id));
 }