Exemple #1
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);
                }
            }
        }
Exemple #2
0
 public virtual void Remove(IAttributeValueState state)
 {
     this._removedAttributeValueStates.Add(state.GlobalId, state);
 }
Exemple #3
0
 public void AddToSave(IAttributeValueState state)
 {
     throw new NotSupportedException();
 }
Exemple #4
0
 public virtual void AddToSave(IAttributeValueState state)
 {
     this._loadedAttributeValueStates[state.GlobalId] = state;
 }
        public static TCreateAttributeValue ToCreateAttributeValue <TCreateAttributeValue>(this IAttributeValueState state)
            where TCreateAttributeValue : ICreateAttributeValue, new()
        {
            var cmd = new TCreateAttributeValue();

            cmd.Value = state.Value;
            cmd.AttributeValueName = state.AttributeValueName;
            cmd.Description        = state.Description;
            cmd.ReferenceId        = state.ReferenceId;
            cmd.Active             = ((IAttributeValueStateProperties)state).Active;
            cmd.AttributeId        = state.AttributeId;
            return(cmd);
        }
        public static TMergePatchAttributeValue ToMergePatchAttributeValue <TMergePatchAttributeValue>(this IAttributeValueState state)
            where TMergePatchAttributeValue : IMergePatchAttributeValue, new()
        {
            var cmd = new TMergePatchAttributeValue();

            cmd.Value = state.Value;
            cmd.AttributeValueName = state.AttributeValueName;
            cmd.Description        = state.Description;
            cmd.ReferenceId        = state.ReferenceId;
            cmd.Active             = ((IAttributeValueStateProperties)state).Active;
            cmd.AttributeId        = state.AttributeId;

            if (state.AttributeValueName == null)
            {
                cmd.IsPropertyAttributeValueNameRemoved = true;
            }
            if (state.Description == null)
            {
                cmd.IsPropertyDescriptionRemoved = true;
            }
            if (state.ReferenceId == null)
            {
                cmd.IsPropertyReferenceIdRemoved = true;
            }
            return(cmd);
        }
        public static TRemoveAttributeValue ToRemoveAttributeValue <TRemoveAttributeValue>(this IAttributeValueState state)
            where TRemoveAttributeValue : IRemoveAttributeValue, new()
        {
            var cmd = new TRemoveAttributeValue();

            cmd.Value = state.Value;
            return(cmd);
        }
        public static IAttributeValueCommand ToCreateOrMergePatchAttributeValue <TCreateAttributeValue, TMergePatchAttributeValue>(this IAttributeValueState state)
            where TCreateAttributeValue : ICreateAttributeValue, new()
            where TMergePatchAttributeValue : IMergePatchAttributeValue, new()
        {
            bool bUnsaved = ((IAttributeValueState)state).IsUnsaved;

            if (bUnsaved)
            {
                return(state.ToCreateAttributeValue <TCreateAttributeValue>());
            }
            else
            {
                return(state.ToMergePatchAttributeValue <TMergePatchAttributeValue>());
            }
        }