示例#1
0
        /// <summary>
        /// 设置用户部门(批量设置)
        /// </summary>
        /// <param name="userIds">用户主键,多个用逗号隔开</param>
        /// <param name="depIds">部门id,多个用逗号隔开</param>
        public bool SetDepartmentBatch(string userIds, string depIds)
        {
            List <UserDepartmentEntity> dep_addList    = new List <UserDepartmentEntity>(); //需要插入部门的sql语句集合
            List <UserDepartmentEntity> dep_deleteList = new List <UserDepartmentEntity>(); //需要删除部门的sql语句集合

            string[] str_userid = userIds.Trim(',').Split(',');
            string[] str_dep    = depIds.Trim(',').Split(',');

            UserDepartmentEntity userdepdelete = null;
            UserDepartmentEntity userdepadd    = null;

            for (int i = 0; i < str_userid.Length; i++)
            {
                //批量设置先删除当前用户的所有部门
                userdepdelete        = new UserDepartmentEntity();
                userdepdelete.UserId = Convert.ToInt32(str_userid[i]);
                dep_deleteList.Add(userdepdelete);

                if (!string.IsNullOrEmpty(depIds))
                {
                    //再添加设置的部门
                    for (int j = 0; j < str_dep.Length; j++)
                    {
                        userdepadd              = new UserDepartmentEntity();
                        userdepadd.UserId       = Convert.ToInt32(str_userid[i]);
                        userdepadd.DepartmentId = Convert.ToInt32(str_dep[j]);
                        dep_addList.Add(userdepadd);
                    }
                }
            }
            return(dal.SetDepartmentBatch(dep_addList, dep_deleteList));
        }
示例#2
0
        public async Task <BaseResult <bool> > AddAdmin(UserAdminInfo userAdminInfo)
        {
            //判断数据库中有没有邮箱(user_email)和电话(user_phone),如果存在则不能添加,提示错误
            int count = await userRepository.CountAsync(c => c.user_email == userAdminInfo.user_email || c.user_phone == userAdminInfo.user_phone);

            if (count >= 1)
            {
                return(new BaseResult <bool>(1003, false));
            }

            //同步添加三个数据库 User和UserInfo和部门表
            UserEntity userEntity = new UserEntity();

            userEntity.user_pwd    = CommonUtil.Md5(userAdminInfo.user_pwd);
            userEntity.user_name   = userAdminInfo.user_name;
            userEntity.full_name   = userAdminInfo.full_name;
            userEntity.user_code   = CommonUtil.ReadRandom("#", 4, 9);
            userEntity.user_email  = userAdminInfo.user_email;
            userEntity.user_phone  = userAdminInfo.user_phone;
            userEntity.user_gender = userAdminInfo.user_gender;
            userEntity.user_ip     = httpContextUtil.getRemoteIp();
            userEntity.source_type = (int)SourceStatus.admin;
            //todo 不知道为什么访问始终有问题,不能添加新的
            userEntity.user_activation = (int)DisableStatus.disable_false;
            userEntity.user_visit      = (int)DisableStatus.disable_false;

            UserInfoEntity userInfoEntity = new UserInfoEntity();

            userInfoEntity.user_id = userEntity.user_id;

            var isUserTrue = await userRepository.AddAsync(userEntity, false);

            var isUserInfoTrue = await userInfoRepository.AddAsync(userInfoEntity, false);

            if (userAdminInfo.department_id.Count > 0)
            {
                List <UserDepartmentEntity> userDepartmentEntitys = new List <UserDepartmentEntity>();
                foreach (string deparmentId in userAdminInfo.department_id)
                {
                    if (deparmentId != null)
                    {
                        UserDepartmentEntity userDepartmentEntity = new UserDepartmentEntity();
                        userDepartmentEntity.user_id       = userEntity.user_id;
                        userDepartmentEntity.department_id = deparmentId;
                        userDepartmentEntitys.Add(userDepartmentEntity);
                    }
                }
                var isUserDepartmentTrue = await userDepartmentRepository.AddListAsync(userDepartmentEntitys, false);
            }
            if (unitOfWork.SaveCommit())
            {
                return(new BaseResult <bool>(200, true));
            }
            return(new BaseResult <bool>(201, false));
        }
