Exemple #1
0
        public static ChangeRecord EvaluatePropertyChange(this ChangeRequest changeRequest, object item, string property, Enum newValue, bool isRelated = false, string comment = "")
        {
            var oldValue = item.GetPropertyValue(property);

            if (oldValue == null && newValue == null)
            {
                return(null);
            }

            if (!(oldValue is Enum) || !newValue.Equals(( Enum )oldValue))
            {
                var changeRecord = new ChangeRecord()
                {
                    OldValue   = (( Enum )oldValue).ConvertToInt().ToString(),
                    NewValue   = newValue.ConvertToInt().ToString(),
                    Action     = ChangeRecordAction.Update,
                    IsRejected = false,
                    WasApplied = false,
                    Property   = property,
                    Comment    = comment
                };

                if (isRelated && item is IEntity)
                {
                    var entity = ( IEntity )item;

                    changeRecord.RelatedEntityId     = entity.Id;
                    changeRecord.RelatedEntityTypeId = EntityTypeCache.Get(entity.GetType()).Id;
                }

                changeRequest.ChangeRecords.Add(changeRecord);
                return(changeRecord);
            }
            return(null);
        }