public void Handle(ApprovalCreated message)
 {
     using (var dataStoreContext = new SqlDataStoreContext())
     {
         var manteqApprovalRequest = new ManteqApprovalRequest();
         manteqApprovalRequest.ApprovalRequestId = message.Id;
         manteqApprovalRequest.PatientName       = message.PatientName;
         manteqApprovalRequest.PatientId         = message.PatientId;
         manteqApprovalRequest.DateOfBirth       = message.DateOfBirth;
         dataStoreContext.ManteqApprovalRequests.Add(manteqApprovalRequest);
         dataStoreContext.SaveChanges();
     }
 }
Example #2
0
        public void SaveEvents(Guid aggregateId, IEnumerable <Event> events, int expectedVersion)
        {
            List <EventDescriptor> eventDescriptors;

            // try to get event descriptors list for given aggregate id
            // otherwise -> create empty dictionary
            if (!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                eventDescriptors = new List <EventDescriptor>();
                _current.Add(aggregateId, eventDescriptors);
            }
            // check whether latest event version matches current aggregate version
            // otherwise -> throw exception
            else if (eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1)
            {
                throw new ConcurrencyException();
            }
            var i = expectedVersion;

            // iterate through current aggregate events increasing version with each processed event
            foreach (var @event in events)
            {
                i++;
                @event.Version = i;

                // push event to the event descriptors list for current aggregate
                eventDescriptors.Add(new EventDescriptor(aggregateId, @event, i));
                //save event to database
                using (var dataStoreContext = new SqlDataStoreContext())
                {
                    var manteqEvent = new ManteqEvent();
                    manteqEvent.AggregateId = aggregateId;
                    manteqEvent.Version     = @event.Version;
                    manteqEvent.Data        = SerializeObject(@event);
                    dataStoreContext.ManteqEvents.Add(manteqEvent);
                    dataStoreContext.SaveChanges();
                }

                // publish current event to the bus for further processing by subscribers
                _publisher.Publish(@event);
            }
        }
Example #3
0
        public void SaveEvents(Guid aggregateId, IEnumerable<Event> events, int expectedVersion)
        {
            List<EventDescriptor> eventDescriptors;

            // try to get event descriptors list for given aggregate id
            // otherwise -> create empty dictionary
            if(!_current.TryGetValue(aggregateId, out eventDescriptors))
            {
                eventDescriptors = new List<EventDescriptor>();
                _current.Add(aggregateId,eventDescriptors);
            }
            // check whether latest event version matches current aggregate version
            // otherwise -> throw exception
            else if(eventDescriptors[eventDescriptors.Count - 1].Version != expectedVersion && expectedVersion != -1)
            {
                throw new ConcurrencyException();
            }
            var i = expectedVersion;

            // iterate through current aggregate events increasing version with each processed event
            foreach (var @event in events)
            {
                i++;
                @event.Version = i;

                // push event to the event descriptors list for current aggregate
                eventDescriptors.Add(new EventDescriptor(aggregateId,@event,i));
                //save event to database
                using (var dataStoreContext = new SqlDataStoreContext())
                {
                    var manteqEvent = new ManteqEvent();
                    manteqEvent.AggregateId = aggregateId;
                    manteqEvent.Version = @event.Version;
                    manteqEvent.Data = SerializeObject(@event);
                    dataStoreContext.ManteqEvents.Add(manteqEvent);
                    dataStoreContext.SaveChanges();
                }

                // publish current event to the bus for further processing by subscribers
                _publisher.Publish(@event);
            }
        }