Ejemplo n.º 1
0
        protected virtual async Task <EntityUpdateModel <T> > UpdateCore(IValueProvider valueProvider, IAuthentication authentication, T entity, IPropertyMetadata[] properties)
        {
            var model = new EntityUpdateModel <T>();

            {
                var arg = new EntityUpdateEventArgs <T>(entity, valueProvider, properties);
                await RaiseAsyncEvent(EntityPreUpdateEvent, arg);

                properties = arg.Properties;
            }
            foreach (var property in properties)
            {
                try
                {
                    await UpdateProperty(valueProvider, entity, property);
                }
                catch (ArgumentException ex)
                {
                    model.ErrorMessage.Add(property, ex.Message);
                }
            }
            if (model.ErrorMessage.Count == 0)
            {
                var arg = new EntityUpdateEventArgs <T>(entity, valueProvider, properties);
                await RaiseAsyncEvent(EntityUpdatedEvent, arg);
            }
            model.IsSuccess = model.ErrorMessage.Count == 0;
            model.Result    = entity;
            return(model);
        }
Ejemplo n.º 2
0
        protected virtual async Task <EntityUpdateModel <T> > UpdateCore(IValueProvider valueProvider, IAuthentication authentication, T entity, IPropertyMetadata[] properties)
        {
            var model = new EntityUpdateModel <T>();

            if (EntityPreUpdate != null)
            {
                var arg = new EntityUpdateEventArgs <T>(entity, valueProvider, properties);
                await EntityPreUpdate(Context, arg);

                properties = arg.Properties;
            }
            foreach (var property in properties)
            {
                await UpdateProperty(valueProvider, entity, property);
            }
            if (EntityUpdated != null)
            {
                var arg = new EntityUpdateEventArgs <T>(entity, valueProvider, properties);
                await EntityUpdated(Context, arg);
            }
            model.IsSuccess = model.ErrorMessage.Count == 0;
            model.Result    = entity;
            return(model);
        }