Example #1
0
        /// <summary>
        /// 取得指定會員
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public GetMemberInfoResponse Get(string id)
        {
            var response = new GetMemberInfoResponse();

            MongoClient       client = new MongoClient("mongodb://localhost:27017");
            MongoDatabaseBase db     = (MongoDatabaseBase)client.GetDatabase("ntut");
            var membersCollection    = db.GetCollection <MembersCollection>("members");

            var query = Builders <MembersCollection> .Filter.Eq(e => e.uid, id);

            var doc = membersCollection.Find(query).ToListAsync().Result.FirstOrDefault();

            if (doc != null)
            {
                response.data.uid   = doc.uid;
                response.data.name  = doc.name;
                response.data.phone = doc.phone;
            }
            else
            {
                response.ok     = false;
                response.errMsg = "編號:" + id + "的會員不存在。";
            }

            return(response);
        }
        public GetMemberInfoResponse Get(string id)
        {
            /* 宣告指令的輸出結果 */
            var response = new GetMemberInfoResponse();

            /* Step1 連接MongoDB伺服器 */
            MongoClient client = new MongoClient("mongodb://localhost:27017");

            /* Step2 取得MongoDB資料庫(Database)和集合(Collection) */
            /*   Step2-1 取得ntut資料庫(Database) */
            MongoDatabaseBase db = client.GetDatabase("ntut") as MongoDatabaseBase;
            /*   Step2-2 取得members集合(Collection) */
            var membersCollection = db.GetCollection <MembersCollection>("members");

            /* Step3 取得指定會員的資訊 */
            /*   Step3-1 設定查詢式 */
            var query = Builders <MembersCollection> .Filter.Eq(e => e.uid, id);

            /*   Step3-2 進行查詢的操作,並取得會員資訊 */
            var doc = membersCollection.Find(query).ToListAsync().Result.FirstOrDefault();

            /* Step4 設定指令的輸出結果 */
            if (doc != null)
            {
                /* Step4-1 當資料庫中存在該會員時,設定Response的data欄位 */
                response.data.uid   = doc.uid;
                response.data.name  = doc.name;
                response.data.phone = doc.phone;
            }
            else
            {
                /* Step4-2 當資料庫中沒有該會員時,設定Response的ok欄位與errMsg欄位 */
                response.ok     = false;
                response.errMsg = "沒有此會員";
            }

            return(response);
        }
Example #3
0
        public async Task <IActionResult> GetByUrlKey(string urlKey)
        {
            var group = await _groupsApi.GetByUrlKey(urlKey);

            var memberInfoResponse = new GetMemberInfoResponse();

            if (User.Identity.IsAuthenticated)
            {
                memberInfoResponse = (await _groupsApi.MemberInfo(group.Result.Id)).Result;
            }

            var response = new ApiSuccessResponse <GetGroupByIdCompositionResponse>
            {
                Code   = 200,
                Result = new GetGroupByIdCompositionResponse
                {
                    Group      = group.Result,
                    MemberInfo = memberInfoResponse
                }
            };

            return(Ok(response));
        }