public static void Initialize(VendingMachineContext context)
        {
            context.Database.EnsureCreated();

            // Look for any existing data.
            if (context.Machines.Any())
            {
                return;   // DB has been seeded
            }

            // Add Machine
            var machine = new Machine
            {
                Wallet   = InitializeWallet(),
                Products = InitializeProducts()
            };

            context.Machines.Add(machine);

            context.SaveChanges();
        }
示例#2
0
 public T Create <T>(T entity) where T : class
 {
     _dbContext.Set <T>().Add(entity);
     _dbContext.SaveChanges();
     return(entity);
 }