Esempio n. 1
0
        private async Task <bool> ValidFeedEvent <T>(FeedEvent e, Type type, T entity)
        {
            if (type == typeof(Activity))
            {
                e.Type        = EventType.Activity;
                e.Date        = (DateTime)GetProperty(type, "StartTime", entity);
                e.Description = string.Format("Completed {0:0.00} minutes of {1}", (double)GetProperty(type, "Duration", entity) / 60, (string)GetProperty(type, "Name", entity));
            }
            else if (type == typeof(UserBadge))
            {
                e.Type = EventType.Badge;
                e.Date = DateTime.UtcNow.LocalTime();
                var badge = await _badgeRepository.GetById((long)GetProperty(type, "BadgeId", entity));

                e.Description = string.Format("Earned the {0} badge", badge.Name);
            }
            else if (type == typeof(Food))
            {
                e.Type        = EventType.Food;
                e.Date        = (DateTime)GetProperty(type, "Time", entity);
                e.Description = string.Format("Ate {0}", (string)GetProperty(type, "FoodName", entity));
            }
            else if (type == typeof(Goal))
            {
                var goalType  = (GoalType)GetProperty(type, "Type", entity);
                var timeFrame = (TimeFrame)GetProperty(type, "TimeFrame", entity);
                var progress  = (double)GetProperty(type, "Progress", entity);
                var completed = (bool)GetProperty(type, "Completed", entity);
                Dictionary <GoalType, string> units = new Dictionary <GoalType, string>()
                {
                    { GoalType.Distance, "miles" },
                    { GoalType.Duration, "minutes" },
                    { GoalType.Steps, "steps" }
                };
                var target = (double)GetProperty(type, "Target", entity);
                if (goalType == GoalType.Duration)
                {
                    target /= 60;
                }
                if (progress < 1)
                {
                    e.Type        = EventType.GoalSet;
                    e.Date        = (DateTime)GetProperty(type, "SetDate", entity);
                    e.Description = string.Format("Set a new {0} {1} goal:  {2} {3}", timeFrame, goalType, target, units[goalType]);
                }
                else if (!completed)
                {
                    e.Type        = EventType.GoalAchieved;
                    e.Date        = DateTime.UtcNow.LocalTime();
                    e.Description = string.Format("Achieved a {0} {1} goal:  {2} {3}", timeFrame, goalType, target, units[goalType]);
                }
            }
            else if (type == typeof(Membership))
            {
                e.EventId = (long)GetProperty(type, "GroupId", entity);
                e.Date    = DateTime.UtcNow.LocalTime();
                var status = (Status)GetProperty(type, "Status", entity);
                var group  = await _groupRepository.GetById((long)GetProperty(type, "GroupId", entity));

                if (status == Status.Member || status == Status.Admin)
                {
                    e.Type        = EventType.GroupJoin;
                    e.Description = string.Format("Joined {0}", group.GroupName);
                }
                else if (status == Status.Left)
                {
                    e.Type        = EventType.GroupLeave;
                    e.Description = string.Format("Left {0}", group.GroupName);
                }
            }
            else if (type == typeof(UserMood))
            {
                e.Type = EventType.Mood;
                e.Date = (DateTime)GetProperty(type, "Time", entity);
                var mood = await _moodRepository.GetById((long)GetProperty(type, "MoodId", entity));

                e.Description = string.Format("Feeling {0}", mood.Type);
            }
            else if (type == typeof(EndOfDayReport))
            {
                e.Type = EventType.EndOfDay;
                var date = (DateTime)GetProperty(type, "Date", entity);
                e.Date        = date;
                e.Description = string.Format("End of Day Report for {0}", date.ToLocalTime().ToShortDateString());
            }
            else
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
 public async Task <Mood> FindMood(long id)
 {
     return(await _moodRepository.GetById(id));
 }