Example #1
0
        public static async Task EnsureSeedCategories(this PulstarDbContext context)
        {
            if (context.Categories.Any())
            {
                return;
            }

            var consoles = new List <string> {
                "PS3", "PS4", "XBox One"
            };
            var accessories = new List <string> {
                "iOS", "PlayStation VR", "Switch", "PS4", "Xbox One", "PC", "PS3", "Xbox 360", "WiiU", "PS", "Vita", "3DS", "PSP", "PS2", "Wii", "NDS Nintendo", "Classic"
            };
            var games = new List <string> {
                "PlayStation VR", "PS4", "Xbox One", "PC", "PS3", "Xbox 360", "WiiU", "PS Vita", "Switch", "3DS", "PSP", "PS2", "WiiNDSМобилниCard & Board"
            };

            consoles
            .ForEach(i =>
            {
                var category = new Category
                {
                    Name = i,
                    Type = CategoryType.Console,
                };
                context.Categories.Add(category);
            });

            accessories
            .ForEach(i =>
            {
                var category = new Category
                {
                    Name = i,
                    Type = CategoryType.Accessory,
                };
                context.Categories.Add(category);
            });

            games
            .ForEach(i =>
            {
                var category = new Category
                {
                    Name = i,
                    Type = CategoryType.Game,
                };
                context.Categories.Add(category);
            });

            await context.SaveChangesAsync();
        }
Example #2
0
        public static async Task EnsureSeedGames(this PulstarDbContext context, string defaultImageFilePath)
        {
            const int gamesPerCategory = 5;

            var categories = context.Categories.Where(c => c.Type == CategoryType.Game).ToList();

            if (categories.Count == 0 || context.Products.Any())
            {
                return;
            }

            var random = new Random();

            foreach (var category in categories)
            {
                for (int i = 0; i < gamesPerCategory; i++)
                {
                    var manufacturer = i % 2 == 0 ? "Sony" : "Samsung";
                    var title        = i % 2 == 0 ? "PS" : "PC";

                    var game = new Product
                    {
                        CategoryId   = category.Id,
                        Manufacturer = $"{manufacturer} Enterprise",
                        Price        = random.Next(20, 400),
                        Title        = $"title{i}",
                        Quantity     = random.Next(0, 100),
                        Discount     = random.Next(0, 100),
                        Model        = $"{title}{i + 1}",
                        Image        = File.ReadAllBytes(defaultImageFilePath),
                        Description  = @"Lorem ipsum dolor sit amet, dico congue reprimique an quo. Ex sea solum rebum dolorem. Duis malis fierent ea vis, ne his idque soluta. Prima idque debet cu vel, mea illum libris ei. Mundi elitr suscipit vel ad, accumsan repudiandae te sit. Unum luptatum vis et.",
                    };
                    context.Products.Add(game);
                }

                await context.SaveChangesAsync();
            }
        }
Example #3
0
 public GenericRepository(PulstarDbContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _dbSet     = _dbContext.Set <T>();
 }