public ObservableCollection <OnTheSpot.Models.Item> GetItems() { List <Item> dbItems = db.Items.ToList(); ObservableCollection <OnTheSpot.Models.Item> modelItems = new ObservableCollection <OnTheSpot.Models.Item>(); foreach (Item item in dbItems) { OnTheSpot.Models.Item model = new OnTheSpot.Models.Item() { ID = item.ID, BarCode = item.BarCode, CustID = item.CustID }; model.Category = new Models.Category() { ID = item.Category.ID, Description = item.Category.Description, Name = item.Category.Name }; modelItems.Add(model); } return(modelItems); }
public OnTheSpot.Models.Item getItem(string barcode) { // Item item = db.Items.Where(i => i.BarCode == barcode).SingleOrDefault(); //these will be no record of this barcode if this is the first time the item is scanned //when it is categorized there should only be 1 occurance but there seems to a bug where the uncategoryized //record is left in the BCS DB, so if we find more than 1 record look for the first that is NOT the uncategorized record //we will still throw if there is more than 1 found as we are really messed up Item item = null; List<Item> items = db.Items.Where(i => i.BarCode == barcode).ToList(); if (items.Count == 0) return null; if (items.Count > 1) //if there are multiple this is ok if all the same category { List<Category> distinct = items.Select(c => c.Category).Distinct().ToList(); if (distinct.Count > 1) throw new Exception("barcode cannot have mutliple categories"); } item = items.First(); OnTheSpot.Models.Item model = new OnTheSpot.Models.Item() { ID = item.ID, BarCode = item.BarCode, CustID = item.CustID, Note = item.Note, picture = item.picture }; model.Category = new Models.Category() { ID = item.Category.ID, Description = item.Category.Description, Name = item.Category.Name }; return model; }
public ObservableCollection<OnTheSpot.Models.Item> GetItems() { List<Item> dbItems = db.Items.ToList(); ObservableCollection<OnTheSpot.Models.Item> modelItems = new ObservableCollection<OnTheSpot.Models.Item>(); foreach (Item item in dbItems) { OnTheSpot.Models.Item model = new OnTheSpot.Models.Item() { ID = item.ID, BarCode = item.BarCode, CustID = item.CustID }; model.Category = new Models.Category() { ID = item.Category.ID, Description = item.Category.Description, Name = item.Category.Name }; modelItems.Add(model); } return modelItems; }