//Domain-Eventhandlers
 private void Apply(CustomerCreatedEvent @event)
 {
     Id            = @event.AggregateId;
     _customerName = new CustomerName(@event.CustomerName);
     _address      = new Address(@event.Street, @event.StreetNumber, @event.PostalCode, @event.City);
     _phoneNumber  = new PhoneNumber(@event.PhoneNumber);
 }
            public static CustomerDomainModel CreateNewInstance(
                Guid id,
                int version,
                string firstName,
                string lastName,
                string idCard,
                string idNumber,
                DateTime dob,
                string email,
                string phone,
                string street,
                string zip,
                string hausnumber,
                string city,
                string state)
            {
                var @event = new CustomerCreatedEvent
                {
                    AggregateId = id,
                    Version     = version,
                    Person      = new Person(firstName, lastName, dob, idCard, idNumber),
                    Contact     = new Contact(email, phone),
                    Address     = new Address(street, zip, hausnumber, city, state),
                    State       = State.Open
                };
                var ba = new CustomerDomainModel();

                ba.ApplyChange(@event);
                return(ba);
            }
Exemple #3
0
 internal void Apply(CustomerCreatedEvent ev)
 {
     Id         = ev.AggregateId;
     Email      = ev.Email;
     Address    = ev.Address;
     PostalCode = ev.PostalCode;
     Residence  = ev.Residence;
 }
        private async Task Handle(CustomerCreatedEvent @event)
        {
            await Repository.Add(@event.CustomerId, new JObject(
                                     new JProperty("CustomerId", @event.CustomerId),
                                     new JProperty("Name", @event.Name)));

            // We should check all articles to update customerids with their name
        }
Exemple #5
0
 private void HandleCustomerCreatedEvent(CustomerCreatedEvent evt)
 {
     this.Id         = (Guid)evt.AggregateRootKey;
     this.Password   = evt.Password;
     this.Name       = evt.Name;
     this.Email      = evt.Email;
     this.ReferralId = evt.ReferralId;
 }
        public void PublishCustomerCreatedEvent(CustomerCreatedEvent @event)
        {
            var message = JsonConvert.SerializeObject(@event);
            var headers = new Dictionary <string, object>();

            headers.Add("type", "CustomerCreatedEvent");

            _publisher.Publish(message: message, routingKey: "customer.events", headers);
        }
Exemple #7
0
        public CustomerCreatedEvent CreateCustomer(NewCustomerCommand cust)
        {
            CustomerCreatedEvent ee = new CustomerCreatedEvent {
                CustomerId = cust.CustomerId, LastName = cust.LastName, FirstName = cust.FirstName
            };

            apply(ee);
            return(ee);
        }
 public void Handle(CustomerCreatedEvent e)
 {
     this.Id            = e.AggregateId;
     this.Version       = e.Version;
     this.Person        = e.Person;
     this.Contact       = e.Contact;
     this.Address       = e.Address;
     this.CustomerState = e.State;
 }
Exemple #9
0
        public static ResultsWithEvents Create(String name, Money creditLimit)
        {
            Customer            customer             = new Customer(name, creditLimit);
            var                 customerCreatedEvent = new CustomerCreatedEvent(customer.Name, customer.CreditLimit);
            List <IDomainEvent> eventList            = new List <IDomainEvent>();

            eventList.Add(customerCreatedEvent);
            return(new ResultsWithEvents(customer, eventList));
        }
        public async Task HandleAsync(CreateCustomerCommand command)
        {
            var customer = new Customer(command.Name);

            //  await _mongoRepository.AddAsync(customer);

            var @event = new CustomerCreatedEvent(customer.Id);

            await _eventDispatcher.PublishAsync(@event);
        }
Exemple #11
0
        public static async Task sendMessage(IEvents myevent)
        {
            QueueClient          client = new QueueClient(connectionString, "testqueue");
            CustomerCreatedEvent e      = myevent as CustomerCreatedEvent;
            var     jsondata            = JsonConvert.SerializeObject(e);
            Message msg = new Message();

            byte[] bytedata = Encoding.ASCII.GetBytes(jsondata);
            msg.Body = bytedata;
            await client.SendAsync(msg);
        }
