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>()); }
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)); }
// 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 }
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()); }