Пример #1
0
        public List <Drink> GetOpenDrinks(User user, int limit, int offset)
        {
            if (_settings.AddPenaltyOnRequest && _lastPenaltyRequestTime.AddHours(1) <= DateTime.Now)
            {
                _drinkBurpeeService.AddPenaltyDrinkBurpeesAsync(user);
                _lastPenaltyRequestTime = DateTime.Now;
            }

            if (limit <= 0 || limit > BusinessConstants.DRINK_COUNT_LIMIT_MAX + 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            return(user.Drinks
                   .Where(d => !d.IsClosed)
                   .OrderBy(d => d.CreatedDateTime)
                   .Skip(offset)
                   .Take(limit)
                   .ToList());
        }
Пример #2
0
        public async Task <IActionResult> AddPenaltyDrinkBurpees()
        {
            try
            {
                var user = await _userService.GetUserAsync(_settings.DefaultUserId);

                await _drinkBurpeeService.AddPenaltyDrinkBurpeesAsync(user);

                return(NoContent());
            }
            catch (Exception ex)
            {
                var msg = "Failed to calculate penalty burpees";
                _logger.LogError(ex, msg);
                return(StatusCode(500, msg));
            }
        }