public static TModel GetModel ( [Comments("Filter.")] FilterGroupParameters filterGroup, [Comments("Variable reference to the repository.")] ISchoolRepository repository, [Comments("Variable reference to AutoMapper's IMapper.")] IMapper mapper, [ListEditorControl(ListControlType.HashSetForm)] [ParameterEditorControl(ParameterControlType.ParameterSourcedPropertyInput)] [NameValue(AttributeNames.PROPERTYSOURCEPARAMETER, "modelType")] [Comments("Update the model type first for help with property names.")] string[] includes = null, [ParameterEditorControl(ParameterControlType.TypeAutoComplete)] [NameValue(AttributeNames.DEFAULTVALUE, "Contoso.Domain.Entities")] [Comments("Fully qualified class name for the model type.")] string modelType = null ) { FilterGroup fg = mapper.Map <FilterGroup>(filterGroup); TModel model = repository.GetItemsAsync <TModel, TData>(fg.GetFilterExpression <TModel>(), null, includes.BuildIncludesExpressionCollection <TModel>()).Result.SingleOrDefault(); return(model ?? new TModel()); }
public static void SaveModel(FilterGroupParameters filterGroup, TModel model, ISchoolRepository repository, IMapper mapper) { FilterGroup fg = mapper.Map <FilterGroup>(filterGroup); TModel existing = Task.Run(async() => await repository.GetItemsAsync <TModel, TData>(fg.GetFilterExpression <TModel>())).Result.SingleOrDefault(); model.EntityState = existing != null ? LogicBuilder.Domain.EntityStateType.Modified : LogicBuilder.Domain.EntityStateType.Added; repository.SaveGraphAsync <TModel, TData>(model).Wait(); }
public void Map_Contoso_FilterGroup_To_LogicBuilder_FilterGroup() { FilterGroupParameters filterGroup = new FilterGroupParameters { Logic = "and", Filters = new List <FilterDefinitionParameters> { new FilterDefinitionParameters { Field = "FirstName", Operator = "contains", Value = "ja" }, new FilterDefinitionParameters { Field = "ZipCaode", Operator = "eq", Value = "28202" } } }; LogicBuilder.Expressions.Utils.DataSource.FilterGroup mapped = mapper.Map <LogicBuilder.Expressions.Utils.DataSource.FilterGroup>(filterGroup); Assert.Equal("and", mapped.Logic); Assert.Equal("FirstName", mapped.Filters.First().Field); Assert.Equal("contains", mapped.Filters.First().Operator); }