Пример #1
0
        public Task<HttpResponseMessage> Post([FromBody]dynamic body)
        {
            var command = new RegisterUserCommand(
                email: (string)body.email,
                username: (string)body.username,
                password: (string)body.password
            );

            var user = _service.Register(command);
            return CreateResponse(HttpStatusCode.Created, command);
        }
Пример #2
0
        public User Register(RegisterUserCommand command)
        {
            // Cria a instâcia do usuário
            var user = new User(command.Email, command.Username, command.Password);

            // Tenta registrar o usuário
            user.Register();

            // Chama o commit
            if(Commit())
            {
                // Dispara o evento de usuário registrado
                DomainEvent.Raise(new OnUserRegisteredEvent(user));

                // Retorna o usuário
                return user;
            }

            // Se não comitou, retorna nulo
            return null;
        }