Beispiel #1
0
        /// <summary>
        /// Update an entity's properties from a JObject (during a PATCH).  Validation is performed, but no changes are saved.
        /// </summary>
        /// <param name="entity">Entity to be updated.</param>
        /// <param name="changes">Changes as a JObject.</param>
        protected virtual void UpdateFromJObject <T1>(T1 entity, JObject changes) where T1 : class, IEntity
        {
            Dictionary <string, object> changedProperties = new Dictionary <string, object>();
            Type entityType = typeof(T1);

            foreach (var pair in changes)
            {
                if (!ProcessJTokenUpdate(entity, pair.Key, pair.Value))
                {
                    var convertedPair = JsonExtensions.ConvertToType <T1>(pair);
                    changedProperties.Add(convertedPair.Key, convertedPair.Value);
                }
            }

            IEntityLogic logic = BusinessLogicHelper.GetBusinessLogic <T1>(unitOfWork);

            unitOfWork.GetRepository <T1>().UpdateChangedProperties(entity, changedProperties, p => logic.Validate(p));
        }