Exemple #12
0
        public async Task <IActionResult> PostAsync([FromBody] string value)
        {
            var customerCreatedEvent = new CustomerCreatedEvent
            {
                Name = "Customer X",
                Id   = new Random(131365).Next(0, 100)
            };

            await _pubSubServiceHelper.Publish(customerCreatedEvent).ConfigureAwait(true);

            return(Ok());
        }
        public async Task <ActionResult <Customer> > Post([FromBody] Customer value)
        {
            CustomerCreatedEvent customerCreatedEvent = new CustomerCreatedEvent()
            {
                Id      = value.Id,
                Name    = value.Name,
                Address = value.Address,
                Phone   = value.Phone
            };

            var cust = await eventHandler.ListenForCustomerCreatedEvent(customerCreatedEvent);

            return(Ok(cust));
        }
        public static void SendEvent(CustomerCreatedEvent cce)
        {
            TopicClient client     = new TopicClient("Endpoint=sb://customerservicens.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=jzBPEK8pBZI2LOktxiqi97yaFsm3AJ37+JunB0uI8Sc=", "customercreated");
            var         jsonstring = JsonConvert.SerializeObject(cce);

            byte[] bytedata = Encoding.ASCII.GetBytes(jsonstring);


            Message msg = new Message();

            msg.Body = bytedata;

            client.SendAsync(msg).GetAwaiter().GetResult();
        }
Exemple #15
0
        public async Task Handle(CreateCustomerCommand command, CancellationToken cancellationToken)
        {
            var customerCreatedEvent = new CustomerCreatedEvent
            {
                Address   = command.Address,
                Name      = command.Name,
                Phone     = command.Phone,
                CreatedAt = DateTime.Now
            };

            // Insert event to Command Db
            await _eventSources.InserEvent(customerCreatedEvent, cancellationToken);

            await _kafkaProducer.Send(customerCreatedEvent, AppGlobalTopic.PosTopic);
        }
        public async Task <Customer> CreateCustomer(Customer customer)
        {
            await _customerDao.CreateCustomer(customer);

            // create OrderCreatedEvent
            var @event = new CustomerCreatedEvent
                         (
                id: Guid.NewGuid(),
                timeStamp: DateTime.Now,
                customerId: customer.CustomerId,
                availableCredit: customer.AvailableCredit
                         );

            // publish event
            _publisher.PublishCustomerCreatedEvent(@event);

            return(customer);
        }
Exemple #17
0
        public async Task ExecuteAsync(HookType type, IDomainEntityContext <Customer> context, CancellationToken cancellationToken)
        {
            switch (context.EditMode)
            {
            case EditMode.Create:
                await context.AddEventAsync(CustomerCreatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);

                break;

            case EditMode.Update:
                await context.AddEventAsync(CustomerUpdatedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);

                break;

            case EditMode.Delete:
                await context.AddEventAsync(CustomerDeletedEvent.Create(_correlationIdProvider.Id, context.Entity.Id, _currentUser.Id), cancellationToken);

                break;
            }
        }
        public void HandleCustomerCreated(ICustomerCommand command)
        {
            CustomerCreatedCommand c = command as CustomerCreatedCommand;

            UserIdentifier       u    = new UserIdentifier(c.Userid);
            FirstNameValueObject f    = new FirstNameValueObject(c.Firstname);
            CustomerEntity       cust = new CustomerEntity(u, f, c.Firstname, c.Age, c.City, 10);

            Users us = cust.GetCustomerModelfromEntity();

            //if (_repo.GetUserbyID(c.Userid) != null) {
            _repo.NewUser(us);
            //}

            CustomerCreatedEvent e = new CustomerCreatedEvent(c.Userid, c.Firstname, c.Lastname, c.City);

            ServiceBusQueueStore.SendEvent(e);

            //save the customer
            // raise the event
        }
Exemple #19
0
 public void Apply(CustomerCreatedEvent aggregateEvent)
 {
 }
//
//        public void Handle(CustomerCreatedEvent args)
//        {
//            SendMessage(args.Customer).ConfigureAwait(false);
//        }

        public async Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
        {
            var customerDTO = mapper.Map <CustomerDTO>(notification.Customer);

            await  SendMessage(customerDTO);
        }
Exemple #21
0
 public IActionResult CustomerCreatedEvent([FromBody] CustomerCreatedEvent @event)
 {
     return(Ok());
 }
Exemple #22
0
 public async Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
 {
     await _mediator.SendCommand(new NotifyNewUserCommand(notification.AggregateId, notification.Name, notification.Email)).ConfigureAwait(false);
 }
 public async Task Handle(CustomerCreatedEvent @event)
 {
     // check if customer exists otherwise add it to database
     Console.WriteLine("CustomerCreatedEvent");
     await Task.Delay(100);
 }
Exemple #24
0
 //Domain-Eventhandlers
 private void Apply(CustomerCreatedEvent @event)
 {
     Id = @event.AggregateId;
     // we don't need to keep any other state here.
 }