Exemplo n.º 1
0
        public async Task <IActionResult> SaveModule(string mac)
        {
            try
            {
                var module = await _moduleRepository.FindByCriteria(i => i.MACAddress.Equals(mac));

                if (module == null)
                {
                    return(BadRequest());
                }
                var playerInGame = (await _playerInGameRepository.GetListWithInclude(i => i.ModuleId == module.Id, i => i.Game).ConfigureAwait(false)).Last();
                if (playerInGame == null)
                {
                    return(BadRequest("Bad module mac"));
                }

                var now            = DateTimeOffset.UtcNow;
                var endOfMatchTime = playerInGame.Game.TimeOfStart.AddHours(3).UtcDateTime;
                var startOfMatch   = playerInGame.Game.TimeOfStart.UtcDateTime;
                if (startOfMatch.Ticks < now.Ticks && now.Ticks < endOfMatchTime.Ticks) //dodac drugi parametr czas zakonczenia
                {
                    return(Ok(new PlayerInGameViewModel()
                    {
                        GameId = playerInGame.GameId, PlayerId = playerInGame.PlayerId, ServerTime = (now.ToUnixTimeMilliseconds() - playerInGame.Game.TimeOfStart.ToUnixTimeMilliseconds()), Now = now, StartGame = playerInGame.Game.TimeOfStart
                    }));
                }
                return(BadRequest("Game is ended: " + $" Now:{now} | Start game:{startOfMatch} | End game: {endOfMatchTime}"));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> GetModules(int clubId)
        {
            var modules = await _moduleRepository.FindByCriteria(i => i.ClubId == clubId);

            var response = modules.Select(i => new Smartplayer.Authorization.WebApi.DTO.Module.Output.Module()
            {
                Id         = i.Id,
                ClubId     = i.ClubId,
                MACAddress = i.MACAddress,
                Name       = i.Name
            });

            return(Ok(response));
        }