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)); }
public void CreateOrderItemReturnsTestItem() { OrderItem orderItem = _testOrderItemTraits.CreateOrderItem(0, 0); Assert.IsInstanceOf <EventTestItem>(orderItem, "CreateOrderItem returned OrderItem of incorrect derived type."); }
public void CreateOrderItemReturnsRefundItem() { OrderItem orderItem = _refundOrderItemTraits.CreateOrderItem(0, 0); Assert.IsInstanceOf <RefundItem>(orderItem, "CreateOrderItem returned OrderItem of incorrect derived type."); }
public void CreateOrderItemReturnsGiftCertificateItem() { OrderItem orderItem = _giftCertificateOrderItemTraits.CreateOrderItem(0, 0); Assert.IsInstanceOf <GiftCertificateItem>(orderItem, "CreateOrderItem returned OrderItem of incorrect derived type."); }
public void CreateOrderItemReturnsProductItem() { OrderItem orderItem = _productOrderItemTraits.CreateOrderItem(0, 0); Assert.IsInstanceOf <ProductItem>(orderItem, "CreateOrderItem returned OrderItem of incorrect derived type."); }