Ejemplo n.º 1
0
        private Expression BuildMasterDetailRelationExpression(ref bool isManyToMany, ref Expression memberChain, Type masterType, Type detailType, IEnumerable <Type> routeEntityTypes, int currentEntityIndex)
        {
            var masterIdProperty = detailType.GetPropertyIgnoreCase(masterType.Name + "id");

            if (masterIdProperty != null)
            {
                var relation = Expression.Equal(
                    Expression.Property(memberChain, masterIdProperty),
                    Expression.Constant(Convert.ChangeType(_actionContextAccessor.GetRouteParamIgnoreCase(masterIdProperty.Name), masterIdProperty.PropertyType)));

                var masterObjectProperty = detailType.GetProperty(masterType.Name);

                if (masterObjectProperty == null)
                {
                    throw new InvalidOperationException($"Type '{detailType.Name}' does not contain a '{masterType.Name}' property.");
                }

                AppendMemberChain(ref memberChain, masterObjectProperty);

                return(relation);
            }

            isManyToMany = true;

            return(BuildMasterDetailManyToManyRelationExpression(memberChain, masterType, detailType, routeEntityTypes, currentEntityIndex));
        }
Ejemplo n.º 2
0
        private async Task <RecordError> ValidateParentEntitiesExistenceAsync()
        {
            for (int i = 0; i <= _routeEntityTypes.Count() - 2; i++)
            {
                var entityType = _routeEntityTypes.ElementAt(i);
                var id         = Convert.ChangeType(_actionContextAccessor.GetRouteParamIgnoreCase(entityType.Name + "id"), entityType.BaseGenericType().GenericTypeArguments[0]);

                var result = await ValidateEntityExistenceAsync(entityType, id);

                if (result != null)
                {
                    return(result);
                }
            }

            return(await Task.FromResult <RecordError>(null));
        }
Ejemplo n.º 3
0
 public void FillForeignKeysFromRoute <TEntity>(TEntity entity)
 {
     foreach (var property in _propertyProvider.GetProperties(entity.GetType())
              .Where(p => _actionContextAccessor.HasRouteParamIgnoreCase(p.Name)))
     {
         entity.SetPropertyValue(property.Name, Convert.ChangeType(_actionContextAccessor.GetRouteParamIgnoreCase(property.Name), property.PropertyType));
     }
 }