예제 #1
0
 public string add(dataViewModel reg)
 {
     reg.createDate = DateTime.Now;
     reg.KEY        = createKey(reg.Name, reg.vpnID, reg.vpnPW, reg.vpnMac);
     reg.Name       = string.IsNullOrEmpty(reg.Name) ? " " : reg.Name;
     reg.vpnID      = string.IsNullOrEmpty(reg.vpnID) ? " " : reg.vpnID;
     vpnEntrys.Add(reg.KEY, reg);
     mBll.Create(reg);
     return(reg.KEY);
 }
        public ActionResult Update(FormCollection f)
        {//{ autoid: id, name: name, vpnid: vpnid, vpnpw: vpnpw, mac: mac, ip: ip, EncryptionType: EncryptionType }
            dataViewModel reg = new dataViewModel();

            if (f.AllKeys.Contains("name") && !string.IsNullOrEmpty(f["name"]))
            {
                reg.Name = f["name"].ToString();
            }
            if (f.AllKeys.Contains("vpnid") && !string.IsNullOrEmpty(f["vpnid"]))
            {
                reg.vpnID = f["vpnid"].ToString();
            }
            if (f.AllKeys.Contains("vpnpwd") && !string.IsNullOrEmpty(f["vpnpwd"]))
            {
                reg.vpnPW = f["vpnpwd"].ToString();
            }
            if (f.AllKeys.Contains("mac") && !string.IsNullOrEmpty(f["mac"]))
            {
                reg.vpnMac = f["mac"].ToString();
            }
            if (f.AllKeys.Contains("ip") && !string.IsNullOrEmpty(f["ip"]))
            {
                reg.vpnIP = f["ip"].ToString();
            }
            if (f.AllKeys.Contains("vpnEncryptionType") && !string.IsNullOrEmpty(f["vpnEncryptionType"]))
            {
                reg.vpnEncryptionType = f["vpnEncryptionType"].ToString();
            }
            if (f.AllKeys.Contains("KEY") && !string.IsNullOrEmpty(f["KEY"]))
            {
                reg.KEY = f["KEY"].ToString();
            }
            //if (f.AllKeys.Contains("autoid") && !string.IsNullOrEmpty(f["autoid"]))
            //    reg.autoid = int.Parse(f["autoid"].ToString());

            string savestate = string.Empty;

            if (string.IsNullOrEmpty(reg.KEY))
            {
                savestate = Bll.add(reg);
            }
            else
            {
                savestate = Bll.update(reg);
            }

            JsonResult rJson = new JsonResult();

            rJson.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            rJson.MaxJsonLength       = 64;
            rJson.Data = savestate;
            return(rJson);
        }
        public JsonResult getUpdatedRow(string id)  //prev Param:int id
        {
            JsonResult r = new JsonResult();

            r.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            r.MaxJsonLength       = int.MaxValue;

            dataViewModel vpn = Bll.signal(id);

            r.Data = vpn;
            return(r);
        }
        public ActionResult Import(string id, string DIPModelsString)
        {
            JsonResult rJson = new JsonResult();

            rJson.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            rJson.MaxJsonLength       = 64;

            /* Bug : DIPModels做为参数,传入后List.Count是对的,但其中元素为空
             * List<dataViewModel> DIPModels = new List<dataViewModel>(); ;
             * if (DIPModels != null && DIPModels.Count > 0)
             * {
             *  foreach (dataViewModel dm in DIPModels)
             *  {
             *      if (Bll.Exist(dm.Name, dm.KEY))
             *          Bll.update(dm);
             *      else
             *          Bll.add(dm);
             *  }
             *  rJson.Data = "已导入数据,请核对!";
             *  return rJson;
             * }
             * else
             * {
             *  rJson.Data = "无导入数据!";
             *
             * }
             */
            //分析传入的DIPModelsString
            var           strList = DIPModelsString.Split('\n');
            dataViewModel dip     = new dataViewModel();

            if (string.IsNullOrEmpty(DIPModelsString))
            {
                rJson.Data = "无导入数据!";
                return(rJson);
            }
            foreach (string strItem in strList)
            {
                dip = new dataViewModel();
                var elems = strItem.Split(',');
                if (elems.Length < 3)
                {
                    continue;
                }
                dip.Name  = elems[0];
                dip.vpnID = elems[1];
                dip.vpnPW = elems[2];
                dip.KEY   = Bll.createKey(dip);

                if (Bll.Exist(dip.Name, dip.KEY))
                {
                    Bll.update(dip);
                }
                else
                {
                    Bll.add(dip);
                }
            }
            rJson.Data = "已导入数据,请核对!";
            return(rJson);
        }
예제 #5
0
 public string update(dataViewModel reg)
 {
     vpnEntrys[reg.KEY] = reg;
     mBll.Update(reg);
     return(reg.KEY);
 }
예제 #6
0
 public string createKey(dataViewModel dvModel)
 {
     return(createKey(dvModel.Name, dvModel.vpnID, dvModel.vpnPW, dvModel.vpnMac));
 }