/// <summary> /// Creates the training definition. /// </summary> /// <returns></returns> public static async Task CreateTrainingDefinition() { // Retrieve the training definition var trainingDefinition = await MConnector.Client.EntityDefinitions.Get(Constants.EntityDefinitions.Training.DefinitionName); if (trainingDefinition != null) { return; } // Create the entity definition trainingDefinition = new EntityDefinitionResource(); trainingDefinition.Name = Constants.EntityDefinitions.Training.DefinitionName; trainingDefinition.IsTaxonomyItemDefinition = true; // Create the membergroup var memberGroup = new MemberGroup() { Name = Constants.EntityDefinitions.Recipe.MemberGroups.Main }; trainingDefinition.MemberGroups.Add(memberGroup); // Create the name property definition memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Training.Properties.Name, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, IsMandatory = true }); // Create the description property definition memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Training.Properties.Description, IncludedInContent = true, Indexed = true, ContentType = StringPropertyDefinition.StringContentType.MultiLine }); // Create or update the training definition await MConnector.Client.EntityDefinitions.Create(trainingDefinition); }
/// <summary> /// Creates or updates the recipe definition. /// </summary> /// <returns></returns> private static async Task <string> CreateOrUpdateRecipeDefinition() { // Retrieve the recipe definition var recipeDefinition = await MConnector.Client.EntityDefinitions.Get(Constants.EntityDefinitions.Recipe.DefinitionName); // Create the entity definition if (recipeDefinition == null) { recipeDefinition = new EntityDefinitionResource(); recipeDefinition.Name = Constants.EntityDefinitions.Recipe.DefinitionName; recipeDefinition.IsTaxonomyItemDefinition = true; recipeDefinition.Labels = new Dictionary <string, string>() { { Constants.DefaultCulture.Name, Constants.EntityDefinitions.Recipe.DefinitionName } }; } // Get the membergroup var memberGroup = recipeDefinition.MemberGroups.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.MemberGroups.Main); if (memberGroup == null) { memberGroup = new MemberGroup() { Name = Constants.EntityDefinitions.Recipe.MemberGroups.Main }; recipeDefinition.MemberGroups.Add(memberGroup); } #region Properties // Create the Name property definition if it doesn't exist already var namePropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Name); if (namePropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Name, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, IsMandatory = true }); } // Create the Description property definition if it doesn't exist already var descriptionPropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Description); if (descriptionPropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Description, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, ContentType = StringPropertyDefinition.StringContentType.MultiLine }); } // Create the Categories property definition if it doesn't exist already var categoriesPropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Categories); if (categoriesPropertyDefinition == null) { var categoriesDataSource = await GetOrCreateCategoriesDataSource(); memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Categories, DataSource = categoriesDataSource.Self.Uri, MultiValue = true, Labels = new Dictionary <string, string>() { { Constants.DefaultCulture.Name, "Categories" } } }); } // Create the Preparation property definition if it doesn't exist already var preparationPropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Preparation); if (preparationPropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Preparation, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, ContentType = StringPropertyDefinition.StringContentType.Html }); } // Create the Servings property definition if it doesn't exist already var servingsPropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Servings); if (servingsPropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new IntegerPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Servings, Indexed = true }); } // PublishDate var publishDatePropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.PublishDate); if (publishDatePropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new DateTimePropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.PublishDate, Indexed = true }); } // Create the Vegetarian property definition if it doesn't exist already var exclusivePropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Properties.Vegetarian); if (exclusivePropertyDefinition == null) { memberGroup.MemberDefinitions.Add( new BooleanPropertyDefinition() { Name = Constants.EntityDefinitions.Recipe.Properties.Vegetarian, Indexed = true }); } #endregion #region Relations // Create the RecipeToMasterAsset relation if it doesn't exist already var recipeToAssetRelationDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Recipe.Relations.RecipeToMasterAsset); if (recipeToAssetRelationDefinition == null) { memberGroup.MemberDefinitions.Add(new RelationDefinition() { Name = Constants.EntityDefinitions.Recipe.Relations.RecipeToMasterAsset, AssociatedEntityDefinition = assetDefinitionUri, Cardinality = Cardinality.ManyToMany, InheritsSecurity = true, Labels = new Dictionary <string, string>() { { Constants.DefaultCulture.Name, "Master Asset" } } }); } // Create the ChefToRecipe relation if it doesn't exist already var chefToRecipeRelationDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Chef.Relations.ChefToRecipe); if (chefToRecipeRelationDefinition == null) { memberGroup.MemberDefinitions.Add(new RelationDefinition() { Name = Constants.EntityDefinitions.Chef.Relations.ChefToRecipe, AssociatedEntityDefinition = chefDefinitionUri, Cardinality = Cardinality.OneToMany, InheritsSecurity = true, Labels = new Dictionary <string, string>() { { Constants.DefaultCulture.Name, "Chef" } } }); } #endregion // Set the display template recipeDefinition.DisplayTemplate = "{" + Constants.EntityDefinitions.Recipe.Properties.Name + "}"; // Create or update the recipe definition if (!recipeDefinition.Exists()) { await MConnector.Client.EntityDefinitions.Create(recipeDefinition); recipeDefinition = await MConnector.Client.EntityDefinitions.Get(Constants.EntityDefinitions.Recipe.DefinitionName); } else { await MConnector.Client.EntityDefinitions.Update(recipeDefinition); } return(recipeDefinition.Self.Uri); }
/// <summary> /// Creates or updates the chef definition. /// </summary> /// <returns></returns> private static async Task <string> CreateOrUpdateChefDefinition() { // Retrieve the chef definition var chefDefinition = await MConnector.Client.EntityDefinitions.Get(Constants.EntityDefinitions.Chef.DefinitionName); // Create the entity definition if (chefDefinition == null) { chefDefinition = new EntityDefinitionResource(); chefDefinition.Name = Constants.EntityDefinitions.Chef.DefinitionName; chefDefinition.IsTaxonomyItemDefinition = true; chefDefinition.Labels = new Dictionary <string, string>() { { Constants.DefaultCulture.Name, Constants.EntityDefinitions.Chef.DefinitionName } }; } // Get the membergroup var memberGroup = chefDefinition.MemberGroups.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Chef.MemberGroups.Main); if (memberGroup == null) { memberGroup = new MemberGroup() { Name = Constants.EntityDefinitions.Chef.MemberGroups.Main }; chefDefinition.MemberGroups.Add(memberGroup); } #region Properties // Create the Name property definition if it doesn't exist already var namePropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Chef.Properties.Name); if (namePropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Chef.Properties.Name, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, IsMandatory = true }); } // Create the bio property definition if it doesn't exist already var bioPropertyDefinition = memberGroup.MemberDefinitions.FirstOrDefault(x => x.Name == Constants.EntityDefinitions.Chef.Properties.Bio); if (bioPropertyDefinition == null) { memberGroup.MemberDefinitions.Add(new StringPropertyDefinition() { Name = Constants.EntityDefinitions.Chef.Properties.Bio, IncludedInContent = true, IncludedInCompletion = true, Indexed = true, IsMandatory = true, ContentType = StringPropertyDefinition.StringContentType.Html }); } #endregion // Set the display template chefDefinition.DisplayTemplate = "{" + Constants.EntityDefinitions.Chef.Properties.Name + "}"; // Create or update the chef definition if (!chefDefinition.Exists()) { await MConnector.Client.EntityDefinitions.Create(chefDefinition); chefDefinition = await MConnector.Client.EntityDefinitions.Get(Constants.EntityDefinitions.Chef.DefinitionName); } else { await MConnector.Client.EntityDefinitions.Update(chefDefinition); } return(chefDefinition.Self.Uri); }
public static bool Exists(this EntityDefinitionResource resource) { return(resource.Id != default(long)); }