private void CheckInDevices(List <DeviceObject> devices) { foreach (DeviceObject device in devices) { SerialInfo si = new SerialInfo(); si.serial = device.serialID; LocationData d = new LocationData(); d.curCase = device.caseID; d.date = DateTime.UtcNow.Date.ToString("MM/dd/yyyy"); d.time = DateTime.Now.ToString("h:mm:ss tt"); d.location = device.location; d.lastLocation = true; d.userID = "311015"; si.locationData.Add(d); if (MongoCRUD.GetInstance().RecordExists <SerialInfo>("Serial", device.serialID, "serial")) { MongoCRUD.GetInstance().AppendRecord <SerialInfo>("Serial", device.serialID, d); } else { MongoCRUD.GetInstance().InsertRecord("Serial", si, device.serialID, device.caseID); } CaseInfo ci = new CaseInfo(); ci.caseID = device.caseID; ci.curLoc = device.location; ci.ageInfo = DateTime.Now.ToString("MM-dd-yyyy hh: mm tt"); MongoCRUD.GetInstance().InsertRecord("Cases", ci, device.caseID, null); AreaInfo a = null; List <AreaInfo> areas = MongoCRUD.GetInstance().LoadRecords <AreaInfo>("Areas", null, null); foreach (AreaInfo area in areas) { foreach (LocationObject loc in area.locationsList) { if (device.location == loc.locName) { a = area; break; } } } if (a != null) { UpdateAreaLocCases(ci, a); } } }
public void UpdateLocationCases(LocationObject lo, AreaInfo ai, CaseInfo ci) { var collection = db.GetCollection <AreaInfo>("Areas"); Console.WriteLine(lo.locName + " UPDATED"); collection.FindOneAndUpdate(c => c.areaName == ai.areaName && c.locationsList.Any(s => s.locName == lo.locName), Builders <AreaInfo> .Update.Push(c => c.locationsList[-1].casesList, ci)); }
private void UpdateAreaLocCases(CaseInfo ci, AreaInfo area) { foreach (LocationObject lo in area.locationsList) { if (lo.locName == ci.curLoc) { if (!lo.casesList.Contains(ci)) { MongoCRUD.GetInstance().UpdateLocationCases(lo, area, ci); } } } }