Пример #1
0
        public void GetOrderItemIdReturnsGivenEntityOrderItemId()
        {
            const int expectedOrderItemId         = 55;
            var       eventPackageOrderItemEntity = new EventPackageOrderItemEntity(expectedOrderItemId, 0);

            long orderItemId = _eventPackageOrderItemTraits.GetOrderItemId(eventPackageOrderItemEntity);

            Assert.AreEqual(expectedOrderItemId, orderItemId, "GetOrderItemId returned incorrect ID.");
        }
Пример #2
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));
        }