コード例 #1
0
 public void Update(Grocery groceryItem, bool autoCommit = true)
 {
     groceryItem = updateNextPurchaseDate(groceryItem);
     groceryItemRepository.Update(groceryItem);
     if (autoCommit) groceryItemRepository.Commit();
     return;
 }
コード例 #2
0
 public void Create(Grocery groceryItem)
 {
     groceryItem = updateNextPurchaseDate(groceryItem);
     groceryItemRepository.Add(groceryItem);
     groceryItemRepository.Commit();
     return;
 }
コード例 #3
0
        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;
        }
コード例 #4
0
 public void Delete(Grocery item)
 {
     groceryItemRepository.Delete(item);
     groceryItemRepository.Commit();
 }