Esempio n. 1
0
        public async Task Save(UserSaveInputDto saveDto)
        {
            var user = _mapper.Map <SysUser>(saveDto);

            if (user.ID < 1)
            {
                if (await _userRepository.ExistAsync(x => x.Account == user.Account))
                {
                    throw new BusinessException(new ErrorModel(HttpStatusCode.Forbidden, "用户已存在"));
                }

                user.ID       = IdGenerater.GetNextId();
                user.Salt     = SecurityHelper.GenerateRandomCode(5);
                user.Password = HashHelper.GetHashedString(HashType.MD5, user.Password, user.Salt);
                await _usrManager.AddUser(user);
            }
            else
            {
                await _userRepository.UpdateAsync(user,
                                                  x => x.Name,
                                                  x => x.DeptId,
                                                  x => x.Sex,
                                                  x => x.Phone,
                                                  x => x.Email,
                                                  x => x.Birthday,
                                                  x => x.Status);
            }
        }
Esempio n. 2
0
        public async Task <AppSrvResult <long> > Add(UserSaveInputDto saveDto)
        {
            if (await _userRepository.ExistAsync(x => x.Account == saveDto.Account))
            {
                return(Problem(HttpStatusCode.BadRequest, "账号已经存在"));
            }

            var user = _mapper.Map <SysUser>(saveDto);

            user.ID       = IdGenerater.GetNextId();
            user.Salt     = SecurityHelper.GenerateRandomCode(5);
            user.Password = HashHelper.GetHashedString(HashType.MD5, user.Password, user.Salt);
            await _usrManager.AddUser(user);

            return(user.ID);
        }