Exemple #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));
            }
        }
Exemple #2
0
        public async Task <IActionResult> CreatePlayer([FromBody] PlayerViewModelIn newPlayer)
        {
            //dodać obsługe czy club istnieje!
            try
            {
                var player = _smartPlayerContext.Add(new Player()
                {
                    FirstName    = newPlayer.FirstName,
                    LastName     = newPlayer.LastName,
                    DateOfBirth  = newPlayer.DateOfBirth,
                    HeighOfUser  = newPlayer.HeightOfUser,
                    WeightOfUser = newPlayer.WeightOfUser,
                    ClubId       = newPlayer.ClubId
                });
                await _smartPlayerContext.SaveChangesAsync();

                return(Ok(player.Entity));
            }
            catch (Exception e)
            {
                return(BadRequest("Check if club exists"));
            }
        }
Exemple #3
0
        public async Task <IActionResult> Register([FromBody] ClubViewModel newClub)
        {
            try
            {
                var club = _smartPlayerContext.Add(new Club()
                {
                    Name         = newClub.ClubName,
                    DateOfCreate = DateTimeOffset.UtcNow,
                    PasswordHash = Convert.ToBase64String(Encoding.ASCII.GetBytes(newClub.Password))
                });
                await _smartPlayerContext.SaveChangesAsync();

                return(Ok(club.Entity));
            }
            catch (Exception e)
            {
                return(Ok(e));
            }
        }