Exemplo n.º 1
0
        public static void EnsureSeeded(this GuildedRoseContext context)
        {
            var imported = new CsvDataLoader("guilded.rose.api.Domain.Data.Inventory.csv").Build();

            if (!context.Categories.Any())
            {
                var categories = imported.Select(import => import.Category).Distinct().Select(cat => new Category {
                    Name = cat
                });

                context.AddRange(categories);
                context.SaveChanges();
            }

            if (!context.Items.Any())
            {
                var items = imported.Select(import => new Item
                {
                    Name        = import.Name,
                    Category    = context.Categories.First(cat => cat.Name == import.Category),
                    CategoryId  = context.Categories.First(cat => cat.Name == import.Category).Id,
                    SellIn      = import.SellIn,
                    Quality     = import.Quality,
                    DateCreated = DateTime.Now
                });

                context.AddRange(items);
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
 public CategoryRepository(GuildedRoseContext context)
 {
     _context = context;
 }
Exemplo n.º 3
0
 public ItemRepository(GuildedRoseContext context)
 {
     _context = context;
 }