// GET: api/Chains public IHttpActionResult Get() { var db = new SuperMarketDb(); var chainsDto = db.Chains.Select(c => new { chainId = c.ChainId, name = c.ChainName, stores = c.Stores.Select(s => new { storeId = s.StoreId, name = s.StoreName, city = s.City, address = s.Address, prices = s.Prices.Select(p => new { productPrice = p.ItemPrice, quantity = p.Quantity, unitquantity = p.UnitQuantity, product = new { name = p.Item.ItemName, ProductId = p.Item.ItemId, description = p.Item.ItemDescription } }) }) }); return(Ok(chainsDto)); }
private void UpdateCollections() { try { ChainShoppingCarts = new ObservableCollection <ChainShoppingCart>(); using (SuperMarketDb context = new SuperMarketDb()) { Chains = new ObservableCollection <Chain>(context.Chains); CreateProducts(context.Items); Prices = new ObservableCollection <Price>(context.Prices); FindMostExpensiveAndCheapestItems(); } foreach (Chain chain in Chains) { ChainShoppingCarts.Add(new ChainShoppingCart { ChainName = chain.ChainName, ChainId = chain.ChainId }); } } catch (Exception exception) { MessageBox.Show("An error occured in the application: " + exception.Message); } }
private bool ParseElements(long storeID, long chainID, long itemId, string itemType, string itemName, string itemDescription, string unitQuantity, string quantity, string isWeighted, double itemPrice) { using (SuperMarketDb context = new SuperMarketDb()) { Item item = CreateItem(context, itemId, itemType, itemName, itemDescription); CreatePrice(context, item, storeID, chainID, unitQuantity, quantity, isWeighted, itemPrice); } return(true); }
// GET: api/Stores public IHttpActionResult Get() { var db = new SuperMarketDb(); var stores = db.Stores.Select(s => new { s.StoreId, s.StoreName, s.ChainId, s.Address, s.City }); return(Ok(stores)); }
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(); } } }
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(); }
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); }
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); } } }
// GET: api/Products public IHttpActionResult Get() { var db = new SuperMarketDb(); var items = db.Items.Select(i => new { i.ItemId, i.ItemName, i.ItemDescription, Prices = i.Prices.Select(p => new { p.Quantity, p.UnitQuantity, p.Store.StoreId, p.Item.ItemId, p.Store.ChainId, p.ItemPrice }), }); return(Ok(items)); }