Esempio n. 1
0
 public static void UpdateSharedChoreMembership(SharedChoreMembership toUpdate)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.SharedChoreMemberships.Attach(toUpdate);
         scope.Entry(toUpdate).State = EntityState.Modified;
         scope.SaveChanges();
     }
 }
Esempio n. 2
0
        public static void RemoveSharedChoreMembership(int sharedChoreId, int userId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                SharedChoreMembership membership = scope.SharedChoreMemberships.FirstOrDefault(x => x.SharedChoreId == sharedChoreId && x.UserId == userId);
                scope.SharedChoreMemberships.Remove(membership);
                scope.SaveChanges();

                // while this may affect other users, we only care that it was removed from this user
                CompletedChoreHandler.AddToUserChoreCacheIterator(userId);
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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);
        }