Example #1
0
        private static void InsertCatalogueEntities()
        {
            using (TransactionScope lScope = new TransactionScope())
            using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer())
            {
                if (lContainer.Medias.Count() == 0)
                {
                    Media lGreatExpectations = new Media()
                    {
                        Director = "Rene Clair",
                        Genre = "Fiction",
                        Price = 20.0M,
                        Title = "And Then there were None",
                        UPC="A"
                    };

                    //lContainer.Media.AddObject(lGreatExpectations);
                    //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                    //    CommandFactory.Instance.GetEntityInsertCommand<Media>(lGreatExpectations)
                    //);

                    Stock lGreatExpectationsStock = new Stock()
                    {
                        Media = lGreatExpectations,

                        // NEWLY ADDED
                        MediaId = lGreatExpectations.Id,


                        Holding = 5,
                        Warehouse = "Neutral Bay",
                        Quantity = 1
                    };

                    //lContainer.Stocks.AddObject(lGreatExpectationsStock);
                    //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                    //    CommandFactory.Instance.GetEntityInsertCommand<Stock>(lGreatExpectationsStock)
                    //);
                    ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                        CommandFactory.Instance.GetEntityInsertCommand<Media>(lGreatExpectations)
                    );


                    Media lSoloist = new Media()
                    {
                        Director = "The Soloist",
                        Genre = "Fiction",
                        Price = 15.0M,
                        Title = "The Soloist",
                        UPC="B"
                    };

                    //lContainer.Media.AddObject(lSoloist);
                    //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                    //    CommandFactory.Instance.GetEntityInsertCommand<Media>(lSoloist)
                    //);


                    Stock lSoloistStock = new Stock()
                    {
                        Media = lSoloist,

                        // NEWLY ADDED
                        MediaId = lSoloist.Id,

                        Holding = 7,
                        Warehouse = "Neutral Bay",
                        Quantity = 1
                    };

                    //lContainer.Stocks.AddObject(lSoloistStock);
                    //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                    //    CommandFactory.Instance.GetEntityInsertCommand<Stock>(lSoloistStock)
                    //);
                    ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                        CommandFactory.Instance.GetEntityInsertCommand<Media>(lSoloist)
                    );



                    for (int i = 0; i < 30; i++)
                    {
                        Media lItem = new Media()
                        {
                            Director = String.Format("Director {0}", i.ToString()),
                            Genre = String.Format("Genre {0}", i),
                            Price = i,
                            Title = String.Format("Title {0}", i),
                            UPC = i.ToString()
                        };

                        //lContainer.Media.AddObject(lItem);
                        //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                        //    CommandFactory.Instance.GetEntityInsertCommand<Media>(lItem)
                        //);

                        Stock lStock = new Stock()
                        {
                            Media = lItem,

                            // NEWLY ADDED
                            //MediaId = lItem.Id,


                            Holding = 7,
                            Warehouse = String.Format("Warehouse {0}", i),
                            Quantity = 1
                        };

                        //lContainer.Stocks.AddObject(lStock);
                        //ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                        //    CommandFactory.Instance.GetEntityInsertCommand<Stock>(lStock)
                        //);
                        ServiceLocator.Current.GetInstance<IPublisherService>().Publish(
                            CommandFactory.Instance.GetEntityInsertCommand<Media>(lItem)
                        );

                    }


                    //lContainer.SaveChanges();
                    lScope.Complete();
                }

                

            }

        }
Example #2
0
     private void FixupStocks(Stock previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && ReferenceEquals(previousValue.Media, this))
         {
             previousValue.Media = null;
         }
 
         if (Stocks != null)
         {
             Stocks.Media = this;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Stocks")
                 && (ChangeTracker.OriginalValues["Stocks"] == Stocks))
             {
                 ChangeTracker.OriginalValues.Remove("Stocks");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Stocks", previousValue);
             }
             if (Stocks != null && !Stocks.ChangeTracker.ChangeTrackingEnabled)
             {
                 Stocks.StartTracking();
             }
         }
     }
Example #3
0
        private static void InsertCatalogueEntities()
        {
            using (TransactionScope lScope = new TransactionScope())
            using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer())
            {
                if (lContainer.Media.Count() == 0)
                {
                    Media lGreatExpectations = new Media()
                    {
                        Director = "Rene Clair",
                        Genre = "Fiction",
                        Price = 20.0M,
                        Title = "And Then there were None"
                    };

                    lContainer.Media.AddObject(lGreatExpectations);

                    Stock lGreatExpectationsStock = new Stock()
                    {
                        Media = lGreatExpectations,
                        Holding = 5,
                        Warehouse = "Neutral Bay"
                    };

                    lContainer.Stocks.AddObject(lGreatExpectationsStock);

                    Media lSoloist = new Media()
                    {
                        Director = "The Soloist",
                        Genre = "Fiction",
                        Price = 15.0M,
                        Title = "The Soloist"
                    };

                    lContainer.Media.AddObject(lSoloist);

                    Stock lSoloistStock = new Stock()
                    {
                        Media = lSoloist,
                        Holding = 7,
                        Warehouse = "Neutral Bay"
                    };

                    lContainer.Stocks.AddObject(lSoloistStock);

                    for (int i = 0; i < 30; i++)
                    {
                        Media lItem = new Media()
                        {
                            Director = String.Format("Director {0}", i.ToString()),
                            Genre = String.Format("Genre {0}", i),
                            Price = i,
                            Title = String.Format("Title {0}", i)
                        };

                        lContainer.Media.AddObject(lItem);

                        Stock lStock = new Stock()
                        {
                            Media = lItem,
                            Holding = 7,
                            Warehouse = String.Format("Warehouse {0}", i)
                        };

                        lContainer.Stocks.AddObject(lStock);
                    }

                    lContainer.SaveChanges();
                    lScope.Complete();
                }

            }
        }