示例#1
0
        public bool FileComplaint(BsonDocument document)
        {
            var mg = new MongoConn("mongodb://localhost", "test");
            var dc = new DataCollection(mg.database);

            return(dc.CreateComplaint(document));
        }
        public void Delete(string id)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            FilterDefinition <Book> filter = new BsonDocument("_id", Int32.Parse(id));

            collection.DeleteOne(filter);
        }
        public void Put(int id, [FromBody] Book book)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            FilterDefinition <Book> filter = new BsonDocument("_id", id);

            collection.ReplaceOne(filter, book);
        }
        public void Put(int id, [FromBody] Genre genre)
        {
            IMongoCollection <Genre> collection = MongoConn.getCollectionGenres();

            FilterDefinition <Genre> filter = new BsonDocument("_id", id);

            collection.ReplaceOne(filter, genre);
        }
        public string GetAllBooks()
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            var query =
                from e in collection.AsQueryable <Book>()
                select e;

            string jsonString = JsonSerializer.Serialize(query);

            return(jsonString);
        }
示例#6
0
        public ActionResult GetFacilities(int zipCode)
        {
            var mg = new MongoConn("mongodb://localhost", "test");
            var dc = new DataCollection(mg.database);

            var result = new JsonResult()
            {
                ContentType = "application/json",
                Data        = dc.GetItemsByField("zipcode", zipCode.ToString()).ToArray()
            };

            return(result);
        }
        public string GetById(string id)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            var query =
                from e in collection.AsQueryable <Book>()
                where e.Id == Int32.Parse(id)
                select e;

            string jsonString = JsonSerializer.Serialize(query);

            return(jsonString);
        }
        public string GetByTitle(string title)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            var query =
                from e in collection.AsQueryable <Book>()
                where e.Title == title
                select e;

            List <Book> listBooks = new List <Book>();

            foreach (var books in query)
            {
                listBooks.Add(books);
            }

            string jsonString = JsonSerializer.Serialize(listBooks);

            return(jsonString);
        }
        public string GetByName(string nom)
        {
            IMongoCollection <Genre> collection = MongoConn.getCollectionGenres();

            var query =
                from e in collection.AsQueryable <Genre>()
                where e.Nom == nom
                select e;

            List <Genre> listGenres = new List <Genre>();

            foreach (var genres in query)
            {
                listGenres.Add(genres);
            }

            string jsonString = JsonSerializer.Serialize(listGenres);

            return(jsonString);
        }
        public string GetByGenre(int id)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();


            var query =
                from e in collection.AsQueryable <Book>()
                where e.Genre[0].Id == id
                select e;

            List <Book> listBooks = new List <Book>();

            foreach (var books in query)
            {
                listBooks.Add(books);
            }


            try
            {
                var query2 =
                    from e in collection.AsQueryable <Book>()
                    where e.Genre[1].Id == id
                    select e;

                foreach (var books2 in query2)
                {
                    listBooks.Add(books2);
                }
            }
            catch (Exception e)
            {
            }

            //List<Book> listBooks2 = listBooks.Distinct();


            string jsonString = JsonSerializer.Serialize(listBooks);

            return(jsonString);
        }
示例#11
0
        static void Main(string[] args)
        {
            MongoConn mongoConn = new MongoConn();

            Console.WriteLine("Hello");
        }
        public void Post([FromBody] Book book)
        {
            IMongoCollection <Book> collection = MongoConn.getCollectionBooks();

            collection.InsertOne(book);
        }
        public void Post([FromBody] Genre genre)
        {
            IMongoCollection <Genre> collection = MongoConn.getCollectionGenres();

            collection.InsertOne(genre);
        }