private static void ValidateCommand(IUserIdAndNameCommand command) { var specification = new UserIdAndNameSpecification(); if (!specification.IsSatisfiedBy(command)) { throw new ArgumentException(specification.GetReasonsForDissatisfactionSeparatedWithNewLine()); } }
public void Execute(RemoveUserAccountCommand command) { var specification = new UserIdAndNameSpecification(); if (!specification.IsSatisfiedBy(command)) { throw new ArgumentException(specification.GetReasonsForDissatisfactionSeparatedWithNewLine()); } User user = repository.GetUser(command.UserId); AccountType type = Map(command.Type); if (user.HasAccount(type, command.Name)) { user.RemoveUserAccount(type, command.Name); repository.SaveChanges(); auditTrail.AddEntry(command.UserId, user.Name, command.Name, "Käyttäjätunnus poistettu"); } }
public void Execute(UpdateUserAccountCommand command) { var specification = new UserIdAndNameSpecification(); if (!specification.IsSatisfiedBy(command)) { throw new ArgumentException(specification.GetReasonsForDissatisfactionSeparatedWithNewLine()); } AccountType type = Map(command.Type); User user = repository.GetUser(command.UserId); Account account = repository.GetUserAccount(command.UserId, type); ThrowIfAccountNameIsAlreadyAssigned(type, account.Name, command.Name); account.Name = command.Name; repository.SaveChanges(); auditTrail.AddEntry(command.UserId, user.Name, command.Name, "Käyttäjätunnus päivitetty"); }