Пример #1
0
        public void Add(SysUserView view)
        {
            if (string.IsNullOrEmpty(view.OrganizationIds))
            {
                throw new Exception("请为用户分配机构");
            }

            SysUser user = view;

            if (Repository.IsExist(u => u.Account == view.Account))
            {
                throw new Exception("账号已存在");
            }
            if (Repository.IsExist(u => u.Name == view.Name))
            {
                throw new Exception("用户名已存在");
            }

            user.Password = Encryption.Encrypt(user.Password); //密码加密
            Repository.Add(user);
            view.Id = user.Id;                                 //要把保存后的ID存入view
            UnitWork.Save();
            int[] orgIds = Array.ConvertAll(view.OrganizationIds.Split(','), int.Parse);

            _revelanceApp.DeleteBy(Define.USERORG, user.Id.Value);
            _revelanceApp.AddRelevance(Define.USERORG, orgIds.ToLookup(u => user.Id.Value));
        }
Пример #2
0
 /// <summary>
 /// 更新相应的多对多关系
 /// </summary>
 /// <param name="obj"></param>
 private void UpdateRole(SysRoleView obj)
 {
     int[] orgIds = Array.ConvertAll(obj.OrganizationIds.Split(','), int.Parse);
     _revelanceApp.DeleteBy(Define.ROLEORG, obj.Id.Value);
     _revelanceApp.AddRelevance(Define.ROLEORG, orgIds.ToLookup(u => obj.Id.Value));
 }