public static void SaveSortingOrders(SerializableIntIntPair[] pairings, int userId) { using (ProMaDB scope = new ProMaDB()) { foreach (SerializableIntIntPair curPairing in pairings) { SharedChoreMembership thisMembership = scope.SharedChoreMemberships.FirstOrDefault(x => x.SharedChoreId == curPairing.Key && x.UserId == userId); if (thisMembership == null) { throw new Exception("Attempted to save ordering for non existant membership"); } scope.SharedChoreMemberships.Attach(thisMembership); thisMembership.PersonalSortingOrder = curPairing.Value; } scope.SaveChanges(); } }
public static void AcceptRequestBetweenUsers(int recipient, int sender) { using (ProMaDB scope = new ProMaDB()) { FriendshipRequest toRemove = scope.FriendshipRequests.FirstOrDefault(x => x.RecipientId == recipient && x.SenderId == sender); if (toRemove != null) { scope.FriendshipRequests.Attach(toRemove); scope.FriendshipRequests.Remove(toRemove); } Friendship newFriendship = new Friendship(); newFriendship.MemberOneId = recipient; newFriendship.MemberTwoId = sender; FriendshipHandler.AddFriendship(newFriendship); scope.SaveChanges(); } AddToUserFriendshipCacheIterator(recipient); AddToUserFriendshipCacheIterator(sender); }
public static void AddSharedChoreMembership(int choreId, int userId) { using (ProMaDB scope = new ProMaDB()) { List <SharedChoreMembership> maximumSharedChoreOrdering = GetSharedChoreMembershipsForUser(userId); int orderForChore = 0; if (maximumSharedChoreOrdering.Count > 0) { orderForChore = maximumSharedChoreOrdering.Max(x => x.PersonalSortingOrder) + 1; } SharedChoreMembership newMembership = new SharedChoreMembership(); newMembership.UserId = userId; newMembership.SharedChoreId = choreId; newMembership.PersonalSortingOrder = orderForChore; scope.SharedChoreMemberships.Add(newMembership); scope.SaveChanges(); } CompletedChoreHandler.AddToUserChoreCacheIterator(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); } }