public ICommandResult Handle(RegisterEndpointCommand command) { // Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Dados inválidos. Verifique o preenchimento dos campos e tente novamente.", command.Notifications)); } // Verfica se Serial Number já está cadastrado if (_repository.SerialNumberExists(command.SerialNumber)) { AddNotification("SerialNumber", "Este \"Número Serial\" já está em uso."); return(new GenericCommandResult(false, "Este \"Número Serial\" já está em uso.", command.Notifications)); } // Gera a Entidade var endpoint = new Endpoint( command.SerialNumber, command.MeterModelId, command.MeterNumber, command.MeterFirmwareVersion, command.SwitchState); // Checa as Notificações if (Invalid) { return(new GenericCommandResult(false, "Dados inválidos. Verifique o preenchimento dos campos e tente novamente.", Notifications)); } // Salva as Informações _repository.Save(endpoint); // Retorna as Informações return(new GenericCommandResult(true, "Cadastro realizado com sucesso.", endpoint)); }