Exemplo n.º 1
0
        public void LoadStoreXmlDataToDb(Chain chain, IEnumerable <Store> stores)
        {
            using (SuperMarketDb context = new SuperMarketDb())
            {
                context.Chains.AddOrUpdate(chain);
                context.SaveChanges();

                foreach (var store in stores)
                {
                    context.Stores.AddOrUpdate(s => new { s.StoreId, s.ChainId }, store);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        private void CreatePrice(SuperMarketDb context, Item item, long storeID, long chainID, string unitQuantity, string quantity,
                                 string isWeighted, double itemPrice)
        {
            Price price = new Price();

            price.ItemPrice    = itemPrice;
            price.UnitQuantity = unitQuantity;
            price.Quantity     = quantity;
            price.IsWeighted   = isWeighted;

            price.Item  = context.Items.Find(item.ItemId);
            price.Store = context.Stores.Find(storeID, chainID);

            context.Prices.Add(price);
            context.SaveChanges();
        }
Exemplo n.º 3
0
        private Item CreateItem(SuperMarketDb context, long itemId, string itemType, string itemName, string itemDescription)
        {
            Item item = new Item()
            {
                ItemId          = itemId,
                ItemName        = itemName,
                ItemType        = itemType,
                ItemDescription = itemDescription
            };

            if (context.Items.Find(item.ItemId) != null)
            {
                return(item);
            }
            context.Items.AddOrUpdate(i => i.ItemId, item);
            context.SaveChanges();

            return(item);
        }
Exemplo n.º 4
0
        public void ClearDb()
        {
            using (var context = new SuperMarketDb())
            {
                try
                {
                    context.Chains.RemoveRange(context.Chains);
                    context.Stores.RemoveRange(context.Stores);
                    context.Items.RemoveRange(context.Items);
                    context.Prices.RemoveRange(context.Prices);

                    context.SaveChanges();
                }

                catch (Exception e)
                {
                    Console.WriteLine("Removing Db has failed!!!" + e.Message);
                }
            }
        }