public ActionResult AuditOneMessage(string id)
        {
            MongoCollection <ModUApiPowerAplictionFind> modUApiPowerAplictionFind = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind modUApiPowerAplictionFindList = modUApiPowerAplictionFind.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            ViewBag.uapi_interface_list = mongoh.GetCollection <ModUApiInterfaceList>().FindAll().OrderBy(m => m.index).ToList();
            ViewBag.uapi_field_list     = mongoh.GetCollection <ModUApiFieldList>().FindAll().OrderBy(m => m.index).ToList();
            return(View(modUApiPowerAplictionFindList));
        }
        public ActionResult Delete(string id = "")
        {
            MongoCollection <ModUApiPowerAplictionFind> modUApiPowerAplictionFind = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind Model = modUApiPowerAplictionFind.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            if (Model == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "数据不存在")));
            }
            modUApiPowerAplictionFind.Remove(Query.EQ("_id", new ObjectId(id)));
            return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "删除成功")));
        }
        public ActionResult UpdateInfoSave(ModUApiPowerAplictionFind mod, FormCollection form)
        {
            string id = CUtil.CStr(form["id"]);
            MongoCollection <ModUApiPowerAplictionFind> modUApiPowerAplictionFind = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind Model = modUApiPowerAplictionFind.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            if (Model == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "数据读取异常")));
            }
            var strLocation = Query.EQ("_id", new ObjectId(id));

            modUApiPowerAplictionFind.Update((strLocation), Update.Set("serviceno_uid", mod.serviceno_uid == null ? "" : mod.serviceno_uid).Set("civetno", mod.civetno == null ? "" : mod.civetno).Set("user_name", mod.user_name == null ? "" : mod.user_name).Set("mobile", mod.mobile == null ? "" : mod.mobile).Set("ext_phone", mod.ext_phone == null ? "" : mod.ext_phone).Set("bg_name", mod.bg_name == null ? "" : mod.bg_name).Set("bu_name", mod.bu_name == null ? "" : mod.bu_name).Set("dept_name", mod.dept_name == null ? "" : mod.dept_name).Set("cost_code", mod.cost_code == null ? "" : mod.cost_code).Set("apply_reason", mod.apply_reason == null ? "" : mod.apply_reason));
            return(Content(Util.JsCustom("alert('修改成功');window.parent._close_dialog(); window.parent.refresh();")));
        }
        public ActionResult UpdateInfo(string id = "")
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "参数错误")));
            }
            MongoCollection <ModUApiPowerAplictionFind> modUApiPowerAplictionFind = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind mod = modUApiPowerAplictionFind.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            if (mod == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "数据读取异常")));
            }
            return(View(mod));
        }
        public ActionResult AuditOneMessage_Already(string id = "")
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "参数错误")));
            }
            MongoCollection <ModUApiPowerAplictionFind> modUApiPowerAplictionFind = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind mod = modUApiPowerAplictionFind.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            if (mod == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index_Already"), "数据读取异常")));
            }
            ViewBag.uapi_interface_list = mongoh.GetCollection <ModUApiInterfaceList>().FindAll().MOrderBy(m => m.index).ToList();
            ViewBag.uapi_field_list     = mongoh.GetCollection <ModUApiFieldList>().FindAll().MOrderBy(m => m.index).ToList();
            return(View(mod));
        }
        public ActionResult AuditOneMessageSave(FormCollection form)
        {
            string id     = form["_id"] ?? "";
            string Audit  = form["Audit"] ?? "";
            string remark = form["remark"] ?? "";

            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(Audit))
            {
                return(Content(Util.JsUrlTo(Url.Action("Index"), "数据错误")));
            }
            MongoCollection <ModUApiPowerAplictionFind> uapiaplict = mongoh.GetCollection <ModUApiPowerAplictionFind>();
            ModUApiPowerAplictionFind resultaplict = uapiaplict.Find(Query.EQ("_id", new ObjectId(id))).FirstOrDefault();

            if (resultaplict == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index"), "数据已删除或不存在")));
            }
            if (!resultaplict.status.Contains("待审核"))
            {
                return(Content(Util.JsUrlTo(Url.Action("Index"), "申请信息已审核,请勿再次提交")));
            }
            #region 查找出需要的接口
            string needinter = "";
            //首先查询这条记录是不是第一次申请,如果没有原有接口,那么就直接新增接口,如果有原有接口,那么就要在原有接口上移除需要的接口再加入新增的接口
            if (resultaplict.interfaces != null && resultaplict.interfaces.Length > 0 && !string.IsNullOrEmpty(resultaplict.interfaces[0]))
            {
                #region 先得出所有需要移除的接口
                string removie = "";
                if (resultaplict.remove_interfaces != null && resultaplict.remove_interfaces.Length > 0 && !string.IsNullOrEmpty(resultaplict.remove_interfaces[0]))
                {
                    foreach (var item1 in resultaplict.remove_interfaces)
                    {
                        removie += item1 + ",";
                    }
                    removie = removie.TrimEnd(',');
                }
                List <string> str  = resultaplict.interfaces.ToList();
                List <string> str_ = resultaplict.interfaces.ToList();
                foreach (var item in str)
                {
                    if (removie.Contains(item))
                    {
                        str_.Remove(item);
                    }
                }
                foreach (var item in str_)
                {
                    needinter += item + ",";
                }
                #endregion
                if (resultaplict.add_interfaces != null && resultaplict.add_interfaces.Length > 0 && !string.IsNullOrEmpty(resultaplict.add_interfaces[0]))
                {
                    foreach (var item1 in resultaplict.add_interfaces)
                    {
                        needinter += item1 + ",";
                    }
                }
            }
            else
            {
                if (resultaplict.add_interfaces != null && resultaplict.add_interfaces.Length > 0 && !string.IsNullOrEmpty(resultaplict.add_interfaces[0]))
                {
                    foreach (var item1 in resultaplict.add_interfaces)
                    {
                        needinter += item1 + ",";
                    }
                }
            }
            needinter = needinter.TrimEnd(',');
            string[] Arrayneedinter = needinter.Split(',');
            #endregion
            #region  查找出需要的栏位
            string needfields = "";
            //首先查询这条记录是不是第一次申请,如何没有原有接口,那么就直接新增接口,如果有原有接口,那么就要在原有接口上移除需要的接口再加入新增的接口
            if (resultaplict.fields != null && resultaplict.fields.Length > 0 && !string.IsNullOrEmpty(resultaplict.fields[0]))
            {
                #region 先得出所有需要移除的栏位
                string removie = "";
                if (resultaplict.remove_fields != null && resultaplict.remove_fields.Length > 0 && !string.IsNullOrEmpty(resultaplict.remove_fields[0]))
                {
                    foreach (var item1 in resultaplict.remove_fields)
                    {
                        removie += item1 + ",";
                    }
                }
                List <string> str  = resultaplict.fields.ToList();
                List <string> str_ = resultaplict.fields.ToList();
                foreach (var item in str)
                {
                    if (removie.Contains(item))
                    {
                        str_.Remove(item);
                    }
                }
                foreach (var item in str_)
                {
                    needfields += item + ",";
                }
                #endregion
                if (resultaplict.add_fields != null && resultaplict.add_fields.Length > 0 && !string.IsNullOrEmpty(resultaplict.add_fields[0]))
                {
                    foreach (var item1 in resultaplict.add_fields)
                    {
                        needfields += item1 + ",";
                    }
                }
            }
            else
            {
                if (resultaplict.add_fields != null && resultaplict.add_fields.Length > 0 && !string.IsNullOrEmpty(resultaplict.add_fields[0]))
                {
                    foreach (var item1 in resultaplict.add_fields)
                    {
                        needfields += item1 + ",";
                    }
                }
            }
            needfields = needfields.TrimEnd(',');
            string[] Arrayneedfields = needfields.Split(',');
            #endregion
            //通过
            if (Audit.Contains("1"))
            {
                //添加用户权限数据
                var collection = mongoh.GetCollection <ModUApiPowerList>();
                if (collection.Count(Query.EQ("_id", new BsonString(resultaplict.serviceno_uid))) == 0)
                {
                    ModUApiPowerList power = new ModUApiPowerList
                    {
                        _id                 = resultaplict.serviceno_uid.ToUpper(),
                        bg_name             = resultaplict.bg_name,
                        bu_name             = resultaplict.bu_name,
                        dept_name           = resultaplict.dept_name,
                        civetno             = resultaplict.civetno,
                        user_name           = resultaplict.user_name,
                        cost_code           = resultaplict.cost_code,
                        start_date          = DateTime.Today,
                        end_date            = new DateTime(2020, 12, 31),
                        fields              = Arrayneedfields,
                        interfaces          = Arrayneedinter,
                        ext_phone           = resultaplict.ext_phone,
                        mobile              = resultaplict.mobile,
                        limit_monthly_count = resultaplict.add_day,
                        open_power          = true,
                        private_key_des     = ""
                    };
                    collection.Insert(power);
                }
                else
                {
                    MongoCollection <ModUApiPowerList> uapipower = mongoh.GetCollection <ModUApiPowerList>();
                    ModUApiPowerList modpower = uapipower.Find(Query.EQ("_id", new BsonString(resultaplict.serviceno_uid))).FirstOrDefault();
                    if (modpower == null)
                    {
                        return(Content(Util.JsUrlTo(Url.Action("Index"), "数据不存在")));
                    }
                    modpower.fields              = Arrayneedfields;
                    modpower.interfaces          = Arrayneedinter;
                    modpower.bg_name             = resultaplict.bg_name;
                    modpower.bu_name             = resultaplict.bu_name;
                    modpower.dept_name           = resultaplict.dept_name;
                    modpower.civetno             = resultaplict.civetno;
                    modpower.user_name           = resultaplict.user_name;
                    modpower.cost_code           = resultaplict.cost_code;
                    modpower.ext_phone           = resultaplict.ext_phone;
                    modpower.mobile              = resultaplict.mobile;
                    modpower.limit_monthly_count = resultaplict.add_day;
                    BsonDocument bd = BsonExtensionMethods.ToBsonDocument(modpower);
                    //修改将需要的接口和栏位保存到权限表中去
                    uapipower.Update(Query.EQ("_id", new BsonString(resultaplict.serviceno_uid)), new UpdateDocument(bd));
                }
                uapiaplict.Update(Query.EQ("_id", new ObjectId(id)), Update.Set("status", "审核通过").Set("audit_time", DateTime.Now).Set("audit_civet_no", UserInfo.BaseInfo.civetno).Set("apply_reason", remark));
            }
            else
            {
                if (Audit.Contains("2"))
                {
                    uapiaplict.Update(Query.EQ("_id", new ObjectId(id)), Update.Set("status", "审核驳回").Set("audit_time", DateTime.Now).Set("audit_civet_no", UserInfo.BaseInfo.civetno).Set("apply_reason", remark));
                }
            }
            return(Content(Util.JsUrlTo(Url.Action("Index"))));
        }