public void Update(Grocery groceryItem, bool autoCommit = true)
 {
     groceryItem = updateNextPurchaseDate(groceryItem);
     groceryItemRepository.Update(groceryItem);
     if (autoCommit) groceryItemRepository.Commit();
     return;
 }
 public void Create(Grocery groceryItem)
 {
     groceryItem = updateNextPurchaseDate(groceryItem);
     groceryItemRepository.Add(groceryItem);
     groceryItemRepository.Commit();
     return;
 }
        private Grocery updateNextPurchaseDate(Grocery grocery)
        {
            switch(grocery.PurchaseFrequency)
            {
                case PurchaseFrequency.Weekly:
                    grocery.NextPurchaseAt = grocery.LastPurchasedAt.AddDays(7);
                    break;
                case PurchaseFrequency.EveryTwoWeeks:
                    grocery.NextPurchaseAt = grocery.LastPurchasedAt.AddDays(14);
                    break;
                case PurchaseFrequency.EveryMonth:
                    grocery.NextPurchaseAt = grocery.LastPurchasedAt.AddMonths(1);
                    break;
                case PurchaseFrequency.EveryTwoMonths:
                    grocery.NextPurchaseAt = grocery.LastPurchasedAt.AddMonths(2);
                    break;
                default:
                    throw new Exception(string.Format("Invalid PurchaseFrequency ({0}) specified for grocery {1}.",
                        grocery.PurchaseFrequency, grocery.Name));
            }

            return grocery;
        }
 public void Delete(Grocery item)
 {
     groceryItemRepository.Delete(item);
     groceryItemRepository.Commit();
 }