Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
 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);
             }
         }
     }
 }
Пример #4
0
        public void InsertRecord <T>(string table, T record, string id, string caseID)
        {
            var collection = db.GetCollection <T>(table);


            Type typeParameterType = typeof(T);

            if (typeParameterType.Name == "SerialInfo")
            {
                var serialCollection = db.GetCollection <SerialInfo>("Serial");

                collection.InsertOne(record);

                serialCollection.FindOneAndUpdate(c => c.serial == id,
                                                  Builders <SerialInfo> .Update.Set(c => c.caseID, caseID));
            }
            else if (typeParameterType.Name == "CaseInfo")
            {
                if (!RecordExists <T>(table, id, "caseID"))
                {
                    var caseCollection = db.GetCollection <CaseInfo>("Cases");

                    collection.InsertOne(record);
                }
                else
                {
                    CaseInfo a = (CaseInfo)(object)record;
                    var      caseCollection = db.GetCollection <CaseInfo>("Cases");
                    caseCollection.FindOneAndUpdate(c => c.caseID == id,
                                                    Builders <CaseInfo> .Update.Set(c => c.curLoc, a.curLoc));
                    caseCollection.FindOneAndUpdate(c => c.caseID == id,
                                                    Builders <CaseInfo> .Update.Set(c => c.ageInfo, a.ageInfo));
                }
            }
            else if (typeParameterType.Name == "AreaInfo")
            {
                if (!RecordExists <T>(table, id, "areaName"))
                {
                    var caseCollection = db.GetCollection <AreaInfo>("Areas");

                    collection.InsertOne(record);
                }
            }
        }
Пример #5
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));
                    }
                }
            }
        }