public bool CheckWorkaholic() { int streak = 0; IEnumerable <Habit> hList = HabitRepository.GetHabitByUserId(_habit.UserID); foreach (Habit hb in hList) { IEnumerable <Log> logList = HabitRepository.GetLogDataByID(hb.ID, hb.UserID); Log temp = null; foreach (Log l in logList) { if (streak == 0) { temp = l; } else if ((l.Date_Log.Date - temp.Date_Log.Date).Days != 0) { continue; } foreach (string s in hb.DaysOff.value) { if (l.Date_Log.DayOfWeek.ToString().StartsWith(s)) { ++streak; if (streak >= 10) { return(true); } } } } } return(false); }
public void LogIn(DateTime Date_Log) { if (LogCount > 0) { IEnumerable <Log> logs = HabitRepository.GetLogDataByID(ID, UserID); if (logs.Count() > 0 && (Date_Log.Date - logs.ElementAt(logs.Count() - 1).Date_Log.Date).Days == 1) { CurrentStreak++; } else if (!Date_Log.Date.Equals(logs.ElementAt(logs.Count() - 1).Date_Log.Date)) { CurrentStreak = 1; } } else { CurrentStreak = 1; } if (LongestStreak < CurrentStreak) { LongestStreak = CurrentStreak; HabitRepository.UpdateLongestStreak(ID, LongestStreak); } HabitRepository.UpdateCurrentStreak(ID, CurrentStreak); HabitRepository.UpdateLogCount(ID, ++LogCount); Log log = new Log(ID, UserID, Date_Log); HabitRepository.SaveLogData(log); events.Add(new HabitLoggedInEvent(this, log)); }
public void ValidateBadgeAssignment() { IEnumerable <Log> logs = HabitRepository.GetLogDataByID(_habit.ID, _habit.UserID); IEnumerable <Badge_Assignment> AssignedBadges = Badge_AssignmentRepository.GetAssignedBadgeByUserID(_habit.UserID); List <string> badges = new List <string>(); if (AssignedBadges.Count() < 3) { foreach (Badge_Assignment bd in AssignedBadges) { badges.Add(bd._Badge.Name); } if (!badges.Contains("Dominating") && CheckDominating()) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Dominating", _log.Date_Log); } if (!badges.Contains("Workaholic") && CheckWorkaholic()) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Workaholic", _log.Date_Log); } if (!badges.Contains("Epic Comeback") && CheckEpic(_habit, logs)) { Badge_AssignmentRepository.SaveBadgeAssignmentData(_habit.UserID, "Epic Comeback", _log.Date_Log); } } }