예제 #1
0
        public IActionResult PolicyInfoSave(PolicyInfoModel model, string policy_id)
        {
            if (string.IsNullOrWhiteSpace(model.app_id))
            {
                return(Content("app_id Empty"));
            }
            if (string.IsNullOrWhiteSpace(model.event_code))
            {
                return(Content("event_code Empty"));
            }
            if (string.IsNullOrWhiteSpace(model.policy_code))
            {
                return(Content("policy_code Empty"));
            }
            var list = MongoDbHelper.SearchPolicyInfoList(model.app_id, model.event_code, model.policy_code);

            if (list.Any())
            {
                MongoDbHelper.DeletePolicyInfo(model);
            }
            if (model.field.Count > 0)
            {
                model.field = model.field[0].Split(',').ToList();
            }
            var res = MongoDbHelper.InsertPolicyInfo(model);


            return(Content(res ? "OK" : "ERROR"));
        }
예제 #2
0
        public static bool DeletePolicyInfo(PolicyInfoModel model)
        {
            try
            {
                var coll = MongodbWrite.GetCollection <PolicyInfoModel>("PolicyInfo");

                Dictionary <string, object> dict = new Dictionary <string, object>();
                if (!string.IsNullOrWhiteSpace(model.app_id))
                {
                    dict.Add("app_id", model.app_id);
                }
                if (!string.IsNullOrWhiteSpace(model.event_code))
                {
                    dict.Add("event_code", model.event_code);
                }
                if (!string.IsNullOrWhiteSpace(model.policy_code))
                {
                    dict.Add("policy_code", model.policy_code);
                }
                var query = new BsonDocument(dict);
                coll.DeleteManyAsync(query);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }

            return(true);
        }
예제 #3
0
        public IActionResult PolicyInfoEdit(string appid = "", string eventcode = "", string policycode = "")
        {
            if (string.IsNullOrWhiteSpace(appid))
            {
                return(Content("app_id Empty"));
            }
            if (string.IsNullOrWhiteSpace(eventcode))
            {
                return(Content("eventcode Empty"));
            }
            PolicyInfoModel model = new PolicyInfoModel();

            if (!string.IsNullOrWhiteSpace(appid) && !string.IsNullOrWhiteSpace(eventcode) && !string.IsNullOrWhiteSpace(policycode))
            {
                var list = MongoDbHelper.SearchPolicyInfoList(appid, eventcode, policycode);
                if (list.Count > 0)
                {
                    model = list.First();
                }
            }
            model.app_id     = appid;
            model.event_code = eventcode;

            return(View(model));
        }
예제 #4
0
        public static bool InsertPolicyInfo(PolicyInfoModel model)
        {
            try
            {
                var coll = MongodbWrite.GetCollection <PolicyInfoModel>("PolicyInfo");
                coll.InsertOneAsync(model);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }

            return(true);
        }