public ActionResult AddUpdateSave(ModUApiManager mod, FormCollection form)
        {
            ModUApiManager model                = new ModUApiManager();
            string         status_name          = CUtil.CStr(form["status_name"]);
            MongoCollection <ModUApiManager> mg = mongoh.GetCollection <ModUApiManager>();
            var eq = Query.EQ("_id", new BsonString(mod._id));

            if (status_name == "1")
            {
                model = mg.Find(eq).FirstOrDefault();
                if (model != null)
                {
                    return(Content(Util.JsUrlTo(Url.Action("Index"), "新增失败,香信号已存在")));
                }
                model                 = new ModUApiManager();
                model._id             = mod._id.ToUpper();
                model.is_disabled     = mod.is_disabled;
                model.user_name       = mod.user_name;
                model.last_login_time = DateTime.Now;
                mg.Insert(model);
                return(Content(Util.JsUrlTo(Url.Action("Index"), "新增成功")));
            }
            model = mg.Find(eq).FirstOrDefault();
            if (model == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index"), "修改失败,数据不存在")));
            }
            model.is_disabled = mod.is_disabled;
            model.user_name   = mod.user_name;
            BsonDocument bd = BsonExtensionMethods.ToBsonDocument(model);

            mg.Update(Query.EQ("_id", new BsonString(mod._id)), new UpdateDocument(bd));
            return(Content(Util.JsUrlTo(Url.Action("Index"), "修改成功")));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Logins the specified signature.
 /// </summary>
 /// <param name="Signature">The signature.</param>
 /// <param name="ToController">To controller.</param>
 /// <param name="ToAction">To action.</param>
 /// <param name="id">The identifier.</param>
 /// <returns>ActionResult.</returns>
 public ActionResult Login(string Signature, string ToController, string ToAction, string id)
 {
     try
     {
         OAuth          oauth = new OAuth(CivetHelper.AppID);
         OAuth.UserInfo uInfo = oauth.FastGetUserInfo(Request);
         //判斷用戶權限並給UserInfo賦值(存入Session)
         if (uInfo == null)
         {
             return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无账号信息") })));
         }
         #region  添加管理员信息
         if (uInfo != null)
         {
             if (!string.IsNullOrEmpty(uInfo.civetno))
             {
                 MongoCollection <ModUApiManager> uapimanager = mongoh.GetDb().GetCollection <ModUApiManager>("uapi_managers");
                 ModUApiManager modeuap = uapimanager.Find(Query.And(
                                                               Query.EQ("_id", new BsonString(uInfo.civetno.ToUpper())),
                                                               Query.EQ("is_disabled", new BsonBoolean(false))
                                                               )).FirstOrDefault();
                 if (modeuap != null)
                 {
                     if (modeuap.last_login_time < DateTime.Now.AddMinutes(-2))
                     {
                         uapimanager.Update((Query.EQ("_id", new BsonString(uInfo.civetno.ToUpper()))), Update.Set("last_login_time", DateTime.Now));
                     }
                     UtilComm.UApi_Manager = modeuap;
                     //if (!modeuap.is_disabled)
                     //{
                     //    return Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无权限") }));
                     //}
                 }
                 else
                 {
                     return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无账号信息") })));
                 }
                 Managelog(uInfo.civetno.ToUpper());
             }
         }
         #endregion
         base.UserInfo = new ModUserInfo {
             BaseInfo = uInfo
         };
         string url         = string.IsNullOrEmpty(id) ? Url.Action(ToAction, ToController) : Url.Action(ToAction, ToController, new { id = id });
         string QueryString = HtmlUtil.DealQuery(Request.QueryString.ToString(), "code", "id");
         if (QueryString != "")
         {
             url += "?" + QueryString;
         }
         //完善登錄操作
         return(Redirect(url));
     }
     catch (Exception)
     {
         return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "数据读取异常") })));
     }
 }
        public ActionResult Delete(string id = "")
        {
            MongoCollection <ModUApiManager> mg = mongoh.GetCollection <ModUApiManager>();
            ModUApiManager Model = mg.Find(Query.EQ("_id", new BsonString(id))).FirstOrDefault();

            if (Model == null)
            {
                return(Content(Util.JsUrlTo(Url.Action("Index", "AccountManage"), "数据不存在")));
            }
            mg.Remove(Query.EQ("_id", new BsonString(id)));
            return(Redirect(Url.Action("Index", "AccountManage", "删除成功")));
        }
        public ActionResult AddUpdate(string id = "")
        {
            ModUApiManager Model = new ModUApiManager();

            if (string.IsNullOrEmpty(id))
            {
                TempData["Mgs"] = "1";
                return(View(Model));
            }
            TempData["Mgs"] = "2";
            MongoCollection <ModUApiManager> mg = mongoh.GetCollection <ModUApiManager>();

            Model = mg.Find(Query.EQ("_id", new BsonString(id))).FirstOrDefault();
            return(View(Model));
        }