Beispiel #1
0
        public IActionResult Index(int page = 1)
        {
            try
            {
                IndexGameSettingsViewModel model = new IndexGameSettingsViewModel
                {
                    GamesSettings = _gameSettingsLogic.List()
                                    .OrderBy(g => g.GameSettingId)
                                    .Skip((page - 1) * PageSize)
                                    .Take(PageSize),
                    PagingInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        ItemsPerPage = PageSize,
                        TotalItems   = _gameSettingsLogic.List().Count
                    }
                };

                return(View(model));
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, $"The following error occurred: {ex.Message} @ {GetType().Name}");
                ViewBag.ErrorMessage = ex.Message;

                return(View("Index"));
            }
        }
Beispiel #2
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Timed Background Service is starting.");

            // Set the default gameLength
            int     gameLength = 60;
            decimal winningPot = 5;

            (int, decimal)gameInformation = (gameLength, winningPot);

            try
            {
                GameSettings gameSettings = _gameSettingsLogic.List().FirstOrDefault();

                if (gameSettings != null)
                {
                    if (gameSettings.GameLength > 0 && Math.Abs(gameSettings.WinningPot) > 0)
                    {
                        gameInformation.Item1 = gameSettings.GameLength;
                    }

                    if (Math.Abs(gameSettings.WinningPot) > 0)
                    {
                        gameInformation.Item2 = gameSettings.WinningPot;
                    }
                }
            }
            catch (NotFoundException ex)
            {
                _logger.LogError($"Error: {ex.Message} @ {GetType().Name}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"The following error occurred: {ex.Message} @ {GetType().Name}");
            }

            _startGameTimer = new Timer(StartGame, gameInformation, TimeSpan.Zero,
                                        TimeSpan.FromSeconds((gameLength + 60) * 60));

            return(Task.CompletedTask);
        }