public static CompletedChore GetPreviousCompletedChore(CompletedChore beforeThis) { using (ProMaDB scope = new ProMaDB()) { return(scope.CompletedChores.Where(x => x.SharedChoreId == beforeThis.SharedChoreId && x.ChoreDate < beforeThis.ChoreDate && x.Completed).OrderByDescending(x => x.ChoreDate).FirstOrDefault()); } }
private static List <CompletedChore> GetChoreItems(List <int> sharedChoreIds, DateTime day) { using (ProMaDB scope = new ProMaDB()) { List <CompletedChore> completedChores = scope.CompletedChores.Where(x => sharedChoreIds.Contains(x.SharedChoreId) && x.ChoreDate == day).ToList(); foreach (int curId in sharedChoreIds) { if (!completedChores.Any(x => x.SharedChoreId == curId)) { // if the item doesn't exist, we want to create it CompletedChore newItem = new CompletedChore(); newItem.SharedChoreId = curId; newItem.ChoreDate = day; completedChores.Add(newItem); } } List <CompletedChore> returnThis = new List <CompletedChore>(); foreach (int curId in sharedChoreIds) { returnThis.Add(completedChores.First(x => curId == x.SharedChoreId)); } return(returnThis); } }
public static void UnCompleteChore(int sharedChoreId, DateTime forDay) { using (ProMaDB scope = new ProMaDB()) { CompletedChore toRemove = scope.CompletedChores.FirstOrDefault(x => x.SharedChoreId == sharedChoreId && x.ChoreDate == forDay); scope.CompletedChores.Remove(toRemove); scope.SaveChanges(); } // change the cache for each user in this membership List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(sharedChoreId); foreach (SharedChoreMembership curMembership in memberships) { CompletedChoreHandler.AddToUserChoreCacheIterator(curMembership.UserId); } }
public static void CompleteChore(int sharedChoreId, DateTime forDay, int userId) { using (ProMaDB scope = new ProMaDB()) { CompletedChore newChore = new CompletedChore(); newChore.SharedChoreId = sharedChoreId; newChore.ChoreDate = forDay; newChore.Completed = true; newChore.UserId = userId; newChore.PostedTime = ProMaUser.NowTime(); scope.CompletedChores.Add(newChore); scope.SaveChanges(); } // change the cache for each user in this membership List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(sharedChoreId); foreach (SharedChoreMembership curMembership in memberships) { CompletedChoreHandler.AddToUserChoreCacheIterator(curMembership.UserId); } }