/** * Record the milestone BinaryAnswer for the given milestone ID and then remove it from the unanswered milestones list. */ public void AddOrUpdateMilestoneHistory(int milestoneID, BinaryAnswer answer) { MilestoneDatabaseAccess milestoneDatabaseAccess = new MilestoneDatabaseAccess(); milestoneDatabaseAccess.InitializeSync(); Milestone milestone = milestoneDatabaseAccess.GetMilestoneByIdSync(milestoneID); MilestoneHistory.UpdateOrInsertToMilestoneHistory(milestone, answer); Boolean milestoneRemoved = UnansweredMilestones.RemoveMilestone(milestone); }
/** * Return dictionary of milestones with responses organized by MilestoneCategory. **/ public Dictionary <MilestoneCategory, List <MilestoneWithResponse> > GetMilestoneResponseHistoryForAllCategories() { // Create result dictionary for milestones with responses organized by category. Dictionary <MilestoneCategory, List <MilestoneWithResponse> > result = new Dictionary <MilestoneCategory, List <MilestoneWithResponse> >(); // Get Milestone history. Dictionary <MilestoneCategory, Dictionary <int, MilestoneAnswer> > milestoneHistory = MilestoneHistory.GetMilestoneHistory(); // For each Milestone Category, find all milestones responses for that category and create MilestoneWithResponse pair via database retrieval. foreach (MilestoneCategory category in Enum.GetValues(typeof(MilestoneCategory))) { // Create new list for current Milestone Category to add to result dictionary. List <MilestoneWithResponse> milestoneWithResponseForCategory = new List <MilestoneWithResponse>(); // Get MilestoneAnswers for the current category. Dictionary <int, MilestoneAnswer> milestonesForCategory = milestoneHistory[category]; if (null != milestonesForCategory && milestonesForCategory.Count > 0) { List <int> milestoneIds = new List <int>(milestonesForCategory.Keys); // Retrieve milestones corresponding to list of MilestoneIds from database. List <Milestone> milestones = GetMilestonesByIds(milestoneIds); foreach (Milestone milestone in milestones) { BinaryAnswer answerForMilestone = milestonesForCategory[milestone.ID].Answer; milestoneWithResponseForCategory.Add(new MilestoneWithResponse(milestone, answerForMilestone)); } } // Add list for current Milestone Category to result dictionary. result[category] = milestoneWithResponseForCategory; } return(result); }