Exemplo n.º 1
0
        public static void AddUnit(Unit unit)
        {
            using (var context = new ArmyContext())
            {
                if (unit.UnitId > 0)
                {
                    UpdateUnit(unit);
                }
                else
                {
                    context.Units.Add(unit);
                    context.SaveChanges();
                }

                AddRace(unit.Species);

                foreach (var trait in unit.Traits)
                {
                    if (trait.TraitId <= 0)
                    {
                        AddTrait(trait);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void AddTrait(Trait trait)
 {
     using (var context = new ArmyContext())
     {
         if (trait.TraitId > 0)
         {
             UpdateTrait(trait);
         }
         else
         {
             context.Traits.Add(trait);
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
        public static void UpdateUnit(Unit unit)
        {
            using (var context = new ArmyContext())
            {
                if (unit.UnitId > 0)
                {
                    var unitToUpdate = (from d in context.Units where d.UnitId == unit.UnitId select d).Single();

                    unitToUpdate = unit;
                    context.SaveChanges();
                }
                else
                {
                    AddUnit(unit);
                }
            }
        }
Exemplo n.º 4
0
        public static void UpdateRace(Race race)
        {
            using (var context = new ArmyContext())
            {
                if (race.RaceId > 0)
                {
                    var raceToUpdate = (from d in context.Races where d.RaceId == race.RaceId select d).Single();

                    raceToUpdate = race;
                    context.SaveChanges();
                }
                else
                {
                    AddRace(race);
                }
            }
        }
Exemplo n.º 5
0
        public static void UpdateTrait(Trait trait)
        {
            using (var context = new ArmyContext())
            {
                if (trait.TraitId > 0)
                {
                    var traitToUpdate = (from d in context.Traits where d.TraitId == trait.TraitId select d).Single();

                    traitToUpdate = trait;
                    context.SaveChanges();
                }
                else
                {
                    AddTrait(trait);
                }
            }
        }
Exemplo n.º 6
0
 public static void AddRace(Race race)
 {
     using (var context = new ArmyContext())
     {
         if (race.RaceId > 0)
         {
             UpdateRace(race);
         }
         else
         {
             context.Races.Add(race);
         }
         foreach (var trait in race.RaceTraits)
         {
             if (trait.TraitId <= 0)
             {
                 AddTrait(trait);
             }
         }
         context.SaveChanges();
     }
 }