コード例 #1
0
        private async Task SeedCake(CakeItDbContext db, ILogger <CakeItDbContext> logger)
        {
            var product1 = new Product {
                CategoryId = 1, Name = "Choco Mint", Price = 23.20m, Description = "A chocolate sponge layered with a mint flavoured cream. Masked with icing cream, chocolate glaze drip and a range of yummy choc mint goodies on top.", Image = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNPFKz7AZZjPSwn-e7_QwcGdDUVRI1z_fG_gQiSPI4u1wBQShmhA&s"
            };

            var product2 = new Product {
                CategoryId = 1, Name = "Cherry Blossom", Price = 55.00m, Description = "Chocolate sponge with matcha green tea buttercream. Decorated with 'cherry blossom' pink sea-salted candied popcorn and pink macarons.", Image = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRcSkgiYbXZlj8AmkDwlbE0BkCMsxKR9NlEHcbVKOL3D5WXvQQx6w&s"
            };

            try
            {
                await db.AddRangeAsync(new object[] { product1, product2 });

                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogDebug(e.Message);
            }
        }
コード例 #2
0
        private async Task SeedCustomCakesImages(CakeItDbContext db, ILogger <CakeItDbContext> logger)
        {
            var product1 = new CustomCakeImg {
                Side = "White_Chocolate_Cigarettes", Top = "Habana", Img = "https://res.cloudinary.com/cakeit/image/upload/v1545083551/Top_Habana_WhiteCigarettes.png", Name = "Habana" + " " + "White Cigarettes"
            };

            var product2 = new CustomCakeImg {
                Side = "White_Chocolate_Cigarettes", Top = "Glaszed_Berries", Img = "https://res.cloudinary.com/cakeit/image/upload/v1545225696/Top_GlazedBerries_WhiteCigarettes.png", Name = "Glaszed Berries" + " " + "White Cigarettes"
            };

            try
            {
                await db.AddRangeAsync(new object[] { product1, product2 });

                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogDebug(e.Message);
            }
        }