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 CreateItemEntityCollectionReturnsEntityCollectionOfTestOrderItemEntities() { IEntityCollection2 entityCollection = _testOrderItemTraits.CreateItemEntityCollection(); Assert.IsInstanceOf <EntityCollection <EventTestOrderItemEntity> >(entityCollection, "CreateItemEntityCollection returned collection of wrong type."); }
public void CreateItemEntityCollectionReturnsEntityCollectionOfGiftCertificateOrderItemEntities() { IEntityCollection2 entityCollection = _giftCertificateOrderItemTraits.CreateItemEntityCollection(); Assert.IsInstanceOf <EntityCollection <GiftCertificateOrderItemEntity> >(entityCollection, "CreateItemEntityCollection returned collection of wrong type."); }