Exemplo n.º 1
0
 public IEnumerable <Hero> GetHeroes()
 {
     using (var dbContext = new HeroDbContext())
     {
         return(dbContext.Heroes.Where(x => x.Active).ToList());
     }
 }
Exemplo n.º 2
0
 public Hero GetHeroById(int id)
 {
     using (var dbContext = new HeroDbContext())
     {
         return(dbContext.Heroes.FirstOrDefault(x => x.Active && x.Id == id));
     }
 }
Exemplo n.º 3
0
 public void SaveHero(string name)
 {
     using (var dbContext = new HeroDbContext())
     {
         dbContext.Heroes.Add(new Hero {
             Name = name, Active = true
         });
         dbContext.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void DeleteHero(int id)
 {
     using (var dbContext = new HeroDbContext())
     {
         var hero = dbContext.Heroes.FirstOrDefault(x => x.Id == id);
         if (hero != null)
         {
             if (hero.Active)
             {
                 hero.Active = false;
                 dbContext.Heroes.AddOrUpdate(hero);
                 dbContext.SaveChanges();
             }
         }
     }
 }