Esempio n. 1
0
        public async Task <double> AssessGoalProgress(Goal goal)
        {
            if (goal.Target <= 0)
            {
                return(0);
            }
            #region totalling
            double total = 0;
            var    today = DateTime.UtcNow.LocalTime();
            IEnumerable <Activity> activities = new List <Activity>();
            if (goal.TimeFrame == TimeFrame.Daily)
            {
                activities = _activityRepository.GetUserActivitiesByDay(goal.UserId, today);
            }
            //kind-of internationalized way to get first and last days of current week
            else if (goal.TimeFrame == TimeFrame.Weekly)
            {
                activities = _activityRepository.GetUserActivitiesByWeek(goal.UserId, today);
            }
            else if (goal.TimeFrame == TimeFrame.Monthly)
            {
                activities = _activityRepository.GetUserActivitiesByMonth(goal.UserId, today);
            }
            else if (goal.TimeFrame == TimeFrame.Yearly)
            {
                activities = _activityRepository.GetUserActivitiesByYear(goal.UserId, today.Year);
            }

            if (goal.Type == GoalType.Duration)
            {
                total = activities.Sum(d => d.Duration);
            }
            else if (goal.Type == GoalType.Distance)
            {
                total = activities.Sum(d => d.Distance);
            }
            else if (goal.Type == GoalType.Steps)
            {
                total = activities.Sum(s => s.Steps);
            }
            #endregion totalling

            var progress = total / goal.Target;
            if (progress < goal.Progress && progress < 1)
            {
                goal.Completed = false;
            }
            else if (progress >= 1 && !goal.Completed)
            {
                goal.Progress = progress;
                await _feedEventService.GenerateFeedEvent(goal);

                goal.Completed = true;
            }
            goal.Progress = progress;
            _goalRepository.Update(goal);
            return(goal.Progress);
        }
Esempio n. 2
0
        public async Task <long> CreateMembership(Membership membership)
        {
            _membershipRepository.Create(membership);
            await _unit.Commit();

            if (membership.Status == Status.Member || membership.Status == Status.Admin)
            {
                await _feedEventService.GenerateFeedEvent(membership);

                _userBadgeService.CheckGroupBadgeProgress(membership.UserId);
                await _unit.Commit();
            }
            return(membership.Id);
        }
Esempio n. 3
0
        public async Task <long> CreateUserBadge(UserBadge userBadge)
        {
            _userBadgeRepository.Create(userBadge);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(userBadge);

            await _unit.Commit();

            return(userBadge.Id);
        }
Esempio n. 4
0
        public async Task <long> CreateUserMood(UserMood userMood)
        {
            userMood = _userMoodRepository.Create(userMood);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(userMood);

            await _unit.Commit();

            return(userMood.Id);
        }
Esempio n. 5
0
        public async Task <long> CreateFood(Food food)
        {
            food = _foodRepository.Create(food);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(food);

            await _unit.Commit();

            return(food.Id);
        }
        public async Task <long> CreateEndOfDayReport(EndOfDayReport report)
        {
            _endOfDayReportRepository.Create(report);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(report);

            await _unit.Commit();

            return(report.Id);
        }
Esempio n. 7
0
        public async Task <long> CreateActivity(Activity activity)
        {
            activity = _activityRepository.Create(activity);
            await _unit.Commit();

            await _feedEventService.GenerateFeedEvent(activity);

            await UpdateGoals(activity.UserId);

            _userBadgeService.CheckActivityBadgeProgress(activity.UserId, activity);
            await _unit.Commit();

            return(activity.Id);
        }