コード例 #1
0
        public async Task <IActionResult> SavePulseValue([FromBody] PulseSensorIn pulseSensorIn)
        {
            try
            {
                var playerInGame = await _smartPlayerContext.Set <PlayerInGame>().AsQueryable().SingleOrDefaultAsync(i => i.GameId == pulseSensorIn.GameId && i.PlayerId == pulseSensorIn.PlayerId).ConfigureAwait(false);

                if (playerInGame == null)
                {
                    return(BadRequest("Bad Game or PlayerId"));
                }

                var result = _smartPlayerContext.Add(new PulseSensorResult()
                {
                    Value          = pulseSensorIn.Value,
                    TimeOfOccur    = DateTimeOffset.UtcNow,
                    PlayerInGameId = playerInGame.Id
                });

                await _smartPlayerContext.SaveChangesAsync();

                return(Ok(result.Entity));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> RemoveFromGame(string playerId, string gameId)
        {
            //dodać obsługe czy gameId i PlayerId istnieje!
            try
            {
                int playerIdInt = 0;
                int gameIdInt   = 0;

                if (int.TryParse(playerId, out playerIdInt) && int.TryParse(gameId, out gameIdInt))
                {
                    var playerInGame = await _smartPlayerContext.Set <PlayerInGame>().FirstOrDefaultAsync(i => i.PlayerId == playerIdInt && i.GameId == gameIdInt);

                    if (playerInGame != null)
                    {
                        playerInGame.Active = false;
                        var result = _playerInGameRepository.Update(playerInGame);
                    }


                    return(Ok(true));
                }
                return(BadRequest("Bad Player or Game id"));
            }
            catch (Exception e)
            {
                return(BadRequest("Check if gameId or PlayerId exists in database"));
            }
        }
コード例 #3
0
        public async Task <TAggregate> FindWithInclude(Expression <Func <TAggregate, bool> > criteria, Expression <Func <TAggregate, object> > columns)
        {
            var result = await _smartPlayerContext
                         .Set <TAggregate>()
                         .AsQueryable()
                         .Include(columns)
                         .SingleOrDefaultAsync(criteria)
                         .ConfigureAwait(false);

            return(result);
        }
コード例 #4
0
 public BaseRepository(SmartPlayerContext smartPlayerContext)
 {
     _smartPlayerContext = smartPlayerContext;
     _dbSet = _smartPlayerContext.Set <TAggregate>();
 }