public async Task ExecuteAsync(UpdateUserImageCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.UserId, token); user.UpdateUserImage(message.ImagePath, message.FileName); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(ChangeOnlineStatusCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.UserId, token); user.ChangeOnlineStatus(message.Status); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(SuspendUserCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.Id, token); user.SuspendUser(message.LockoutEnd, message.Reason); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(UpdateEmailCommand message, CancellationToken token) { var user = await _repository.GetAsync(message.UserId, token); user.ChangeEmail(message.Email); await _repository.UpdateAsync(user, token); }
public async Task ExecuteAsync(UpdateNameCommand message, CancellationToken token) { var user = await _repository.GetAsync(message.UserId, token); user.ChangeName(message.FirstName, message.LastName); await _repository.UpdateAsync(user, token); }
public async Task ExecuteAsync(ChangeCountryCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.Id, token); user.ChangeCountryAdmin(message.Country.ToUpperInvariant()); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(TransferMoneyToPointsCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.UserId, token); var t = new BuyPointsTransaction(message.Amount, message.PayPalTransactionId); user.MakeTransaction(t); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(UserRemoveCourseCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.UserId, token); var course = await _courseRepository.LoadAsync(message.Name, token); user.RemoveCourse(course); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(BecomeTutorCommand message, CancellationToken token) { var user = await _userRepository.LoadAsync(message.UserId, token); if (user.Tutor != null) { throw new ArgumentException("user is already a tutor"); } user.BecomeTutor(message.Bio, message.Price, message.Description, message.FirstName, message.LastName); await _tutorRepository.AddAsync(user.Tutor, token); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(CashOutCommand message, CancellationToken token) { var balance = await _userRepository.UserBalanceAsync(message.UserId, token); if (balance < 1000) { throw new InvalidOperationException("user doesn't have enough money"); } var user = await _userRepository.LoadAsync(message.UserId, token); user.CashOutMoney(/*message.Amount*/); await _userRepository.UpdateAsync(user, token); }
public async Task ExecuteAsync(UpdateUserBalanceCommand message, CancellationToken token) { foreach (var id in message.UsersIds) { //TODO: we can do it better var user = await _userRepository.LoadAsync(id, token); var balance = await _transactionRepository.GetBalanceAsync(id, token); var score = (int)(await _transactionRepository.GetUserScoreAsync(id, token)); user.UpdateUserBalance(balance, score); await _userRepository.UpdateAsync(user, token); } }
public async Task ExecuteAsync(UpdatePhoneCommand message, CancellationToken token) { var user = await _repository.GetAsync(message.UserId, token); if (user == null) { throw new NotFoundException(); } if (string.IsNullOrEmpty(user.Country)) { throw new NullReferenceException(); } user.PhoneNumber = message.NewPhone; await _repository.UpdateAsync(user, token); }