Beispiel #1
0
 public bool UserAddEdit([FromBody] UserAddEditDto dto)
 {
     _sysUserSerivce.AddEdit(dto);
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// 添加和编辑用户信息
        /// </summary>
        /// <param name="dto"></param>
        public void AddEdit(UserAddEditDto dto)
        {
            //去前后空格
            dto.UserName = dto.UserName.Trim();
            dto.Email    = dto.Email.Trim();
            long    userId  = 0;
            SysUser sysUser = null;

            if (dto.UserId.HasValue)
            {
                if (dbClint.Queryable <SysUser>().Where(u => u.UserCode == dto.UserCode && u.IsDeleted == false && u.UserId != dto.UserId.Value).Any())
                {
                    throw Oops.Oh(string.Format("用户名[{0}]已经存在!", dto.UserName));
                }
                if (dbClint.Queryable <SysUser>().Where(u => u.Email == dto.Email && u.IsDeleted == false && u.UserId != dto.UserId.Value).Any())
                {
                    throw Oops.Oh(string.Format("邮箱[{0}]已经被使用!", dto.Email));
                }
                sysUser                = _repository.FirstOrDefault(u => u.UserId == dto.UserId.Value);
                sysUser.ModifyDate     = DateTime.Now;
                sysUser.ModifyUserId   = _userManager.UserId;
                sysUser.ModifyUserName = _userManager.UserName;
                userId = sysUser.UserId;
            }
            else
            {
                if (dbClint.Queryable <SysUser>().Where(u => u.UserName == dto.UserName && u.IsDeleted == false).Any())
                {
                    throw Oops.Oh(string.Format("用户名[{0}]已经存在!", dto.UserName));
                }
                if (dbClint.Queryable <SysUser>().Where(u => u.Email == dto.Email && u.IsDeleted == false).Any())
                {
                    throw Oops.Oh(string.Format("邮箱[{0}]已经被使用!", dto.Email));
                }
                sysUser = new SysUser()
                {
                    CreateDate     = DateTime.Now,
                    CreateUserId   = _userManager.UserId,
                    CreateUserName = _userManager.UserName,
                    //Password = EncryptHelper.DESEnCode(dto.Password.Trim(), _auth.PasswordKey),
                    Type      = (int)UserTypeEnum.Normal,
                    IsDeleted = false
                };
            }
            sysUser.UserCode = dto.UserCode;
            sysUser.UserName = dto.UserName;
            sysUser.Email    = dto.Email;
            sysUser.Phone    = dto.Phone;
            sysUser.Status   = dto.Status;
            sysUser.Sex      = dto.Sex;
            sysUser.Qq       = dto.Qq;
            sysUser.Remark   = dto.Remark;

            var result = dbClint.Ado.UseTran(() =>
            {
                if (dto.UserId.HasValue)
                {
                    dbClint.Updateable(sysUser).ExecuteCommand();
                }
                else
                {
                    userId = dbClint.Insertable(sysUser).ExecuteReturnBigIdentity();
                }
                //用户部门
                if (dto.OrgId.HasValue && dto.OrgId > 0)
                {
                    _sysRelevanceService.SetUserOrg(userId, dto.OrgId.Value);
                }
            });

            if (result.IsSuccess == false)
            {
                throw Oops.Oh(result.ErrorMessage);
            }
        }