示例#3
0
        public async Task <BaseResult <bool> > UpdateAdmin(UserAdminInfo userAdminInfo, string user_id)
        {
            //逻辑:登录的用户如果=admin,则可以修改admin,否则不能修改admin
            if (userAdminInfo.user_id.Equals("66dbea2b41dd47a1a81eef2e5dc2af0e"))
            {
                if (!user_id.Equals("66dbea2b41dd47a1a81eef2e5dc2af0e"))
                {
                    return(new BaseResult <bool>(1007, false));
                }
            }

            //判断数据库中有没有用户名(login_name)邮箱(user_email)和电话(user_phone),如果存在则不能添加,提示错误
            int count = await userRepository.CountAsync(c => c.user_id != userAdminInfo.user_id && (c.user_email == userAdminInfo.user_email || c.user_phone == userAdminInfo.user_phone));

            if (count >= 1)
            {
                return(new BaseResult <bool>(1003, false));
            }

            //同步修改两个数据库,用户表和用户部门表
            UserEntity userEntity = new UserEntity();

            userEntity.user_id     = userAdminInfo.user_id;
            userEntity.user_name   = userAdminInfo.user_name;
            userEntity.full_name   = userAdminInfo.full_name;
            userEntity.user_email  = userAdminInfo.user_email;
            userEntity.user_phone  = userAdminInfo.user_phone;
            userEntity.user_gender = userAdminInfo.user_gender;
            var isTrue = await userRepository.UpdateAsync(userEntity, false, true, c => c.user_name, c => c.full_name, c => c.user_email, c => c.user_phone, c => c.user_gender);

            //先根据用户Id删除用户部门表里面所有的用户信息然后再添加
            var isDeleteUserDetrue = await userDepartmentRepository.DeleteByUserId(userAdminInfo.user_id);

            if (userAdminInfo.department_id.Count > 0)
            {
                List <UserDepartmentEntity> userDepartmentEntitys = new List <UserDepartmentEntity>();
                foreach (string deparmentId in userAdminInfo.department_id)
                {
                    if (deparmentId != null)
                    {
                        UserDepartmentEntity userDepartmentEntity = new UserDepartmentEntity();
                        userDepartmentEntity.user_id       = userEntity.user_id;
                        userDepartmentEntity.department_id = deparmentId;
                        userDepartmentEntitys.Add(userDepartmentEntity);
                    }
                }
                var isUserDepartmentTrue = await userDepartmentRepository.AddListAsync(userDepartmentEntitys, false);
            }
            if (unitOfWork.SaveCommit())
            {
                return(new BaseResult <bool>(200, true));
            }
            return(new BaseResult <bool>(201, false));
        }
示例#4
0
        /// <summary>
        /// 设置用户部门(单个用户)
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="depIds">部门id,多个用逗号隔开</param>
        public bool SetDepartmentSingle(int userId, string depIds)
        {
            DataTable dt_user_dep_old = new DepartmentBLL().GetDepartmentByUserId(userId);  //用户之前拥有的部门
            List <UserDepartmentEntity> dep_addList    = new List <UserDepartmentEntity>(); //需要插入部门的sql语句集合
            List <UserDepartmentEntity> dep_deleteList = new List <UserDepartmentEntity>(); //需要删除部门的sql语句集合

            string[] str_dep = depIds.Trim(',').Split(',');                                 //传过来用户勾选的部门(有去勾的也有新勾选的)

            UserDepartmentEntity userdepdelete = null;
            UserDepartmentEntity userdepadd    = null;

            for (int i = 0; i < dt_user_dep_old.Rows.Count; i++)
            {
                //等于-1说明用户去掉勾选了某个部门 需要删除
                if (Array.IndexOf(str_dep, dt_user_dep_old.Rows[i]["departmentid"].ToString()) == -1)
                {
                    userdepdelete = new UserDepartmentEntity();
                    userdepdelete.DepartmentId = Convert.ToInt32(dt_user_dep_old.Rows[i]["departmentid"].ToString());
                    userdepdelete.UserId       = userId;
                    dep_deleteList.Add(userdepdelete);
                }
            }

            if (!string.IsNullOrEmpty(depIds))
            {
                for (int j = 0; j < str_dep.Length; j++)
                {
                    //等于0那么原来的部门没有 是用户新勾选的
                    if (dt_user_dep_old.Select("departmentid = '" + str_dep[j] + "'").Length == 0)
                    {
                        userdepadd              = new UserDepartmentEntity();
                        userdepadd.UserId       = userId;
                        userdepadd.DepartmentId = Convert.ToInt32(str_dep[j]);
                        dep_addList.Add(userdepadd);
                    }
                }
            }
            if (dep_addList.Count == 0 && dep_deleteList.Count == 0)
            {
                return(true);
            }
            else
            {
                return(dal.SetDepartmentSingle(dep_addList, dep_deleteList));
            }
        }
示例#5
0
 public UserDepartmentEventEntity(UserDepartment userDepartment)
 {
     OldValue = new UserDepartmentEntity();
     NewValue = new UserDepartmentEntity();
     Mapper.Map(userDepartment, OldValue);
 }