public async Task <bool> Handle(ChangeUserPassworkCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetByIdAsync(request.Id); if (user == null) { await _bus.RaiseEvent(new DomainNotification(request.Id.ToString(), "用户不存在"), cancellationToken); return(false); } user.UserPassword = request.NewPassword.ToMd5(); await _userRepository.UpdateAsync(user); if (await Commit()) { var key = GirvsEntityCacheDefaults <User> .ByIdCacheKey.Create(user.Id.ToString()); await _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken); await _bus.RaiseEvent(new RemoveCacheListEvent(GirvsEntityCacheDefaults <User> .ListCacheKey.Create()), cancellationToken); } return(true); }
public async Task ChangeUserPassword(Guid userId, [FromForm] ChangeUserPassworkViewModel model) { var command = new ChangeUserPassworkCommand(userId, model.NewPassword); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage); } }