Esempio n. 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 }
                });
            });
        }
Esempio n. 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);

            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(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));
            });
        }
Esempio n. 4
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 }
                    });
                }
            });
        }