Exemplo n.º 1
0
 public List <FavouriteSuperHero> GetUserFavouriteHeroList(string userId)
 {
     using (SuperHeroDBEntities db = new SuperHeroDBEntities())
     {
         var user = AspNetUsersDb.GetUserIncludeFavouriteHeroesByIdAndDb(userId, db);
         return(user.FavouriteSuperHero.ToList());
     }
 }
Exemplo n.º 2
0
 public FavouriteSuperHero GetUserFavouriteHeroById(int apiId, string userId)
 {
     using (SuperHeroDBEntities db = new SuperHeroDBEntities())
     {
         var user = AspNetUsersDb.GetUserIncludeFavouriteHeroesByIdAndDb(userId, db);
         return(user.FavouriteSuperHero.Where(h => h.ApiId == apiId).FirstOrDefault());
     }
 }
Exemplo n.º 3
0
        public void SaveHeroToDb(FavouriteSuperHero newFavouriteHero, string userId)
        {
            using (SuperHeroDBEntities db = new SuperHeroDBEntities())
            {
                var user = AspNetUsersDb.GetUserIncludeFavouriteHeroesByIdAndDb(userId, db);

                using (DbContextTransaction tran = db.Database.BeginTransaction())
                {
                    newFavouriteHero.AspNetUsers.Add(user);
                    db.FavouriteSuperHero.Add(newFavouriteHero);
                    db.SaveChanges();
                    tran.Commit();
                }
            }
        }