Ejemplo n.º 1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <StatusResult> AddAsync(UserAddInputDto input)
        {
            if (_userRepository.Select.Any(o => o.UserName == input.UserName || o.Phone == input.Phone))
            {
                return(new StatusResult("账号或手机号已存在"));
            }

            var password = MySecurity.MD5(MySecurity.MD5Lower("123456"));
            var entity   = input.Adapt <UserEntity>();

            entity.Id       = Snowflake.GenId();
            entity.Password = password;
            var res = await _userRepository.InsertOrUpdateAsync(entity);

            var userRoles = input.RoleIds.Select(o => new UserRoleEntity()
            {
                RoleId = o.key,
                UserId = entity.Id,
                Id     = Snowflake.GenId()
            });
            await _userRoleRepository.InsertAsync(userRoles);

            return(new StatusResult(res == null, "添加失败"));
        }
Ejemplo n.º 2
0
 public async Task <StatusResult> Add(UserAddInputDto input)
 {
     return(await _userService.AddAsync(input));
 }