Пример #1
0
        public async Task <IActionResult> DetailsAsync(string titleId)
        {
            // get mongoDB Client
            mongoDatabase = GetMongoDatabase();

            // search mongoDB Collection
            FilterDefinition <BsonDocument> filter  = "{ _id: " + titleId + " }";
            FindOptions <BsonDocument>      options = new FindOptions <BsonDocument>
            {
                NoCursorTimeout = false
            };

            MongoDB.Driver.IAsyncCursor <BsonDocument> result = await mongoDatabase.GetCollection <BsonDocument>("Titles").FindAsync <BsonDocument>(filter, options);

            List <BsonDocument> resultDocs = result.ToList <BsonDocument>();

            //convert result to MediaItem
            MediaItem mItem = new MediaItem();

            if (resultDocs.Count > 0)
            {
                mItem = JsonConvert.DeserializeObject <MediaItem>(resultDocs[0].ToJson());
            }

            //return MediaItem (detail of selected Title) to View
            ViewBag["titleDetail"] = mItem;

            return(View());
        }
Пример #2
0
        public async Task <IActionResult> GetTitlesAsync(string searchString)
        {
            mongoDatabase = GetMongoDatabase();
            //FilterDefinition<BsonDocument> filter = FilterDefinition<BsonDocument>.Empty;
            // https: //docs.mongodb.com/manual/reference/operator/query/#query-selectors
            FilterDefinition <BsonDocument> filter  = "{ TitleName: { $text: " + "searchString" + " } }";
            FindOptions <BsonDocument>      options = new FindOptions <BsonDocument>
            {
                NoCursorTimeout = false
            };

            MongoDB.Driver.IAsyncCursor <BsonDocument> result = await mongoDatabase.GetCollection <BsonDocument>("Titles").FindAsync <BsonDocument>(filter, options);

            List <BsonDocument> resultDocs = result.ToList <BsonDocument>();

            //convert result to MediaItem
            MediaItem            mItem      = new MediaItem();
            List <MediaItem>     mItemList  = new List <MediaItem>();
            List <TitleListItem> mTitleList = new List <TitleListItem>();

            foreach (BsonDocument d in resultDocs)
            {
                mItem = JsonConvert.DeserializeObject <MediaItem>(d.ToJson());
                TitleListItem i = new TitleListItem();
                i.id        = mItem._id.ToString();
                i.TitleName = mItem.TitleName;

                mTitleList.Add(i);
            }

            //return list of titles for view
            ViewBag["titlelist"] = mTitleList;

            return(View());
        }