コード例 #1
0
        public async Task <Unit> Handle(RemoveUserRoleCommand request, CancellationToken cancellationToken)
        {
            await _userManagerService.RemoveRole(request.UserId, request.RoleName);

            await _dataContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
コード例 #2
0
        public async Task <Unit> Handle(AddUserRoleCommand command, CancellationToken cancellationToken)
        {
            await _userManagerService.AddRole(command.UserId, command.RoleName);

            await _dataContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(UpdateUserPasswordCommand request, CancellationToken cancellationToken)
        {
            await _userManagerService.UpdatePassword(request.UserId, request.OldPassword, request.NewPassword);

            await _dataContext.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new PasswordChangedEvent(request.UserId, request.OldPassword, request.NewPassword),
                                    cancellationToken);

            _logger.Log(LogLevel.Debug, "PasswordChanged Event Published.");
            return(Unit.Value);
        }
コード例 #4
0
        public async Task <Unit> Handle(UpdateUserInfoCommand command, CancellationToken cancellationToken)
        {
            var result = await _userManager.UpdateProfile(
                userId : command.Id,
                firstName : command.FirstName,
                lastName : command.LastName
                );

            await _dataContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
コード例 #5
0
        public async Task <ApplicationUser> Handle(RegisterUserCommand command, CancellationToken cancellationToken)
        {
            var user = await _userManagerService.CreateUser(new ApplicationUser()
            {
                FirstName     = command.FirstName,
                LastName      = command.LastName,
                UserName      = command.UserName,
                Email         = command.Email,
                SecurityStamp = Guid.NewGuid().ToString()
            }, command.Password);

            await _dataContext.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(
                new UserRegisteredEvent(id : user.Id, email : user.Email, firstName : user.FirstName,
                                        lastName : user.LastName), cancellationToken);

            _logger.Log(LogLevel.Debug, "UserRegistered Event Published.");

            return(user);
        }