public List <RoomsListModel> GetRoomData() { ConnectDB conn = new ConnectDB(); var database = conn.Conn(); var RoomDataList = new List <RoomsListModel> { }; IMongoCollection <RoomsListModel> collection = database.GetCollection <RoomsListModel>("ROOM"); // sorting var sort = Builders <RoomsListModel> .Sort.Ascending("roomId"); //end sorting var RoomsDocuments = collection.Find(new BsonDocument()).Sort(sort); foreach (RoomsListModel set in RoomsDocuments.ToList()) { var data = new RoomsListModel() { roomId = set.roomId, }; RoomDataList.Add(data); } return(RoomDataList); }
public double GetCurrentValue(string Id) { ConnectDB conn = new ConnectDB(); var database = conn.Conn(); IMongoCollection <BsonDocument> collection; FilterDefinition <BsonDocument> filter; var dbStr = Id.Substring(0, 2) switch { "EF" => "EXH_FAN", "AC" => "AC", "LT" => "LIGHT", "HD" => "HUM", "CA" => "PI_CAM", _ => "" }; var json = new DBManger().DataBase.GetCollection <CurrentDataModel>(dbStr).Find(Builders <CurrentDataModel> .Filter.Eq("devicesId", Id)).Sort(Builders <CurrentDataModel> .Sort.Descending(s => s.latest_checking_time)).ToList(); if (json.Count() > 0 && json != null) { //Debug.WriteLine("current =="+ json.First().current+" "+ json.First().latest_checking_time); return(json.First().current); } else { //Debug.WriteLine("current ==0" ); return(0); } }
public object Post([FromBody] object SensorJson) { var json = System.Text.Json.JsonSerializer.Serialize(SensorJson); var data = JsonConvert.DeserializeObject <List <SensorsAddDataModel> >(json); var str = ""; ConnectDB conn = new ConnectDB(); IMongoDatabase database = conn.Conn(); var collection = database.GetCollection <BsonDocument>("SENSOR"); if (SensorJson != null) { foreach (var S in data) { string id = S.Sid; string Value = S.V; DateTime utcNow = DateTime.UtcNow; str += "{ SId , " + id + "},{ V," + Value + "},{ PD," + utcNow + "}\n"; collection.InsertOne(new BsonDocument { { "SId", id }, { "V", Value }, { "PD", utcNow } }); } } else { str = "Parameter cannot be null "; } return(str); }