Example #1
0
        public virtual async Task <IActionResult> OnPatch(TKey id, T entity, T patchEntity, JObject value)
        {
            if (ModelState.IsValid)
            {
                await OnBeforePatchAsync(id, entity, patchEntity, value);

                foreach (var property in value)
                {
                    var propertyInfo          = entity.GetType().GetTypeInfo().GetProperty(property.Key);
                    var entityType            = Model.GetEdmType(propertyInfo.DeclaringType) as EdmEntityType;
                    var propertyConfiguration = entityType?.FindProperty(propertyInfo.Name) as PropertyConfiguration;
                    if (propertyConfiguration != null && !propertyConfiguration.IsIgnored)
                    {
                        // Set the value to the value of the same property on the patch entity
                        propertyInfo?.SetValue(entity, propertyInfo.GetValue(patchEntity));
                    }
                }
                await OnAfterPatchAsync(id, entity, patchEntity, value);

                if (!await Crud.UpdateAndSaveAsync(entity))
                {
                    return(NotFound());
                }
                return(new NoContentResult());
            }
            return(this.ODataModelStateError());
        }
Example #2
0
        public virtual async Task <ActionResult> Patch(TKey id, T entity, JObject value)
        {
            var patchEntity = value.ToObject <T>();

            await OnBeforePatchAsync(id, entity, patchEntity, value);

            foreach (var property in value)
            {
                var propertyInfo = entity.GetType().GetTypeInfo().GetProperty(property.Key);
                //var entityType = Model.GetEdmType(propertyInfo.DeclaringType) as EdmEntityType;
                //var propertyConfiguration = entityType?.FindProperty(propertyInfo.Name) as PropertyConfiguration;
                //if (propertyConfiguration != null && !propertyConfiguration.IsIgnored)
                {
                    // Set the value to the value of the same property on the patch entity
                    propertyInfo?.SetValue(entity, propertyInfo.GetValue(patchEntity));
                }
            }
            await OnAfterPatchAsync(id, entity, patchEntity, value);

            if (!await Crud.UpdateAndSaveAsync(entity))
            {
                return(HttpNotFound());
            }
            return(new EmptyResult());
        }