Example #1
0
        public void UpdateLastLocations(string id, string serial)
        {
            if (RecordExists <SerialInfo>("Serial", serial, "serial"))
            {
                SerialInfo list       = LoadRecords <SerialInfo>("Serial", "serial", serial)[0];
                var        collection = db.GetCollection <SerialInfo>("Serial");


                //loop through each locationData object and if object doesn't match the id of most recent entry then set last location to false, otherwise true
                foreach (LocationData ld in list.locationData)
                {
                    // Save the entire document back to the database

                    if (ld.ID != id)
                    {
                        collection.FindOneAndUpdate(c => c.serial == serial && c.locationData.Any(s => s.ID == ld.ID),
                                                    Builders <SerialInfo> .Update.Set(c => c.locationData[-1].lastLocation, false));
                    }
                    else
                    {
                        collection.FindOneAndUpdate(c => c.serial == serial && c.locationData.Any(s => s.ID == ld.ID),
                                                    Builders <SerialInfo> .Update.Set(c => c.locationData[-1].lastLocation, true));

                        collection.FindOneAndUpdate(c => c.serial == serial,
                                                    Builders <SerialInfo> .Update.Set(c => c.caseID, ld.curCase));
                    }
                }
            }
        }
Example #2
0
        public void UpdateCaseSerials(string serial)
        {
            if (RecordExists <SerialInfo>("Serial", serial, "serial"))
            {
                SerialInfo si = LoadRecords <SerialInfo>("Serial", "serial", serial)[0];

                if (RecordExists <CaseInfo>("Cases", si.caseID, "caseID"))
                {
                    var collection = db.GetCollection <CaseInfo>("Cases");

                    CaseInfo ci = LoadRecords <CaseInfo>("Cases", "caseID", si.caseID)[0];

                    if (!ci.serialList.Contains(si))
                    {
                        collection.FindOneAndUpdate(c => c.caseID == ci.caseID,
                                                    Builders <CaseInfo> .Update.Push(c => c.serialList, si));
                    }
                }
            }
        }