public static Character AddCharacter(this TContext ctx, int userId, Terraria.Player player)
        {
            Character chr = new Character()
            {
                UserId          = userId,
                UUID            = player.ClientUUId,
                Health          = player.statLife,
                MaxHealth       = player.statLifeMax,
                Mana            = player.statMana,
                MaxMana         = player.statManaMax,
                SpawnX          = player.SpawnX,
                SpawnY          = player.SpawnY,
                Hair            = player.hair,
                HairDye         = player.hairDye,
                HideVisual      = DataEncoding.EncodeInteger(player.hideVisual),
                Difficulty      = player.difficulty,
                HairColor       = DataEncoding.EncodeColor(player.hairColor),
                SkinColor       = DataEncoding.EncodeColor(player.skinColor),
                EyeColor        = DataEncoding.EncodeColor(player.eyeColor),
                ShirtColor      = DataEncoding.EncodeColor(player.shirtColor),
                UnderShirtColor = DataEncoding.EncodeColor(player.underShirtColor),
                PantsColor      = DataEncoding.EncodeColor(player.pantsColor),
                ShoeColor       = DataEncoding.EncodeColor(player.shoeColor),
                AnglerQuests    = player.anglerQuestsFinished
            };

            ctx.Characters.Add(chr);

            ctx.SaveChanges();

            return(chr);
        }
        private void TPT_or_TPC_model_with_PK_property_to_different_columns_in_different_tables_roundtrips <TContext>()
            where TContext : BaseContextForPkNaming, new()
        {
            using (var context = new TContext())
            {
                context.Database.Initialize(force: false);

                try
                {
                    ProviderAgnosticConfiguration.SuspendExecutionStrategy = true;

                    using (new TransactionScope())
                    {
                        var baseEntity = context.Bases.Add(
                            new BaseForPKNaming
                        {
                            Id  = 1,
                            Foo = "Foo1"
                        });
                        var derivedEntity =
                            context.Deriveds.Add(
                                new DerivedForPKNaming
                        {
                            Id  = 2,
                            Foo = "Foo2",
                            Bar = "Bar2"
                        });

                        context.SaveChanges();

                        context.Entry(baseEntity).State    = EntityState.Detached;
                        context.Entry(derivedEntity).State = EntityState.Detached;

                        var foundBase    = context.Bases.Single(e => e.Id == baseEntity.Id);
                        var foundDerived = context.Deriveds.Single(e => e.Id == derivedEntity.Id);

                        Assert.Equal("Foo1", foundBase.Foo);
                        Assert.Equal("Foo2", foundDerived.Foo);
                        Assert.Equal("Bar2", foundDerived.Bar);

                        Assert.True(context.Database.SqlQuery <int>("select base_id from base_table").Any());
                        Assert.True(context.Database.SqlQuery <int>("select derived_id from derived_table").Any());

                        if (typeof(TContext)
                            == typeof(ContextForPkNamingTPC))
                        {
                            Assert.True(context.Database.SqlQuery <string>("select base_foo from base_table").Any());
                            Assert.True(context.Database.SqlQuery <string>("select derived_foo from derived_table").Any());
                        }
                    }
                }
                finally
                {
                    ProviderAgnosticConfiguration.SuspendExecutionStrategy = false;
                }
            }
        }
Example #3
0
 public static void Seed(TContext context)
 {
     context.SaveChanges();
 }
 public bool SaveAll()
 {
     return(_context.SaveChanges() > 0);
 }
Example #5
0
 public int Complete() => context.SaveChanges();
        public static Character NewCharacter
        (
            TContext ctx,
            CharacterMode mode,
            string auth,
            string clientUUID,
            int health,
            int maxHealth,
            int mana,
            int maxMana,
            int spawnX,
            int spawnY,
            int hair,
            byte hairDye,
            int hideVisual,
            byte difficulty,
            uint hairColor,
            uint skinColor,
            uint eyeColor,
            uint shirtColor,
            uint underShirtColor,
            uint pantsColor,
            uint shoeColor,
            int anglerQuests
        )
        {
            int?userId = null;

            if (mode == CharacterMode.AUTH)
            {
                var user = AuthenticatedUsers.GetUser(auth);
                userId = user.Id;
            }
            else if (mode != CharacterMode.UUID)
            {
                return(null);
            }

            Character chr = new Character()
            {
                UserId          = userId,
                UUID            = clientUUID,
                Health          = health,
                MaxHealth       = maxHealth,
                Mana            = mana,
                MaxMana         = maxMana,
                SpawnX          = spawnX,
                SpawnY          = spawnY,
                Hair            = hair,
                HairDye         = hairDye,
                HideVisual      = hideVisual,
                Difficulty      = difficulty,
                HairColor       = hairColor,
                SkinColor       = skinColor,
                EyeColor        = eyeColor,
                ShirtColor      = shirtColor,
                UnderShirtColor = underShirtColor,
                PantsColor      = pantsColor,
                ShoeColor       = shoeColor,
                AnglerQuests    = anglerQuests
            };

            ctx.Characters.Add(chr);

            ctx.SaveChanges();

            return(chr);
        }
        public static Character UpdateCharacter
        (
            TContext ctx,
            CharacterMode mode,
            string auth,
            string clientUUID,
            int health,
            int maxHealth,
            int mana,
            int maxMana,
            int spawnX,
            int spawnY,
            int hair,
            byte hairDye,
            int hideVisual,
            byte difficulty,
            uint hairColor,
            uint skinColor,
            uint eyeColor,
            uint shirtColor,
            uint underShirtColor,
            uint pantsColor,
            uint shoeColor,
            int anglerQuests
        )
        {
            int?userId = null;

            if (mode == CharacterMode.AUTH)
            {
                var user = AuthenticatedUsers.GetUser(auth);
                userId = user.Id;
            }
            else if (mode != CharacterMode.UUID)
            {
                return(null);
            }

            Character chr;

            if (mode == CharacterMode.AUTH)
            {
                chr = ctx.Characters.Single(x => x.UserId == userId.Value);
            }
            else
            {
                chr = ctx.Characters.Single(x => x.UUID == clientUUID);
            }

            chr.Health          = health;
            chr.MaxHealth       = maxHealth;
            chr.Mana            = mana;
            chr.MaxMana         = maxMana;
            chr.SpawnX          = spawnX;
            chr.SpawnY          = spawnY;
            chr.Hair            = hair;
            chr.HairDye         = hairDye;
            chr.HideVisual      = hideVisual;
            chr.Difficulty      = difficulty;
            chr.HairColor       = hairColor;
            chr.SkinColor       = skinColor;
            chr.EyeColor        = eyeColor;
            chr.ShirtColor      = shirtColor;
            chr.UnderShirtColor = underShirtColor;
            chr.PantsColor      = pantsColor;
            chr.ShoeColor       = shoeColor;
            chr.AnglerQuests    = anglerQuests;

            ctx.SaveChanges();

            return(chr);
        }
        public int SaveChanges()
        {
            var result = _context.SaveChanges();

            return(result);
        }