Ejemplo n.º 1
0
 public void ClearChoreCompletion(CompleteChorePayload data)
 {
     if (!gl.TryEnterUpgradeableReadLock(LOCK_TIMEOUT))
     {
         throw new TimeoutException();
     }
     try
     {
         var dateToRemove     = GetDateTimeThisWeek(data.Day);
         var completedChores  = CompletedChores.Values;
         var completedRecords = completedChores.Where(x => x.ChildId == data.ChildId && x.ChoreId == data.ChoreId && x.Date.HasValue && IsDateMatch(x.Date.Value, dateToRemove)).ToList();
         if (!completedRecords.Any())
         {
             return;
         }
         gl.TryEnterWriteLock(LOCK_TIMEOUT);
         try
         {
             foreach (var completed in completedRecords)
             {
                 CompletedChores.Remove(completed.Id);
             }
             PersistToDisk();
         }
         finally
         {
             gl.ExitWriteLock();
         }
     }
     finally
     {
         gl.ExitUpgradeableReadLock();
     }
 }
Ejemplo n.º 2
0
 public void CompleteChore(CompleteChorePayload data)
 {
     if (!gl.TryEnterUpgradeableReadLock(LOCK_TIMEOUT))
     {
         throw new TimeoutException();
     }
     try
     {
         var dateToComplete   = GetDateTimeThisWeek(data.Day);
         var completedChores  = CompletedChores.Values;
         var alreadyCompleted = completedChores.Any(x => x.ChildId == data.ChildId && x.ChoreId == data.ChoreId && x.Date.HasValue && IsDateMatch(x.Date.Value, dateToComplete));
         if (alreadyCompleted)
         {
             return;
         }
         gl.TryEnterWriteLock(LOCK_TIMEOUT);
         try
         {
             var completedChoreId = ++MaxCompletedChoreId;
             CompletedChores.Add(completedChoreId, new CompletedChore(completedChoreId, data.ChoreId, data.ChildId, GetDateTimeThisWeek(data.Day)));
             PersistToDisk();
         }
         finally
         {
             gl.ExitWriteLock();
         }
     }
     finally
     {
         gl.ExitUpgradeableReadLock();
     }
 }
Ejemplo n.º 3
0
        public void CompleteChore(CompleteChorePayload data)
        {
            var dateToComplete = GetDateTimeThisWeek(data.Day);
            var endOfDay       = GetEndOfDay(dateToComplete);

            var alreadyCompleted =
                _dbContext.CompletedChores.Any(x => x.ChildId == data.ChildId &&
                                               x.ChoreId == data.ChoreId &&
                                               x.Date.HasValue &&
                                               x.Date.Value >= dateToComplete && x.Date.Value <= endOfDay);

            if (alreadyCompleted)
            {
                return;
            }

            var completedChore = new CompletedChore
            {
                ChoreId = data.ChoreId,
                ChildId = data.ChildId,
                Date    = dateToComplete
            };

            _dbContext.CompletedChores.Add(completedChore);
            _dbContext.SaveChanges();
        }
Ejemplo n.º 4
0
        public void ClearChoreCompletion(CompleteChorePayload data)
        {
            var dateToComplete = GetDateTimeThisWeek(data.Day);
            var endOfDay       = GetEndOfDay(dateToComplete);

            var completedChores =
                _dbContext.CompletedChores.Where(x => x.ChildId == data.ChildId &&
                                                 x.ChoreId == data.ChoreId &&
                                                 x.Date.HasValue &&
                                                 x.Date.Value >= dateToComplete && x.Date.Value <= endOfDay).ToList();

            if (!completedChores.Any())
            {
                return;
            }

            _dbContext.CompletedChores.RemoveRange(completedChores);
            _dbContext.SaveChanges();
        }