Esempio n. 1
0
 public static IEnumerable <Unit> GetUnits()
 {
     using (var context = new ArmyContext())
     {
         return(context.Units.ToList());
     }
 }
Esempio n. 2
0
 public static IEnumerable <Race> GetRaces()
 {
     using (var context = new ArmyContext())
     {
         return(context.Races.ToList());
     }
 }
Esempio n. 3
0
 public static Unit GetUnitById(int id)
 {
     using (var context = new ArmyContext())
     {
         return((from u in context.Units where u.UnitId == id select u).Single());
     }
 }
Esempio n. 4
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);
                    }
                }
            }
        }
Esempio n. 5
0
 public static Race GetRaceById(int id)
 {
     using (var context = new ArmyContext())
     {
         return((from r in context.Races where r.RaceId == id select r).Single());
     }
 }
Esempio n. 6
0
 public static Trait GetTraitById(int id)
 {
     using (var context = new ArmyContext())
     {
         return((from t in context.Traits where t.TraitId == id select t).Single());
     }
 }
Esempio n. 7
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();
     }
 }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
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);
                }
            }
        }
Esempio n. 11
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();
     }
 }