Ejemplo n.º 1
0
        } // end function

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            try
            {
                Console.WriteLine("Deleting item and spell data.  This might take a few minutes... be patient and don't exit early!");
            }
            catch { }


            var allItemsAndSpells = getAllItemsAndSpells();

            using (var context = new TunnelQuestContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // delete items first
                        var itemsToDelete = new List <Item>();
                        foreach (var fullItem in allItemsAndSpells.Items)
                        {
                            itemsToDelete.Add(new Item()
                            {
                                ItemName = fullItem.ItemName
                            });
                        }
                        context.RemoveRange(itemsToDelete);
                        context.SaveChanges();

                        // delete spells second
                        var spellsToDelete = new List <Spell>();
                        foreach (var fullSpell in allItemsAndSpells.Spells)
                        {
                            spellsToDelete.Add(new Spell()
                            {
                                SpellName = fullSpell.SpellName
                            });
                        }
                        context.RemoveRange(spellsToDelete);
                        context.SaveChanges();


                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }

            try
            {
                Console.WriteLine("Finished deleting item and spell data.");
            }
            catch { }
        }
Ejemplo n.º 2
0
        // This is the big ugly migration that contains all the logic for parsing the scraped wiki data
        // in the json files and inserting the database rows for items and spells.

        protected override void Up(MigrationBuilder migrationBuilder)
        {
            try
            {
                Console.WriteLine("Inserting item and spell data.  This might take a few minutes... be patient and don't exit early!");
            }
            catch { }


            var allItemsAndSpells = getAllItemsAndSpells();

            using (var context = new TunnelQuestContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        // insert spells first
                        context.AddRange(allItemsAndSpells.Spells);
                        context.SaveChanges();

                        // insert items second
                        context.AddRange(allItemsAndSpells.Items);
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                } // end using (transaction)
            }     // end using (context)

            try
            {
                Console.WriteLine("Finished inserting item and spell data.");
            }
            catch { }
        } // end function
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var context = new TunnelQuestContext())
            {
                deleteAliases(context);
                deleteServers(context);
                deleteAuthTokens(context);
                deleteAuthTokenStatuses(context);
                deleteClasses(context);
                deleteRaces(context);
                deleteSizes(context);
                deleteSlots(context);
                deleteEffectTypes(context);
                deleteWeaponSkills(context);
                deleteDeities(context);

                context.SaveChanges();
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var context = new TunnelQuestContext())
            {
                insertAliases(context);
                insertServers(context);
                insertAuthTokenStatuses(context);
                insertAuthTokens(context);
                insertClasses(context);
                insertRaces(context);
                insertSizes(context);
                insertSlots(context);
                insertEffectTypes(context);
                insertWeaponSkills(context);
                insertDeities(context);

                context.SaveChanges();
            }
        }