Example #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();
        }
Example #2
0
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }