private void Apply(ActivityFieldAttached obj)
        {
            if (this.ActivityFields.Any(a => string.Equals(a.Name, obj.FieldName, StringComparison.OrdinalIgnoreCase)))
            {
                throw new DuplicateFieldNameException();
            }

            this.ActivityFields.Add(new ActivityField(obj.ActivityFieldType, obj.FieldName, obj.UnitOfMeasure));
        }
 public async Task Handle(ActivityFieldAttached notification, CancellationToken cancellationToken)
 {
     using (var connection = this._dbConnectionFactory.OpenConnection())
     {
         var activityRepository = new ActivityFieldRepository();
         await activityRepository.AttachFieldToActivityAsync(connection, notification.AggregateId, notification.ActivityFieldType,
                                                             notification.FieldName, notification.UnitOfMeasure);
     }
 }
        public void AddActivityField(ActivityFieldType activityFieldType, string fieldName, string unitOfMeasure)
        {
            if (string.IsNullOrEmpty(fieldName) || fieldName.Length > 255)
            {
                throw new ArgumentException();
            }

            var activityFieldAttachedEvent = new ActivityFieldAttached(this.AggregateId, activityFieldType, fieldName, unitOfMeasure);

            this.RaiseEvent(activityFieldAttachedEvent);
        }