public MixInValidation(DynamicModel mixWith) { rules = new List <dynamic>(); errors = new List <dynamic>(); @this = mixWith; if (HasValidationCapabilities(mixWith)) { mixWith.SetUnTrackedMember("Errors", new DynamicFunction(Errors)); mixWith.SetUnTrackedMember("IsValid", new DynamicFunctionWithParam(IsValid)); mixWith.SetUnTrackedMember("FirstError", new DynamicFunction(FirstError)); IEnumerable <dynamic> validationRules = @this.Validates(); foreach (var validationRule in validationRules) { validationRule.Init(mixWith); AddRule(validationRule); } } }
private dynamic EntityFor(DynamicModel model, dynamic attributes) { var entity = new Gemini(attributes); entity.SetMember(ForeignKeyFor(model), model.GetMember(Id())); return(Repository.Projection(entity)); }
public void Init(DynamicModel model) { string foreignKeyName = string.IsNullOrEmpty(ForeignKey) ? ForeignKeyFor(model) : ForeignKey; model.SetUnTrackedMember( Singular(Repository), new DynamicFunction(() => Repository.SingleWhere(foreignKeyName + " = @0", model.GetMember(Id())))); }
public void Init(DynamicModel model) { ForeignKey = ForeignKeyFor(model); var toTable = Repository.GetType().Name; AddAssociationMethods(model, ForeignKey, toTable); }
public void Init(DynamicModel model) { string foreignKeyName = string.IsNullOrEmpty(ForeignKey) ? ForeignKeyFor(model) : ForeignKey; model.SetUnTrackedMember( Singular(Repository), Query(foreignKeyName, Repository.GetType().Name, through.GetType().Name, ForeignKeyFor(Repository), model)); }
private DynamicFunction QueryIds(DynamicModel model) { return(() => { IEnumerable <dynamic> models = (Query(model) as DynamicFunctionWithParam).Invoke(null); return models.Select(s => s.Id).ToList(); }); }
private void AddNewAssociationMethod(DynamicModels collection, DynamicModel model) { collection.SetMember( "New", new DynamicFunctionWithParam(attributes => { return(EntityFor(attributes)); })); }
private void AddAssociationMethod(DynamicModel model) { model.SetUnTrackedMember( Named, Query(model)); model.SetUnTrackedMember( Singular(Named) + "Ids", QueryIds(model)); }
public void Init(DynamicModel model) { fromColumn = ForeignKeyFor(model); toTable = Repository.GetType().Name; resolvedForeignKey = ForeignKey ?? ForeignKeyFor(Repository); AddAssociationMethod(model); }
public MixInChanges(dynamic dynamicModel) { @this = dynamicModel; originalValues = new Dictionary<string, object>(dynamicModel.TrackedHash()); dynamicModel.SetUnTrackedMember("HasChanged", new DynamicFunctionWithParam(HasChanged)); dynamicModel.SetUnTrackedMember("Original", new DynamicFunctionWithParam(Original)); dynamicModel.SetUnTrackedMember("Changes", new DynamicFunctionWithParam(Changes)); }
public MixInChanges(dynamic dynamicModel) { @this = dynamicModel; originalValues = new Dictionary <string, object>(dynamicModel.TrackedHash()); dynamicModel.SetUnTrackedMember("HasChanged", new DynamicFunctionWithParam(HasChanged)); dynamicModel.SetUnTrackedMember("Original", new DynamicFunctionWithParam(Original)); dynamicModel.SetUnTrackedMember("Changes", new DynamicFunctionWithParam(Changes)); }
public void Init(DynamicModel model) { string foreignKeyName = string.IsNullOrEmpty(ForeignKey) ? ForeignKeyFor(Repository) : ForeignKey; string primaryKeyName = string.IsNullOrEmpty(PrimaryKey) ? "Id" : PrimaryKey; string whereClause = string.Format("{0} = @0", primaryKeyName); model.SetUnTrackedMember( Named, new DynamicFunction(() => Repository.SingleWhere(whereClause, model.GetMember(foreignKeyName)))); }
public MixInAssociation(DynamicModel mixWith) { if (!SupportsAssociations(mixWith)) { return; } IEnumerable <dynamic> associations = (mixWith as dynamic).Associates(); foreach (dynamic association in associations) { referencedAssociations.Add(association); association.Init(mixWith); } mixWith.SetUnTrackedMember("AssociationNamed", new DynamicFunctionWithParam(AssociationNamed)); }
private DynamicFunctionWithParam Query(DynamicModel model) { return((options) => { if (DiscardCache(options)) { cachedCollection = null; } if (cachedCollection != null) { return cachedCollection; } cachedCollection = new DynamicModels(Repository.Query(SelectClause(model))); AddNewAssociationMethod(cachedCollection, model); return cachedCollection; }); }
public bool Validate(DynamicModel entity) { dynamic value = entity.GetMember(Property); if (value == null && IgnoreNull == true) { return(true); } if (value == null) { return(false); } int length = value.Length; if (Minimum != null && length < Minimum) { return(false); } if (Maximum != null && length > Maximum) { return(false); } if (In != null && !In.Contains(length)) { return(false); } if (Is != null && length != Is) { return(false); } return(true); }
private DynamicFunction Query(string fromColumn, string toTable, string throughTable, string @using, DynamicModel model) { return(() => Repository.Query( @" select {toTable}.* from {throughTable} inner join {toTable} on {throughTable}.{using} = {toTable}.Id where {fromColumn} = @0" .Replace("{toTable}", toTable) .Replace("{throughTable}", throughTable) .Replace("{using}", @using) .Replace("{fromColumn}", fromColumn), model.Expando.Id as object) .FirstOrDefault()); }
private void AddAssociationMethods(DynamicModel model, string fromColumn, string toTable) { model.SetUnTrackedMember(Named, Query(fromColumn, model)); model.SetUnTrackedMember(Singular(Named) + "Ids", QueryIds(fromColumn, model)); }
public bool HasValidationCapabilities(DynamicModel mixWith) { return(mixWith.GetType().GetMethod("Validates") != null); }
public bool SupportsAssociations(DynamicModel mixWith) { return(mixWith.GetType().GetMethod("Associates") != null); }