Example #1
0
        public async Task <IResponseOutput> AddAsync(UserAddInput input)
        {
            if (input.Password.IsNull())
            {
                input.Password = "******";
            }

            input.Password = MD5Encrypt.Encrypt32(input.Password);

            var entity = _mapper.Map <UserEntity>(input);
            var user   = await _userRepository.InsertAsync(entity);

            if (!(user?.Id > 0))
            {
                return(ResponseOutput.NotOk());
            }

            if (input.RoleIds != null && input.RoleIds.Any())
            {
                var roles = input.RoleIds.Select(d => new UserRoleEntity(user.Id, d));
                await _userRoleRepository.InsertAsync(roles);
            }

            return(ResponseOutput.Ok());
        }
Example #2
0
        public async Task <IResultModel> AddAsync(UserAddInput input)
        {
            if (input.Password.IsNull())
            {
                input.Password = "******";
            }
            input.Password = MD5Encrypt.Encrypt32(input.Password);
            var entity = _mapper.Map <UserEntity>(input);

            entity.IsDeleted       = false;
            entity.ModifiedTime    = entity.CreatedTime = DateTime.UtcNow;
            entity.CreatedUserId   = entity.ModifiedUserId = _user.Id;
            entity.CreatedUserName = entity.ModifiedUserName = _user.Name;
            using (var _dbConnection = ConnectionFactory.CreateConnection(_dbOption.Value))
            {
                IDbTransaction transaction = _dbConnection.BeginTransaction();
                try
                {
                    var _id = await _dbConnection.InsertAsync <UserEntity>(entity, transaction);

                    if (!(_id > 0))
                    {
                        return(ResultModel.Failed());
                    }
                    UserRoleEntity _userRoleEntity;
                    if (input.RoleIds != null && input.RoleIds.Any())
                    {
                        foreach (var _ro in input.RoleIds)
                        {
                            _userRoleEntity = new UserRoleEntity
                            {
                                RoleId          = _ro,
                                UserId          = _id,
                                CreatedTime     = DateTime.UtcNow,
                                CreatedUserId   = _user.Id,
                                CreatedUserName = _user.Name
                            };
                            await _dbConnection.InsertAsync <UserRoleEntity>(_userRoleEntity, transaction);
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
            return(ResultModel.Success());
        }
Example #3
0
 public async Task <IResponseOutput> Add(UserAddInput input)
 {
     return(await _userServices.AddAsync(input));
 }
Example #4
0
 public async Task <IResultModel> Add(UserAddInput input)
 {
     return(await _userServices.AddAsync(input));
 }
Example #5
0
 public async Task Add([FromBody] UserAddInput input) => await _userAppService.Add(input);