Exemplo n.º 1
0
 public static int SaveEntityCollection(IEntityCollection2 entitiesToSave)
 {
     using (DataAccessAdapterBase dataAccessAdapterBase = new DataAccessAdapter(ManageBase.ConnectionString))
     {
         return(dataAccessAdapterBase.SaveEntityCollection(entitiesToSave, true, false));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Saves the orders passed in
 /// </summary>
 /// <param name="orders">The orders.</param>
 public void SaveOrders(IEntityCollection2 orders)
 {
     using (DataAccessAdapter adapter = new DataAccessAdapter())
     {
         adapter.SaveEntityCollection(orders, false, true);
     }
 }
Exemplo n.º 3
0
        public OrderItem GetOrderItem(long orderItemId)
        {
            IOrderItemTraits orderItemTraits;
            long             itemId;

            using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData  = new LinqMetaData(myAdapter);
                var orderItemType = (OrderItemType)linqMetaData.OrderItem.Single(oi => oi.OrderItemId == orderItemId).Type;
                orderItemTraits = _orderItemTraitsFactory.CreateTraits(orderItemType);

                if (orderItemType == OrderItemType.CancellationFee)
                {
                    return(orderItemTraits.CreateOrderItem(orderItemId, orderItemId));
                }

                IPredicate         orderItemPredicate = orderItemTraits.OrderItemIdPredicate(orderItemId);
                IEntityCollection2 itemEntities       = orderItemTraits.CreateItemEntityCollection();
                myAdapter.FetchEntityCollection(itemEntities, new RelationPredicateBucket(orderItemPredicate));
                if (itemEntities.HasSingleItem())
                {
                    itemId = orderItemTraits.GetItemId(itemEntities[0]);
                }
                else
                {
                    throw new DuplicateObjectException <OrderItem>();
                }
            }
            return(orderItemTraits.CreateOrderItem(orderItemId, itemId));
        }
Exemplo n.º 4
0
 protected void ExpectLinqFetchEntityCollection(IEntityCollection2 entitiesToReturn)
 {
     _entitiesToReturn = entitiesToReturn;
     Expect.Call(_dataAccessAdapter.FunctionMappings).Return(new FunctionMappingStore());
     Expect.Call(() => _dataAccessAdapter.FetchEntityCollection(null, null, 0, null, null, null, 0, 0)).
     IgnoreArguments().Callback(new FetchLinqEntityCollectionDelegate(FetchEntityCollection));
 }
Exemplo n.º 5
0
        public void CreateItemEntityCollectionReturnsEmptyEntityCollection()
        {
            const int expectedNumberOfEntities = 0;

            IEntityCollection2 entityCollection = _testOrderItemTraits.CreateItemEntityCollection();

            Assert.AreEqual(expectedNumberOfEntities, entityCollection.Count, "CreateItemEntityCollection returned nonempty collection of entities.");
        }
Exemplo n.º 6
0
 private bool FetchEntityCollection(IEntityCollection2 collection, IRelationPredicateBucket bucket)
 {
     if (_entitiesToReturn != null)
     {
         foreach (IEntity2 entity in _entitiesToReturn)
         {
             collection.Add(entity);
         }
     }
     return(true);
 }
 private bool SaveData(IEntityCollection2 customerHealthInfoEntitities)
 {
     using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
     {
         if (myAdapter.SaveEntityCollection(customerHealthInfoEntitities) > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 8
0
 private bool FetchEntityCollection(IEntityCollection2 collection, IRelationPredicateBucket bucket)
 {
     if (collection != null)
     {
         collection.Add(new GlobalConfigurationEntity
         {
             Name = ConfigurationSettingName.EpochDate.ToString(), Value = _expectedDateString
         });
     }
     return(true);
 }
Exemplo n.º 9
0
 private bool FetchEntityCollectionWithSortExpression(IEntityCollection2 collection,
                                                      IRelationPredicateBucket bucket, int maxNumberOfItemsToReturn, ISortExpression sortExpression)
 {
     if (_entitiesToReturnForSortExpression != null)
     {
         foreach (IEntity2 entity in _entitiesToReturnForSortExpression)
         {
             collection.Add(entity);
         }
     }
     return(true);
 }
Exemplo n.º 10
0
        /// <summary>
        /// CTor
        /// </summary>
        public CustomersByProduct(INorthwindService service)
        {
            InitializeComponent();
            _dalService = service;

            // load products, sort them on ProductName asc.
            IEntityCollection2 products = _dalService.GetProductsSortedBy(ProductFields.ProductName, SortOperator.Ascending);

            // bind it to the combo box
            productSelectComboBox.DataSource    = products;
            productSelectComboBox.DisplayMember = ProductFields.ProductName.Name;
            productSelectComboBox.SelectedIndex = 0;
        }
Exemplo n.º 11
0
 private bool FetchEntityCollection(IEntityCollection2 collection, IRelationPredicateBucket bucket,
                                    int maxNumberOfItemsToReturn, ISortExpression sortExpression, IPrefetchPath2 prefetchPath,
                                    ExcludeIncludeFieldsList excludeIncludeFieldsList, int pageNumber, int pageSize)
 {
     if (_entitiesToReturn != null)
     {
         foreach (IEntity2 entity in _entitiesToReturn)
         {
             collection.Add(entity);
         }
     }
     return(true);
 }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
0
        private void productSelectComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            // get the selected product
            if (productSelectComboBox.SelectedItem == null)
            {
                return;
            }

            var selectedProduct          = (ProductEntity)productSelectComboBox.SelectedItem;
            IEntityCollection2 customers = _dalService.GetAllCustomersFilteredOnProduct(selectedProduct.ProductId);

            customers.AllowNew = false;

            // bind them
            customersDataGrid.DataSource = customers;
            _amountUnitsSoldTextBox.Text = _dalService.GetNumerOfTimesProductWasSold(selectedProduct.ProductId).ToString();
        }
        /// <summary>
        /// CTor
        /// </summary>
        public CustomerSelector(INorthwindService service)
        {
            InitializeComponent();

            // get all customers
            _allCustomers = service.GetAllCustomers();
            // bind to grid.
            customersDataGrid.DataSource = _allCustomers;

            if (_allCustomers.Count > 0)
            {
                // there are customers, enable select button
                selectButton.Enabled = true;

                // select first row.
                customersDataGrid.Select(0);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Supprime la collection d'entités passé en paramètre
 /// </summary>
 /// <param name="collection"></param>
 public void Delete(IEntityCollection2 collection)
 {
     // La prorpriété RemovedEntitiesTracker des collections n'étant pas toujours renseignée, je préfère faire un test pour que cela ne plante pas
     // plutôt que :
     // 1) d'être obligé de faire ce test à chaque appel
     // 2) obligé de renseigner les propriétés RemovedEntitiesTracker de toutes les collections à chaque récupération d'une entité
     if (collection != null)
     {
         try
         {
             this.adapter.DeleteEntityCollection(collection);
         }
         catch (Exception e)
         {
             throw new ApplicationException(MessageSuppressionImpossible, e);
         }
     }
 }
Exemplo n.º 16
0
        public IEnumerable <OrderItem> GetOrderItems(long[] orderItemId)
        {
            IOrderItemTraits orderItemTraits;
            long             itemId;
            var orderItems = new List <OrderItem>();

            using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData      = new LinqMetaData(myAdapter);
                var orderItemEntities = linqMetaData.OrderItem.Where(oi => orderItemId.Contains(oi.OrderItemId)).ToList();

                if (orderItemEntities.IsNullOrEmpty())
                {
                    throw new ObjectNotFoundInPersistenceException <OrderItem>();
                }

                var orderItemTypes = orderItemEntities.Select(oi => oi.Type).Distinct();

                foreach (var itemType in orderItemTypes)
                {
                    var orderItemType = (OrderItemType)itemType;
                    orderItemTraits = _orderItemTraitsFactory.CreateTraits(orderItemType);
                    orderItemEntities.Where(oi => oi.Type == itemType).ToList().
                    ForEach(oi =>
                    {
                        IPredicate orderItemPredicate   = orderItemTraits.OrderItemIdPredicate(oi.OrderItemId);
                        IEntityCollection2 itemEntities = orderItemTraits.CreateItemEntityCollection();
                        myAdapter.FetchEntityCollection(itemEntities, new RelationPredicateBucket(orderItemPredicate));
                        if (itemEntities.HasSingleItem())
                        {
                            itemId = orderItemTraits.GetItemId(itemEntities[0]);
                        }
                        else
                        {
                            throw new DuplicateObjectException <OrderItem>();
                        }

                        orderItems.Add(orderItemTraits.CreateOrderItem(oi.OrderItemId, itemId));
                    });
                }
                return(orderItems);
            }
        }
Exemplo n.º 17
0
 protected void ExpectFetchEntityCollectionWithSortExpression(IEntityCollection2 entityCollectionToReturn)
 {
     _entitiesToReturnForSortExpression = entityCollectionToReturn;
     ExpectFetchEntityCollectionWithSortExpression();
 }
Exemplo n.º 18
0
 public void FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, int maxNumberOfItemsToReturn, ISortExpression sortClauses)
 {
     adapter.FetchEntityCollection(collectionToFill, filterBucket, maxNumberOfItemsToReturn, sortClauses);
 }
Exemplo n.º 19
0
 public int SaveEntity(IEntityCollection2 entities)
 {
     return(Adapter.SaveEntityCollection(entities));
 }
        public void CreateItemEntityCollectionReturnsEntityCollectionOfGiftCertificateOrderItemEntities()
        {
            IEntityCollection2 entityCollection = _giftCertificateOrderItemTraits.CreateItemEntityCollection();

            Assert.IsInstanceOf <EntityCollection <GiftCertificateOrderItemEntity> >(entityCollection, "CreateItemEntityCollection returned collection of wrong type.");
        }
Exemplo n.º 21
0
 public static PagedDataSource GetPaging(IEntityCollection2 view, string page, int PageSize)
 {
     return GetPaging(view.DefaultView, page, PageSize);
 }
Exemplo n.º 22
0
        public void CreateItemEntityCollectionReturnsEntityCollectionOfTestOrderItemEntities()
        {
            IEntityCollection2 entityCollection = _testOrderItemTraits.CreateItemEntityCollection();

            Assert.IsInstanceOf <EntityCollection <EventTestOrderItemEntity> >(entityCollection, "CreateItemEntityCollection returned collection of wrong type.");
        }
Exemplo n.º 23
0
 protected void ExpectFetchEntityCollection(IEntityCollection2 entityCollectionToReturn)
 {
     _entitiesToReturn = entityCollectionToReturn;
     ExpectFetchEntityCollection();
 }
Exemplo n.º 24
0
 private void ExpectGetInstrumentsForPayment(IEntityCollection2 checkEntitiesToReturn)
 {
     ExpectGetDataAccessAdapterAndDispose();
     ExpectFetchEntityCollection(checkEntitiesToReturn);
     ExpectGetPaymentInstrumentsFromCheckEntities();
 }