示例#1
0
        public static List <string> GetChangedProperties <T>(this Web.OData.Delta <T> value, T original, List <String> includeList = null) where T : class, new()
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            var changedProperties = value.GetChangedPropertyNames();

            if (!changedProperties.Any())
            {
                return(new List <string>());
            }

            var compareObjects = new CompareObjects {
                MaxDifferences    = 100,
                ElementsToInclude = includeList ?? value.GetChangedPropertyNames().ToList()
            };

            compareObjects.ElementsToInclude.Add(typeof(T).Name);

            bool result = compareObjects.Compare(original, value.GetEntity());

            return(!result?compareObjects.Differences.Select(d => d.PropertyName).Distinct().ToList() : new List <string>());
        }
示例#2
0
        public static bool ContainsChangedProperty <T>(this Web.OData.Delta <T> value, Expression <Func <T, object> > action) where T : class, new()
        {
            if (!value.GetChangedPropertyNames().Any())
            {
                return(false);
            }

            MemberExpression expression = action.Body as MemberExpression ?? ((UnaryExpression)action.Body).Operand as MemberExpression;

            return(expression != null && value.GetChangedPropertyNames().Contains(expression.Member.Name));
        }
示例#3
0
        // TODO: Investigate work around for: http://aspnetwebstack.codeplex.com/workitem/562
        public virtual HttpResponseMessage Patch(string id, Web.OData.Delta <TModel> value)
        {
            if (value == null || !value.GetChangedPropertyNames().Any())
            {
                return(BadRequestErrorResponseMessage());
            }

            TModel original = GetEntity(id);

            if (original == null)
            {
                return(NotFoundErrorResponseMessage(id));
            }

            if (!CanUpdateEntity(original, value))
            {
                return(CannotUpdateReadOnlyPropertyResponseMessage());
            }

            UpdateEntity(original, value);

            return(new HttpResponseMessage(HttpStatusCode.OK)); // NoContent
        }
示例#4
0
        protected abstract TModel InsertEntity(TModel value); // TODO: User can currently specify the organization id to insert.

        /// <summary>
        /// A check to see if a document can be updated.
        /// </summary>
        /// <param name="original">The original document.</param>
        /// <param name="value">The document.</param>
        protected virtual bool CanUpdateEntity(TModel original, Web.OData.Delta <TModel> value)
        {
            return(value.GetChangedPropertyNames().Any());
        }