private static void UpdateProduct(ProductId id, CatalogDbContext context)
        {
            var product = context.Products.Single(e => e.Id == id);

            var details = new ProductDetails(new Name("Updated name"), new Description("Updated description"));

            product.UpdateDetails(details);

            product.Tag(Tag.New, Tag.New);

            product.AddComment(new Comment {
                Content = "Awesome!"
            });

            product.AddImage(new Image("bar"));

            product.Rate(new Rating(10));

            context.SaveChanges();
        }
Example #2
0
        public static void Seed(CatalogDbContext dbContext)
        {
            if (dbContext.Database.GetPendingMigrations().Any())
            {
                dbContext.Database.Migrate();
            }

            if (!dbContext.Brands.Any())
            {
                dbContext.Brands.Add(Brand.Create(new BrandId(1), "Razer"));
                dbContext.Brands.Add(Brand.Create(new BrandId(2), "Logitech"));
                dbContext.Brands.Add(Brand.Create(new BrandId(3), "Corsair"));
            }

            if (!dbContext.Categories.Any())
            {
                dbContext.Categories.Add(Category.Create(new CategoryId(1), "Home"));
                dbContext.Categories.Add(Category.Create(new CategoryId(2), "Gaming"));
                dbContext.Categories.Add(Category.Create(new CategoryId(3), "Professional"));
            }

            dbContext.SaveChanges();
        }