Example #1
0
        public virtual void When(IAttributeStateCreated e)
        {
            ThrowOnWrongEvent(e);
            this.AttributeName = e.AttributeName;

            this.OrganizationId = e.OrganizationId;

            this.Description = e.Description;

            this.IsMandatory = (e.IsMandatory != null && e.IsMandatory.HasValue) ? e.IsMandatory.Value : default(bool);

            this.AttributeValueType = e.AttributeValueType;

            this.AttributeValueLength = e.AttributeValueLength;

            this.IsList = (e.IsList != null && e.IsList.HasValue) ? e.IsList.Value : default(bool);

            this.FieldName = e.FieldName;

            this.ReferenceId = e.ReferenceId;

            this.Active = (e.Active != null && e.Active.HasValue) ? e.Active.Value : default(bool);

            this.Deleted = false;

            this.CreatedBy = e.CreatedBy;
            this.CreatedAt = e.CreatedAt;

            foreach (IAttributeValueStateCreated innerEvent in e.AttributeValueEvents)
            {
                IAttributeValueState innerState = this.AttributeValues.Get(innerEvent.GlobalId.Value, true);
                innerState.Mutate(innerEvent);
            }
            foreach (IAttributeAliasStateCreated innerEvent in e.AttributeAliasEvents)
            {
                IAttributeAliasState innerState = this.Aliases.Get(innerEvent.GlobalId.Code, true);
                innerState.Mutate(innerEvent);
            }
        }
Example #2
0
        public virtual void When(IAttributeStateMergePatched e)
        {
            ThrowOnWrongEvent(e);

            if (e.Name == null)
            {
                if (e.IsPropertyNameRemoved)
                {
                    this.Name = default(string);
                }
            }
            else
            {
                this.Name = e.Name;
            }

            if (e.OrganizationId == null)
            {
                if (e.IsPropertyOrganizationIdRemoved)
                {
                    this.OrganizationId = default(string);
                }
            }
            else
            {
                this.OrganizationId = e.OrganizationId;
            }

            if (e.Description == null)
            {
                if (e.IsPropertyDescriptionRemoved)
                {
                    this.Description = default(string);
                }
            }
            else
            {
                this.Description = e.Description;
            }

            if (e.IsMandatory == null)
            {
                if (e.IsPropertyIsMandatoryRemoved)
                {
                    this.IsMandatory = default(bool);
                }
            }
            else
            {
                this.IsMandatory = (e.IsMandatory != null && e.IsMandatory.HasValue) ? e.IsMandatory.Value : default(bool);
            }

            if (e.IsInstanceAttribute == null)
            {
                if (e.IsPropertyIsInstanceAttributeRemoved)
                {
                    this.IsInstanceAttribute = default(bool);
                }
            }
            else
            {
                this.IsInstanceAttribute = (e.IsInstanceAttribute != null && e.IsInstanceAttribute.HasValue) ? e.IsInstanceAttribute.Value : default(bool);
            }

            if (e.AttributeValueType == null)
            {
                if (e.IsPropertyAttributeValueTypeRemoved)
                {
                    this.AttributeValueType = default(string);
                }
            }
            else
            {
                this.AttributeValueType = e.AttributeValueType;
            }

            if (e.AttributeValueLength == null)
            {
                if (e.IsPropertyAttributeValueLengthRemoved)
                {
                    this.AttributeValueLength = default(int?);
                }
            }
            else
            {
                this.AttributeValueLength = e.AttributeValueLength;
            }

            if (e.IsList == null)
            {
                if (e.IsPropertyIsListRemoved)
                {
                    this.IsList = default(bool);
                }
            }
            else
            {
                this.IsList = (e.IsList != null && e.IsList.HasValue) ? e.IsList.Value : default(bool);
            }

            if (e.FieldName == null)
            {
                if (e.IsPropertyFieldNameRemoved)
                {
                    this.FieldName = default(string);
                }
            }
            else
            {
                this.FieldName = e.FieldName;
            }

            if (e.ReferenceId == null)
            {
                if (e.IsPropertyReferenceIdRemoved)
                {
                    this.ReferenceId = default(string);
                }
            }
            else
            {
                this.ReferenceId = e.ReferenceId;
            }

            if (e.Active == null)
            {
                if (e.IsPropertyActiveRemoved)
                {
                    this.Active = default(bool);
                }
            }
            else
            {
                this.Active = (e.Active != null && e.Active.HasValue) ? e.Active.Value : default(bool);
            }


            this.UpdatedBy = e.CreatedBy;
            this.UpdatedAt = e.CreatedAt;


            foreach (IAttributeValueStateEvent innerEvent in e.AttributeValueEvents)
            {
                IAttributeValueState innerState = this.AttributeValues.Get(innerEvent.GlobalId.Value);

                innerState.Mutate(innerEvent);
                var removed = innerEvent as IAttributeValueStateRemoved;
                if (removed != null)
                {
                    this.AttributeValues.Remove(innerState);
                }
            }
        }