public void GetOne()
        {
            ProxyAPICallModels pac = new ProxyAPICallModels();

            // Act
            object result = pac.GetOne("560d002482b1591aa849ff6e");

            // Assert
            Assert.AreEqual(result, "0");
        }
        public void Creat()
        {
            ProxyAPICallModels pac = new ProxyAPICallModels();
            pac.API_Name = "GetGamePoints";
            pac.Parameters = "{\"GameCodeInfo\":[\"C6B17C21-3751-4736-92DD-982CFCF96E1C\",\"4A287D31-3407-44E2-AED6-7E4EEE31B64C\",\"A9797B1B-439A-45C2-AB3E-57CC311D964B\",\"B821990C-2A1F-426D-85C3-390B0B16AF00\",\"8C0F981D-859F-4BAF-B9B6-947DC6D72AD7\"],\"UserId\":\"gotesta\",\"ExecUser\":\"SystemAdmin\",\"ExecIP\":\"192.168.1.1\"}";
            pac.API_CName = "用戶批量獲取遊戲端點數(額度)API";
            pac.ReturnCode = "200";
            pac.ReturnData = "{\"Code\":\"200\",\"ErrMsg\":\"\",\"RetObj\":[{\"GameGUID\":\"C6B17C21-3751-4736-92DD-982CFCF96E1C\",\"Point\":0.00,\"GetTime\":\"2015-10-01 01:37:35\",\"Success\":true},{\"GameGUID\":\"A9797B1B-439A-45C2-AB3E-57CC311D964B\",\"Point\":0.00,\"GetTime\":\"2015-10-01 01:37:34\",\"Success\":true},{\"GameGUID\":\"4A287D31-3407-44E2-AED6-7E4EEE31B64C\",\"Point\":0.00,\"GetTime\":\"2015-10-01 01:37:35\",\"Success\":true},{\"GameGUID\":\"B821990C-2A1F-426D-85C3-390B0B16AF00\",\"Point\":0.00,\"GetTime\":\"2015-10-01 01:37:35\",\"Success\":true},{\"GameGUID\":\"8C0F981D-859F-4BAF-B9B6-947DC6D72AD7\",\"Point\":1381.19,\"GetTime\":\"2015-10-01 01:37:35\",\"Success\":true}]}";
            pac.Description = "正常";
            pac.ExecuteUser = "******";

            // Act
            object result = pac.Creat();

            // Assert
            Assert.AreEqual(result, "0");
        }
 public ActionResult ProxyAPICall_Add(ProxyAPICallModels pac)
 {
     object result = pac.Creat();
     return View();
 }
 /// <summary>
 /// MongoDB測試-ProxyAPICall
 /// </summary>
 /// <returns></returns>
 public ActionResult ProxyAPICall_Add()
 {
     ProxyAPICallModels model = new ProxyAPICallModels();
     return View(model);
 }
        /// <summary>
        /// ProxyAPI呼叫記錄 - 取得全部
        /// </summary>
        /// <returns>"0":成功, 其它:失敗</returns>
        public static object GetAll(out List<ProxyAPICallModels> pacs)
        {            
            pacs = new List<ProxyAPICallModels>();
            object result = "0";
            try
            {
                //MongoDB.Driver 2.0.1
                IMongoCollection<BsonDocument> collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                List<BsonDocument> docs = new List<BsonDocument>();
                Task.Run(async () =>
                {
                    var tmp = await collection.Find(new BsonDocument()).ToListAsync();
                    docs = tmp.ToList();
                }).GetAwaiter().GetResult();

                List<ProxyAPICallModels> models = new List<ProxyAPICallModels>();
                docs.ForEach(doc =>
                {
                    ProxyAPICallModels model = new ProxyAPICallModels(doc);
                    models.Add(model);
                }
                );
                pacs = models;

                //MongoDB.Driver 1.10
                //MongoCollection<BsonDocument> collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                //var docs = collection.FindAll();

                //List<ProxyAPICallModels> models = new List<ProxyAPICallModels>();
                //foreach (var doc in docs)
                //{
                //    ProxyAPICallModels model = new ProxyAPICallModels(doc);
                //    models.Add(model);
                //}
                //pacs = models;
            }
            catch (Exception ex)
            {
                result = ex.ToString();
            }

            return result;
        }
        /// <summary>
        /// ProxyAPI呼叫記錄 - 依條件取得
        /// </summary>
        /// <returns>"0":成功, 其它:失敗</returns>
        public static object GetList(string API_Name, string ReturnCode, string UserId, out List<ProxyAPICallModels> pacs)
        {
            pacs = new List<ProxyAPICallModels>();
            object result = "0";
            try
            {
                //MongoDB.Driver 2.0.1
                var builder = Builders<BsonDocument>.Filter;
                var filter = builder.Ne("_id", ""); //預設ID不為空 => 全列

                if (!string.IsNullOrEmpty(API_Name))
                    filter = filter & builder.Regex("API_Name", ".*" + API_Name + ".*"); //字串部分比對
                if (!string.IsNullOrEmpty(ReturnCode))
                    filter = filter & builder.Eq("ReturnCode", ReturnCode);
                if (!string.IsNullOrEmpty(UserId))
                    filter = filter & builder.Regex("Parameters.UserId", "/" + UserId + "/"); //字串部分比對

                var collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                List<BsonDocument> docs = new List<BsonDocument>();
                Task.Run(async () =>
                {
                    var tmp = await collection.Find(filter).ToListAsync();
                    docs = tmp.ToList();
                }).GetAwaiter().GetResult();

                List<ProxyAPICallModels> models = new List<ProxyAPICallModels>();
                docs.ForEach(doc =>
                {
                    ProxyAPICallModels model = new ProxyAPICallModels(doc);
                    models.Add(model);
                }
                );
                pacs = models;

                //MongoDB.Driver 1.10
                //var query = Query.NE("_id", ""); //預設ID不為空 => 全列

                //if (!string.IsNullOrEmpty(API_Name))
                //    query = Query.And(query, Query.Matches("API_Name", API_Name)); //字串部分比對
                //if (!string.IsNullOrEmpty(ReturnCode))
                //    query = Query.And(query, Query.EQ("ReturnCode", ReturnCode));
                //if (!string.IsNullOrEmpty(UserId))
                //    query = Query.And(query, Query.Matches("Parameters.UserId", UserId)); //字串部分比對
                //if (!string.IsNullOrEmpty(StartTime) && !string.IsNullOrEmpty(EndTime))
                //{
                //    query = Query.And(query, Query.GTE("CTime", DateTime.Parse(StartTime).ToLocalTime()));
                //    query = Query.And(query, Query.LTE("CTime", DateTime.Parse(EndTime).ToLocalTime()));
                //}

                //MongoCollection<BsonDocument> collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                //var docs = collection.Find(query);

                //List<ProxyAPICallModels> models = new List<ProxyAPICallModels>();
                //foreach (var doc in docs)
                //{
                //    ProxyAPICallModels model = new ProxyAPICallModels(doc);
                //    models.Add(model);
                //}
                //pacs = models;
            }
            catch (Exception ex)
            {
                result = ex.ToString();
            }

            return result;
        }
        /// <summary>
        /// ProxyAPI呼叫記錄 - 取得一筆
        /// </summary>
        /// <returns>"0":成功, 其它:失敗</returns>
        public object GetOne(string ID)
        {
            object result = "0";
            try
            {
                //MongoDB.Driver 2.0.1
                var filter = Builders<BsonDocument>.Filter.Eq("_id", ObjectId.Parse(ID));
                ProxyAPICallModels pac = new ProxyAPICallModels();

                IMongoCollection<BsonDocument> collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                Task.Run(async () =>
                {
                    var doc = await collection.Find(filter).FirstAsync();
                    this.ID = doc.GetValue("_id", string.Empty).ToString().Replace("ObjectId(", "").Replace(")", "");
                    this.API_Name = doc.GetValue("API_Name", string.Empty).ToString();
                    this.Parameters = doc.GetValue("Parameters", string.Empty).ToString();
                    this.API_CName = doc.GetValue("API_CName", string.Empty).ToString();
                    this.ReturnCode = doc.GetValue("ReturnCode", string.Empty).ToString();
                    this.ReturnData = doc.GetValue("ReturnData", string.Empty).ToString();
                    this.Description = doc.GetValue("Description", string.Empty).ToString();
                    this.ExecuteUser = doc.GetValue("ExecuteUser", string.Empty).ToString();
                    DateTime tmp;
                    DateTime.TryParse(doc.GetValue("CTime", DateTime.UtcNow).ToString(), out tmp);
                    this.CTime = tmp.ToLocalTime();
                }).GetAwaiter().GetResult();

                //MongoDB.Driver 1.10
                //MongoCollection<BsonDocument> collection = MongoDBCollections.GetCollection_ProxyAPICall(); //取得Log資料庫ProxyAPICall資料表
                //var query = Query.EQ("_id", ObjectId.Parse(ID));
                //var doc = collection.FindOne(query);

                //this.ID = doc.GetValue("_id", string.Empty).ToString().Replace("ObjectId(", "").Replace(")", "");
                //this.API_Name = doc.GetValue("API_Name", string.Empty).ToString();
                //this.Parameters = doc.GetValue("Parameters", string.Empty).ToString();
                //this.API_CName = doc.GetValue("API_CName", string.Empty).ToString();
                //this.ReturnCode = doc.GetValue("ReturnCode", string.Empty).ToString();
                //this.ReturnData = doc.GetValue("ReturnData", string.Empty).ToString();
                //this.Description = doc.GetValue("Description", string.Empty).ToString();
                //this.ExecuteUser = doc.GetValue("ExecuteUser", string.Empty).ToString();
                //DateTime tmp;
                //DateTime.TryParse(doc.GetValue("CTime", DateTime.UtcNow).ToString(), out tmp);
                //this.CTime = tmp.ToLocalTime();
            }
            catch (Exception ex)
            {
                result = ex.ToString();
            }
            return result;
        }