public DailyProgressSummary BuildDailyProgress(DateTime date) { var start = date.Date; var end = (date.Date == DateTime.Today)? DateTime.Now : date.AddDays(1); var dailySummary = GetDailySummary(start, end); var sleepSummary = GetSleepSummary(start, end); var goals = _goalsRepository.GetGoals(_localStorage.GetCurrentUserId()); if (goals == null) { goals = new Goals(); } var progressSummary = new DailyProgressSummary { UserId = _localStorage.GetCurrentUserId(), DayId = dailySummary.StartTime.Date, StepsTaken = dailySummary.StepsTaken, StepsTakenGoal = goals.StepsTaken, CaloriesBurned = dailySummary.CaloriesBurnedSummary.TotalCalories, CaloriesBurnedGoal = goals.CaloriesBurned, SleepMinutes = (int)TimeUtil.GetDuration(sleepSummary.SleepDuration).TotalMinutes, SleepMinutesGoal = goals.SleepMinutes, ActiveMinutes = dailySummary.ActiveSeconds / 60, FloorsClimbed = dailySummary.FloorsClimbed, TotalDistance = dailySummary.DistanceSummary.TotalDistance, TotalDistanceOnFoot = dailySummary.DistanceSummary.TotalDistanceOnFoot }; return(progressSummary); }
public Goals GetGoals(string playerId = null) { _userId = _localStorage.GetCurrentUserId(); if (playerId != null) { _userId = playerId; } var goals = _goalsRepository.GetGoals(_userId); return(goals); }
public void UpdateBalance(DailyProgressSummary[] progress) { if (progress.IsNullOrEmpty()) { return; } var goals = _goalsRepository.GetGoals(progress.First().UserId); foreach (var summary in progress.Where(summary => summary.DayId != DateTime.Today)) { var crystals = CalculateByDay(summary, goals); if (crystals > 0) { _balanceHandler.SendTransaction(crystals, summary.DayId.ToString()); } } UpadteLastWeek(progress); }
private void UpdateUnassignedToPlayer(string initialId, Player player) { var userId = player.UserId; _playerRepository.RemovePlayer(initialId); _playerRepository.SavePlayer(player); _userTypeRepository.RemovePlayerTypeRecord(initialId); _userTypeRepository.SaveUserType(userId, UserType.Player, player.CoachId); var goals = _goalsRepository.GetGoals(initialId); _goalsRepository.RemoveGoals(initialId); _goalsRepository.SaveGoals(userId, goals); }
public async Task <IActionResult> GetActiveGoals() { try { System.Threading.Thread.Sleep(1000); var activeGoals = await _goalRepository.GetGoals(); return(Ok(new ApiResponseOKResult() { Data = activeGoals })); } catch (Exception ex) { _logger.LogError(ex, "Failed to fetch active goals"); return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiResponseFailure() { ErrorMessage = "Failed to fetch active goals" })); } }
public async Task <List <GoalModel> > GetGoalsService(long userId) { try { if (userId <= 0) { throw new ArgumentException("User not found"); } List <GoalModel> coreGoals = new List <GoalModel>(); List <Goal> dbGoals = await _goalsRepository.GetGoals(userId); if (dbGoals == null || dbGoals.Count == 0) { throw new Exception("No goals found"); } foreach (var goal in dbGoals) { if (goal.UserId == 0) { throw new ArgumentException("User not found"); } coreGoals.Add(Mapper.GoalsMapper.DbToCoreGoalModel(goal)); } return(coreGoals); } catch (ArgumentException ae) { throw new ArgumentException(ae.Message); } catch (Exception e) { throw new Exception(e.Message); } }