Ejemplo n.º 1
0
        public List <AccountDO> Carregar()
        {
            IMongoDatabase db = MongoDBFactory.GetMongoDatabase();
            IMongoCollection <AccountDO> accCollection = db.GetCollection <AccountDO>("accounts");

            return(accCollection.Find(new BsonDocument()).ToList <AccountDO>());
        }
        public List <PostDO> CarregarPorData(DateTime data)
        {
            IMongoDatabase            db          = MongoDBFactory.GetMongoDatabase();
            IMongoCollection <PostDO> pCollection = db.GetCollection <PostDO>("posts");
            var result = pCollection.Find(x => x.CreatedTime >= data).ToList();

            result.OrderByDescending(x => x.CreatedTime).ToList();

            return(result);
        }
Ejemplo n.º 3
0
        public void Salvar(AccountDO obj)
        {
            IMongoDatabase db = MongoDBFactory.GetMongoDatabase();
            IMongoCollection <AccountDO> accCollection = db.GetCollection <AccountDO>("accounts");
            var result = accCollection.Find(x => x.Id == obj.Id).FirstOrDefault();

            if (result != null)
            {
                var filter = Builders <AccountDO> .Filter.Eq("Id", obj.Id);

                var update = Builders <AccountDO> .Update.Set("FirstName", obj.FirstName);

                accCollection.UpdateOne(filter, update);
            }
            else
            {
                accCollection.InsertOne(obj);
            }
        }
        public void Salvar(PostDO obj)
        {
            IMongoDatabase            db          = MongoDBFactory.GetMongoDatabase();
            IMongoCollection <PostDO> pCollection = db.GetCollection <PostDO>("posts");
            var result = pCollection.Find(x => x.Id == obj.Id).FirstOrDefault();

            if (result != null)
            {
                var filter = Builders <PostDO> .Filter.Eq("Id", obj.Id);

                var update = Builders <PostDO> .Update.Set("Message", obj.Message);

                pCollection.UpdateOne(filter, update);
            }
            else
            {
                pCollection.InsertOne(obj);
            }
        }