public async Task <JsonBoxData> ScanBoxes() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://10.10.14.13:8081/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { HttpResponseMessage response = await client.GetAsync("scanOnce"); if (response.IsSuccessStatusCode) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JsonBoxData)); Stream s = await response.Content.ReadAsStreamAsync(); JsonBoxData boxes = (JsonBoxData)ser.ReadObject(s); return(boxes); } } //catch (SocketException SE) catch (Exception E) { Console.WriteLine(E); return(null); } } return(null); }
public void ScanStash(JsonBoxData CurrentItems) { //Get all boxeditems in one list string[] BoxedItems = CurrentItems.Boxes[0].TagIDs.Concat(CurrentItems.Boxes[1].TagIDs).Concat(CurrentItems.Boxes[2].TagIDs).ToArray(); UpdateRemovedItems(CurrentItems, BoxedItems); UpdateReturnedItems(CurrentItems, BoxedItems); }
/// <summary> /// View of all box's contents /// </summary> /// <author>Daniel Sacdalan and Matt Lucrida</author> /// <returns></returns> public async Task <ActionResult> Index(string searchString) { DataAccess.DataAccess dataAccess = new DataAccess.DataAccess(); JsonBoxData CurrentItems = new JsonBoxData(); CurrentItems = await dataAccess.ScanBoxes(); // How are the box keys being assigned? if (CurrentItems != null) { dataAccess.ScanStash(CurrentItems); } return(View(Service.BoxIndex(searchString))); }
public void UpdateRemovedItems(JsonBoxData CurrentItems, string[] BoxedItems) { //Find all entries with NULL out times string[] RecordedInItems = (from I in db.Items join T in db.Itemtransactions on I.itemkey equals T.itemkey where T.out_time == null select I.RFIDkey).ToArray(); //Returns all items currently out of stash IEnumerable <string> OutItems = RecordedInItems.Except(BoxedItems); //Update each transaction to show item was removed. foreach (var item in OutItems) { //Find the transaction to update var update = from Item in db.Items join T in db.Itemtransactions on Item.itemkey equals T.itemkey where Item.RFIDkey == item && T.out_time == null select T; //Update the out_time //Will only loop once foreach (Itemtransaction It in update) { It.out_time = DateTime.UtcNow; } //Save changes to db try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } }
public void UpdateReturnedItems(JsonBoxData CurrentItems, String[] BoxedItems) { //numBoxes IS FOR DEBUGGING SET TO 3 WHEN FINSIHED int numBoxes = 3; for (int i = 0; i < numBoxes; i++) { int curBoxKey = CurrentItems.Boxes[i].BoxID; //Look at all the items that are boxed foreach (var item in BoxedItems) { //If there is any record with an out_time NULL, //that means it is in the box. bool Out = (from I in db.Items join T in db.Itemtransactions on I.itemkey equals T.itemkey where I.RFIDkey == item && T.out_time == null select T).Any(); //If there is NO record with the out_time NULL, //Then that means the item is being returned. if (!Out) { //Find the item's itemkey int curItemKey = (from I in db.Items where I.RFIDkey == item select I.itemkey).FirstOrDefault(); //Create new transaction record Itemtransaction Transaction = new Itemtransaction { itemkey = curItemKey, boxkey = curBoxKey, in_time = DateTime.UtcNow, out_time = null }; //Save the changes to the db try { db.Itemtransactions.Add(Transaction); db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } //else //{ // bool newRFID = ((from I in db.Items // where I.RFIDkey == item // select I).Any()) // || // ((from I in db.Items // where I.RFIDkey == item && I.delete_date != null // select I).Any()); // if (newRFID) // { // Item newItem = new Item // { // RFIDkey = item, // name = "NEW ITEM", // object_description = null, // itemgroupkey = null, // photokey = null, // create_date = DateTime.UtcNow // }; // try // { // db.Items.Add(newItem); // db.SaveChanges(); // } // catch (Exception e) // { // Console.WriteLine(e); // } // } //} } } }