Beispiel #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);
                    }
                }
            }
        }
Beispiel #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();
     }
 }
Beispiel #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);
                }
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #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();
     }
 }