public JsonResult DictBaseSave()
        {
            NcDictbase model = new NcDictbase();

            action = Request.Form["act"];
            if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower())//修改
            {
                int id = Utils.StrToInt(Request.Form["id"]);
                model = dblEf.Find <NcDictbase>(id);
                model = DictBaseSetModel(model);

                if (DictBaseUpdate(model))
                {
                    strStatus = "1";
                    strMsg    = "保存成功";
                }
            }
            else//新增
            {
                model = DictBaseSetModel(model);

                if (DictBaseAdd(model))
                {
                    strStatus = "1";
                    strMsg    = "保存成功";
                }
            }
            return(Json(new { status = strStatus, msg = strMsg }));
        }
 /// <summary>
 /// 字典获取赋值
 /// </summary>
 private NcDictbase DictBaseSetModel(NcDictbase model)
 {
     model.KeyType  = Request.Form["txtKey_Type"];
     model.KeyCode  = Request.Form["txtKey_Code"];
     model.KeyValue = Request.Form["txtKey_Value"];
     model.SortId   = Utils.StrToInt(Request.Form["txtSortId"]);
     return(model);
 }
        public ActionResult DictBase_Edit()
        {
            action = Request.Query["act"];
            int        id    = Utils.StrToInt(Request.Query["id"]);
            NcDictbase model = new NcDictbase();

            if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower() && id != 0) //修改
            {
                model = dblEf.Find <NcDictbase>(id);
            }
            else
            {
                model.SortId = 1;
            }
            ViewBag.action = action;
            ViewBag.id     = id;
            return(View(model));
        }
        public JsonResult DictBase_Del(string ids)
        {
            bool res = true;

            if (string.IsNullOrEmpty(ids))
            {
                res    = false;
                strMsg = "删除参数异常!";//
            }
            else
            {
                string[] arrId  = ids.Split(',');
                string   result = string.Empty;
                try
                {
                    for (int i = 0; i < arrId.Length; i++)
                    {
                        int        id    = Utils.StrToInt(arrId[i]);
                        NcDictbase model = dblEf.Find <NcDictbase>(id);
                        if (model != null)
                        {
                            //dblEf.NcDictbase.Remove(m => m.id);//.Delete<NcDictbase>(m => m.id == id);//删除,linq to entities不识别xx[index]这种格式,需要先赋值临时变量
                            dblEf.Remove <NcDictbase>(model);
                            dblEf.SaveChanges();
                            res    = true;
                            strMsg = "删除成功!";
                        }
                    }
                }
                catch (Exception ex)//循环删除,异常才报删除错误
                {
                    res    = false;
                    strMsg = "删除过程中出现异常!";//调试过程中+ex.ToString();
                }
            }
            return(Json(new { status = (res ? 1 : 0), message = strMsg }));
        }
 public bool DictBaseUpdate(NcDictbase model)
 {
     //return dblEf.Update<dictbase>(model);
     dblEf.Update <NcDictbase>(model);
     return(dblEf.SaveChanges() > 0);
 }
 public bool DictBaseAdd(NcDictbase model)
 {
     //return false;
     dblEf.NcDictbase.Add(model);
     return(dblEf.SaveChanges() > 0);
 }