private async Task CreateProducts() { Console.Out.WriteLine("Creating Products"); var collectionId = CollectionIdHelper.GetId(typeof(ProductDocument)); await CreateCollectionIfNotExistsAsync(DocumentClient, collectionId); foreach (var document in Documents) { await DocumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionId), document); Console.Out.WriteLine($"Created {document.Id} {document.Title}"); } }
private async Task CreateFeaturedProducts() { Console.Out.WriteLine("Creating Featured Products"); var products = new List <FeaturedProductDocument>(); var collectionId = CollectionIdHelper.GetId(typeof(FeaturedProductDocument)); // randomly select 10 products to be "featured" var index = 0; var count = Documents.Count; var random = new Random(); do { var r = random.Next(count); var product = Documents[r]; var featuredProduct = new FeaturedProductDocument(product.Id, product.Title) { PrimaryImage = product.PrimaryImage, Price = product.Price, ShortDescription = product.ShortDescription }; if (products.Contains(featuredProduct) == false) { products.Add(featuredProduct); index++; } } while (index < 10); await CreateCollectionIfNotExistsAsync(DocumentClient, collectionId); foreach (var fp in products) { await DocumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionId), fp); Console.Out.WriteLine($"Created {fp.Id} {fp.Title}"); } }
private async Task CreateCategories() { Console.Out.WriteLine("Creating Categories"); var categories = new Dictionary <string, CategoryDocument>(); var collectionId = CollectionIdHelper.GetId(typeof(CategoryDocument)); await CreateCollectionIfNotExistsAsync(DocumentClient, collectionId); foreach (var document in Documents) { var primaryCategory = document.Categories[0]; CategoryDocument categoryDocument; if (categories.ContainsKey(primaryCategory.Id)) { categoryDocument = categories[primaryCategory.Id]; } else { categoryDocument = new CategoryDocument(primaryCategory.Id, primaryCategory.Name); categories.Add(primaryCategory.Id, categoryDocument); } var secondaryCategory = document.Categories[1]; categoryDocument.AddSubCategory(new SubCategory(secondaryCategory.Id, secondaryCategory.Name)); } foreach (var category in categories) { await DocumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionId), category.Value); Console.Out.WriteLine($"Created {category.Key} {category.Value.Name}"); } }
public void GetId_returns_the_proper_pluralized_name() { var collectionId = CollectionIdHelper.GetId(typeof(ProductDocument)); collectionId.ShouldBe("Products"); }