Exemple #1
0
        public ActionResult AddSensorsData(SensorsListModel postData)        //post
        {
            //getdb();
            //var collection = database.GetCollection<MongoSensorsListModel>("SENSOR_LIST");

            MongoSensorsListModel insertList = new MongoSensorsListModel {
            };


            var    all   = GetSensorsData().Where(c => c.sensorId.Contains(postData.Sensortype));
            int    count = all.Count();
            string id    = postData.Sensortype + count;

            all = GetSensorsData().Where(c => c.sensorId == (id));



            while (all.Count() != 0)
            {
                count += 1;
                id     = postData.Sensortype + count;
                all    = GetSensorsData().Where(c => c.sensorId == (id));

                // code block to be executed
            }


            insertList.roomId   = postData.roomId;
            insertList.sensorId = postData.Sensortype + count;
            //insertList.location = postData.location;
            insertList.pos_x = postData.pos_x;
            insertList.pos_y = postData.pos_y;
            insertList.desc  = postData.desc;
            insertList.latest_checking_time = DateTime.UtcNow;
            insertList.total_run_time       = DateTime.UtcNow;
            try
            {
                new DBManger().DataBase.GetCollection <MongoSensorsListModel>("SENSOR_LIST").InsertOneAsync(insertList);
            }
            catch (Exception)
            {
                return(ReturnUrl());
            };

            return(ReturnUrl());
        }
Exemple #2
0
        public List <SensorsListModel> GetAllSensors()
        {
            List <SensorsListModel> SensorsDataList = new List <SensorsListModel> {
            };

            IQueryable <MongoSensorsListModel> query = from c in SensorsCollection.AsQueryable <MongoSensorsListModel>() select c;

            if (PageRoomId.Length == 0)
            {
                query = from c in SensorsCollection.AsQueryable <MongoSensorsListModel>() select c;
            }
            else
            {            //Sensors/{id}
                query = from c in SensorsCollection.AsQueryable <MongoSensorsListModel>() where c.roomId.Contains(PageRoomId) select c;
            }
            if (query.Count() > 0)
            {
                foreach (var set in query.ToList())
                {
                    var data = new SensorsListModel()
                    {
                        roomId               = set.roomId,
                        sensorId             = set.sensorId,
                        sensor_name          = set.sensor_name,
                        pos_x                = set.pos_x,
                        pos_y                = set.pos_y,
                        desc                 = set.desc,
                        latest_checking_time = set.latest_checking_time,
                        total_run_time       = set.total_run_time,
                        current_Value        = Convert.ToDouble(GetSensorCurrentValue(set.sensorId)),
                        current_Time         = Convert.ToDateTime(GetSensorCurrentDate(set.sensorId)),
                        typeImg              = GetType(set.sensorId),
                        typeUnit             = Getunit(set.sensorId),
                        Exception            = set.Exception,
                        status               = set.status
                    };
                    SensorsDataList.Add(data);
                }
            }
            return(SensorsDataList);
        }