public List <Goal> UpdateCurrentGoals(long activityId) { Activity activity = actRepo.Get(activityId); List <Goal> updated = new List <Goal>(); List <Goal> current = Repo.GetByAccountAndStatus(activity.AccountId, GoalStatus.Current).ToList(); foreach (Goal g in current) { Target t = tRepo.Get(g.TargetId); if ((t.ActivityType == TargetActivityType.Biking && activity.Type == ActivityType.Biking) || (t.ActivityType == TargetActivityType.Running && activity.Type == ActivityType.Running) || (t.ActivityType == TargetActivityType.Jogging && activity.Type == ActivityType.Jogging) || (t.ActivityType == TargetActivityType.Walking && activity.Type == ActivityType.Walking) || t.ActivityType == TargetActivityType.General) { if (t.Type == TargetType.Duration) { TimeSpan time = activity.Duration; g.Progress += time.TotalMinutes; } else if (t.Type == TargetType.Distance) { g.Progress += activity.Distance; } else if (t.Type == TargetType.Steps) { g.Progress += activity.Steps; } } if (t.TargetNumber < g.Progress) { g.Status = GoalStatus.Completed; g.EndDate = DateTime.UtcNow; } updated.Add(Repo.Update(g)); } Unit.SaveChanges(); return(updated); }
public ActionResult <IEnumerable <Target> > GetTarget() { var targets = _targetRepository.Get().ToList(); return(Ok(targets)); }
private bool Evaluate(string accountId, Badge b, long activityId) { Target t = tRepo.Get(b.TargetId); Activity activity = actRepo.Get(activityId); List <Activity> activities = new List <Activity>(); DateTime begin = activity.EndTime; DateTime end = begin; if (EqualActivityType(t.ActivityType, activity.Type)) { if (b.Timeline == BadgeTimeline.SingleActivity) { activities.Add(activity); } else if (b.Timeline == BadgeTimeline.Cumulative) { activities = actRepo.GetByAccountAndType(accountId, activity.Type).ToList(); } else { if (b.Timeline == BadgeTimeline.Daily) { begin.AddDays(-1); } else if (b.Timeline == BadgeTimeline.Weekly) { begin.AddDays(-7); } else if (b.Timeline == BadgeTimeline.Monthly) { begin.AddMonths(-1); } if (t.ActivityType == TargetActivityType.General) { activities = actRepo.GetByDate(accountId, begin, end).ToList(); } else { activities = actRepo.GetByDateAndType(accountId, begin, end, activity.Type).ToList(); } } } else { return(false); } double total = 0; if (t.Type == TargetType.Duration) { foreach (Activity a in activities) { total += a.Duration.TotalHours; } } else if (t.Type == TargetType.Distance) { foreach (Activity a in activities) { total += a.Distance; } } else if (t.Type == TargetType.Steps) { foreach (Activity a in activities) { total += a.Steps; } } if (total >= t.TargetNumber) { return(true); } else { return(false); } }
public Target Get(long id) { return(Repo.Get(id)); }