コード例 #1
0
        private static void CreateProducts(StoreContext context)
        {
            var categoryRepository = new CategoryRepository(context);
            var categoryIds        = categoryRepository.GetAll().ToArray();

            var productRepository = new ProductRepository(context);

            if (!productRepository.IsEmpty())
            {
                return;
            }

            for (var i = 1; i <= 100; i++)
            {
                productRepository.AddOrUpdate(new ProductModel {
                    Id                  = i,
                    Category            = RandomHelpers.GetRandom(categoryIds),
                    Title               = string.Format("محصول آزمایشی {0}", i),
                    Slug                = StringHelpers.Slugify(string.Format("Test Product {0}", i)),
                    Summary             = "خلاصه ای در مورد این محصول",
                    Description         = "توضیحات کامل مربوط به این محصول.",
                    Features            = "<ul><li>ویژگی شماره 1</li><li>ویژگی شماره 2</li><li>ویژگی شماره 3</li><li>و...</li></ul>",
                    MetaKeywords        = "کلمه 1, کلمه 2, کلمه 3",
                    MetaDescription     = "توضیحاتی در مورد محصول",
                    UnitPrice           = 55500 * i,
                    ReleaseDateUtc      = RandomHelpers.GetRandom(DateTime.UtcNow.AddYears(-2), DateTime.UtcNow),
                    LastModifiedDateUtc = RandomHelpers.GetRandom(DateTime.UtcNow.AddYears(-1), DateTime.UtcNow),
                    ViewsCount          = 0,
                    AddedToCartCount    = 0
                });
            }

            productRepository.SaveChanges();
        }