Ejemplo n.º 1
0
        public void ItemIdPredicateReturnsPredicateComparingTestIdToGivenId()
        {
            const int  testOrderItemId   = 234;
            IPredicate expectedPredicate = TestOrderItemFields.TestId == testOrderItemId;

            IPredicate predicate = _testOrderItemTraits.ItemIdPredicate(testOrderItemId);

            Assert.AreEqual(expectedPredicate, predicate, "ItemIdPredicate returned incorrect predicate.");
        }
Ejemplo n.º 2
0
        public void ItemIdPredicateReturnsPredicateComparingRefundIdToGivenId()
        {
            const int  refundOrderItemId = 234;
            IPredicate expectedPredicate = RefundOrderItemFields.RefundId == refundOrderItemId;

            IPredicate predicate = _refundOrderItemTraits.ItemIdPredicate(refundOrderItemId);

            Assert.AreEqual(expectedPredicate, predicate, "ItemIdPredicate returned incorrect predicate.");
        }
Ejemplo n.º 3
0
        public void ItemIdPredicateReturnsPredicateComparingEventPackageIdToGivenId()
        {
            const int  eventPackageOrderItemId = 234;
            IPredicate expectedPredicate       = EventPackageOrderItemFields.EventPackageId == eventPackageOrderItemId;

            IPredicate predicate = _eventPackageOrderItemTraits.ItemIdPredicate(eventPackageOrderItemId);

            Assert.AreEqual(expectedPredicate, predicate, "ItemIdPredicate returned incorrect predicate.");
        }
        public void ItemIdPredicateReturnsPredicateComparingGiftCertificateIdToGivenId()
        {
            const int  giftCertificateOrderItemId = 234;
            IPredicate expectedPredicate          = GiftCertificateOrderItemFields.GiftCertificateId == giftCertificateOrderItemId;

            IPredicate predicate = _giftCertificateOrderItemTraits.ItemIdPredicate(giftCertificateOrderItemId);

            Assert.AreEqual(expectedPredicate, predicate, "ItemIdPredicate returned incorrect predicate.");
        }
        public void ItemIdPredicateReturnsPredicateComparingProductIdToGivenId()
        {
            const int  productOrderItemId = 234;
            IPredicate expectedPredicate  = ProductOrderItemFields.ProductId == productOrderItemId;

            IPredicate predicate = _productOrderItemTraits.ItemIdPredicate(productOrderItemId);

            Assert.AreEqual(expectedPredicate, predicate, "ItemIdPredicate returned incorrect predicate.");
        }
Ejemplo n.º 6
0
        public OrderItem SaveOrderItem(long itemId, OrderItemType orderItemType)
        {
            long orderItemId;

            IOrderItemTraits   orderItemTraits      = _orderItemTraitsFactory.CreateTraits(orderItemType);
            IPredicate         itemIdPredicate      = orderItemTraits.ItemIdPredicate(itemId);
            IEntityCollection2 itemEntityCollection = orderItemTraits.CreateItemEntityCollection();

            using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                // Check to make sure that this item isn't already mapped to another OrderItem.
                myAdapter.FetchEntityCollection(itemEntityCollection, new RelationPredicateBucket(itemIdPredicate));
                if (itemEntityCollection.Count > 0)
                {
                    IEntity2 entity = itemEntityCollection[0];
                    // Get order item ID based off of item ID.
                    return(orderItemTraits.CreateOrderItem(orderItemTraits.GetOrderItemId(entity), itemId));
                }

                myAdapter.StartTransaction(IsolationLevel.ReadCommitted, "SaveNewOrderItemTransaction");
                try
                {
                    // Insert a new entry into the OrderItem table.
                    var orderItemEntity = new OrderItemEntity {
                        Type = (short)orderItemType
                    };
                    if (!myAdapter.SaveEntity(orderItemEntity))
                    {
                        throw new PersistenceFailureException();
                    }
                    // Insert a new entry into the corresponding mapping Item table.
                    orderItemId = orderItemEntity.OrderItemId;
                    IEntity2 itemEntityToSave = orderItemTraits.CreateItemEntity(orderItemId, itemId);
                    if (!myAdapter.SaveEntity(itemEntityToSave))
                    {
                        throw new PersistenceFailureException();
                    }
                    myAdapter.Commit();
                }
                catch (Exception)
                {
                    myAdapter.Rollback();
                    throw;
                }
            }
            return(orderItemTraits.CreateOrderItem(orderItemId, itemId));
        }