示例#1
0
 public static IEnumerable <Unit> GetUnits()
 {
     using (var context = new ArmyContext())
     {
         return(context.Units.ToList());
     }
 }
示例#2
0
 public static IEnumerable <Race> GetRaces()
 {
     using (var context = new ArmyContext())
     {
         return(context.Races.ToList());
     }
 }
示例#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());
     }
 }
示例#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);
                    }
                }
            }
        }
示例#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());
     }
 }
示例#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());
     }
 }
示例#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();
     }
 }
示例#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);
                }
            }
        }
示例#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);
                }
            }
        }
示例#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);
                }
            }
        }
示例#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();
     }
 }