Example #1
0
 public void SetOriginalValue(string propertyName, object value)
 {
     if (!OriginalValues.ContainsKey(propertyName))
     {
         OriginalValues.Add(propertyName, value);
     }
 }
 // Captures the original value for a property that is changing.
 internal void RecordOriginalValue(string propertyName, object oldValue, object newValue)
 {
     if (IsChangeTrackingEnabled && _objectState != ObjectState.Added)
     {
         if (OriginalValues.ContainsKey(propertyName))
         {
             if (object.Equals(OriginalValues[propertyName], newValue))
             {
                 OriginalValues.Remove(propertyName);
                 if (OriginalValues.Count == 0 && _objectState == ObjectState.Modified)
                 {
                     State = ObjectState.Unchanged;
                     ModifiedProperties.Clear();
                 }
                 else
                 {
                     ModifiedProperties.Remove(propertyName);
                 }
             }
         }
         else
         {
             OriginalValues[propertyName] = oldValue;
         }
     }
 }
 // Captures the original value for a property that is changing.
 //moved internal to public scope
 public void RecordOriginalValue(string propertyName, object value)
 {
     if (_changeTrackingEnabled && _objectState != ObjectState.Added)
     {
         if (!OriginalValues.ContainsKey(propertyName))
         {
             OriginalValues[propertyName] = value;
         }
     }
 }
Example #4
0
            public void SetNewValue(string propertyName, object value)
            {
                if (OriginalValues.ContainsKey(propertyName) && OriginalValues[propertyName] == value)
                {
                    return;
                }

                if (NewValues.ContainsKey(propertyName))
                {
                    NewValues[propertyName] = value;
                }
                else
                {
                    NewValues.Add(propertyName, value);
                }
            }
Example #5
0
 // Captures the original value for a property that is changing.
 internal void RecordValue(string propertyName, object oldValue, object newValue)
 {
     if (_changeTrackingEnabled && _objectState != ObjectState.Added)
     {
         if (OriginalValues.ContainsKey(propertyName) &&
             OriginalValues[propertyName] == newValue)
         {
             // On repasse à l'état initial
             OriginalValues.Remove(propertyName);
             ModifiedValues.Remove(propertyName);
         }
         else
         {
             if (!OriginalValues.ContainsKey(propertyName))
             {
                 OriginalValues[propertyName] = oldValue;
             }
             ModifiedValues[propertyName] = newValue;
         }
     }
 }
Example #6
0
        /// <summary>
        /// Validate the e-tag via applies the current DataModificationItem's OriginalValues to the
        /// specified query and returns result.
        /// </summary>
        /// <param name="query">The IQueryable to apply the property values to.</param>
        /// <returns>
        /// The object is e-tag checked passed.
        /// </returns>
        public object ValidateEtag(IQueryable query)
        {
            Ensure.NotNull(query, nameof(query));
            var type  = query.ElementType;
            var param = Expression.Parameter(type);

            Expression where = null;

            if (OriginalValues != null)
            {
                foreach (var item in OriginalValues)
                {
                    if (!item.Key.StartsWith("@", StringComparison.Ordinal))
                    {
                        where = ApplyPredicate(param, where, item);
                    }
                }

                if (OriginalValues.ContainsKey(IfNoneMatchKey))
                {
                    where = Expression.Not(where);
                }
            }

            var whereLambda = Expression.Lambda(where, param);
            var queryable   = ExpressionHelpers.Where(query, whereLambda, type);

            var matchedResource = queryable.SingleOrDefault();

            if (matchedResource == null)
            {
                // If ETAG does not match, should return 412 Precondition Failed
                var message = string.Format(CultureInfo.InvariantCulture, Resources.PreconditionCheckFailed, new object[] { EntitySetOperation, query.SingleOrDefault() });
                throw new PreconditionFailedException(message);
            }

            return(matchedResource);
        }
Example #7
0
 public bool ContainsKey(TKey key)
 => IsKeyFiltered(key) && OriginalValues.ContainsKey(key);
 public object GetOriginalValue(string propertyName)
 {
     return(OriginalValues.ContainsKey(propertyName) ? OriginalValues[propertyName] : null);
 }