mercredi 25 mars 2015

CQRS applying command handler business logic

I am apllying sample CQSR to an application. And I am confused about applying logical rules.



public class UserCommandHandler : ICommandHandler<CreateUserCommand>
{
private readonly IUserRepository repository;

public UserCommandHandler(IUserRepository repository)
{
this.repository = repository;
}

public void Handle(CreateUserCommand command)
{
User user = new User();
user.Username = command.Username;
user.Password = command.Password;
user.Email = command.Email;
user.CreteDate = DateTime.Now;
// Rules
var isUserDuplicated = repository.GetAll().Any(u => u.Username == command.Username);
var isEmailDuplicated = repository.GetAll().Any(u => u.Email == command.Email);

repository.Add(user);
repository.Save();
}
}


1- Where can I apply business rules to chack if username duplicated or email duplicated.


2- My command handler is void. So how can I send duplication notification to users?


Aucun commentaire:

Enregistrer un commentaire