Пример #1
0
        public async Task FavouriteGame(int gameId, int userId, bool isFavourited)
        {
            GamesFavourites gamesFavourites = await dbContext.Set <GamesFavourites>().FirstOrDefaultAsync(item => item.GameId == gameId && item.UserId == userId);

            if (gamesFavourites == null)
            {
                gamesFavourites              = new GamesFavourites();
                gamesFavourites.GameId       = gameId;
                gamesFavourites.UserId       = userId;
                gamesFavourites.IsFavourited = isFavourited;
                await dbContext.Set <GamesFavourites>().AddAsync(gamesFavourites);
            }
            else
            {
                gamesFavourites.IsFavourited           = isFavourited;
                dbContext.Entry(gamesFavourites).State = EntityState.Modified;
            }

            await dbContext.SaveChangesAsync();
        }
Пример #2
0
 public virtual async Task <T> GetByIdAsync(int id)
 {
     return(await _dbContext.Set <T>().FindAsync(id));
 }