コード例 #1
0
ファイル: GoalController.cs プロジェクト: grae22/BearChaser
        //---------------------------------------------------------------------------------------------

        private async Task <List <GoalAttempt> > GetAttemptsForPeriod(int goalId,
                                                                      DateTime periodStart,
                                                                      DateTime periodEnd)
        {
            return(await
                   _goalAttemptStore
                   .GetAttempts(goalId)
                   .Where(a => a.Timestamp >= periodStart && a.Timestamp <= periodEnd)
                   .ToListAsync());
        }
コード例 #2
0
        public async Task <IHttpActionResult> DeleteLastAttemptAsync(int goalId)
        {
            _log.LogDebug($"Request: goalId={goalId}");

            User user;

            try
            {
                user = await ControllerUtils.GetUserForRequestHeaderTokenAsync(this, _tokenStore, _userStore, _log);
            }
            catch (AuthenticationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InternalServerException)
            {
                return(InternalServerError());
            }

            Goal goal = await _goalStore.GetGoalAsync(goalId);

            if (goal == null || goal.UserId != user.Id)
            {
                _log.LogDebug($"Goal not found with id {goalId} for user {user.Id}.");
                return(NotFound());
            }

            GoalAttempt lastAttempt =
                await _attemptStore.GetAttempts(goalId)
                .OrderByDescending(a => a.Timestamp)
                .FirstOrDefaultAsync();

            await _attemptStore.RemoveAttemptAsync(lastAttempt.Id);

            _log.LogInfo($"Deleted goal-attempt {lastAttempt.Id} for user {user.Id}.");

            return(Ok());
        }