示例#1
0
        public void Updatejson(string json)
        {
            var _client   = new MongoClient();
            var _database = _client.GetDatabase("surveys");
            var surveys   = _database.GetCollection <Mgsurvey>("surveys");
            var list      = surveys.Find(_ => true).ToListAsync <Mgsurvey>().Result;
            var l         = list.Find(_ => _.index == this.SurveyID);

            Mgsurvey tempsur = JsonConvert.DeserializeObject <Mgsurvey>(json);

            tempsur._id = l._id;

            surveys.ReplaceOneAsync <Mgsurvey>(_ => _._id == l._id, tempsur);
        }
示例#2
0
        public void createMG()
        {
            var _client   = new MongoClient();
            var _database = _client.GetDatabase("surveys");
            var surveys   = _database.GetCollection <Mgsurvey>("surveys");
            var solutions = _database.GetCollection <MgSolution>("Solution");

            string     newsurstring = "{\"index\":" + this.SurveyID.ToJson() + ", \"sname\": " + this.SurveyName.ToJson() + ", \"shortdescription\": \"" + this.SurveyJson + "\"" + ", nextqid: 1, \"pages\": [{page_title: \"untitle\", shortdescription: \"\", questions:[]}]}";
            string     newsolstring = "{\"index\":" + this.SurveyID.ToJson() + ", \"responses\": []}";
            Mgsurvey   newsur       = JsonConvert.DeserializeObject <Mgsurvey>(newsurstring);
            MgSolution newsol       = JsonConvert.DeserializeObject <MgSolution>(newsolstring);

            var updatesur = surveys.InsertOneAsync(newsur);
            var updatesol = solutions.InsertOneAsync(newsol);
        }