public JsonResult DictCacheSave()
        {
            NcDictcache model = new NcDictcache();

            action = Request.Form["act"];
            if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower())//修改
            {
                long id = Utils.StrToInt(Request.Form["id"]);
                model             = dblEf.Find <NcDictcache>(id);
                model             = DictCacheSetModel(model);
                model.UpdatedTime = DateTime.Now;

                if (DictCacheUpdate(model))
                {
                    strStatus = "1";
                    strMsg    = "保存成功";
                }
            }
            else//新增
            {
                model             = DictCacheSetModel(model);
                model.CreatedTime = DateTime.Now;
                if (DictCacheAdd(model))
                {
                    strStatus = "1";
                    strMsg    = "保存成功";
                }
            }
            return(Json(new { status = strStatus, msg = strMsg }));
        }
        public JsonResult UpdateSort_DictCache(string ids, string sorts)
        {
            bool res = true;

            if (string.IsNullOrEmpty(ids) || string.IsNullOrEmpty(sorts))
            {
                res = false;
            }
            else
            {
                string[] arrId   = ids.Split(',');
                string[] arrSort = sorts.Split(',');
                for (int i = 0; i < arrId.Length; i++)
                {
                    long        id    = Utils.StrToInt(arrId[i]);
                    NcDictcache model = dblEf.Find <NcDictcache>(id);
                    if (model != null && Utils.StrToInt(arrSort[i]) != model.SortId)//减少数据库访问次数
                    {
                        model.SortId = Utils.StrToInt(arrSort[i]);
                        ////var res = dblEf.NcDictcache.Update(model);
                        //res = dblEf.SaveChanges() > 0;
                        //dblEf.NcDictcache.Attach(model);
                        //var ress = (dblEf.Entry<NcDictcache>(model).Property<int?>(v => v.SortId).IsModified = true);

                        res = dblEf.SaveChanges() > 0;
                    }
                }
            }
            return(Json(new { status = (res ? 1 : 0), message = "保存成功!" }));
        }
 /// <summary>
 /// 角色获取赋值
 /// </summary>
 private NcDictcache DictCacheSetModel(NcDictcache model)
 {
     model.Title       = Request.Form["txtTitle"];
     model.Depend      = Request.Form["txtDepend"];
     model.CacheKey    = Request.Form["txtCache_Key"];
     model.CacheExp    = Request.Form["txtCache_Exp"];
     model.CacheDesc   = Request.Form["txtCache_Desc"];
     model.SortId      = Utils.StrToInt(Request.Form["txtSortId"]);
     model.CreatedName = Request.Form["txtCreated_Name"];
     model.UpdatedName = Request.Form["txtUpdated_Name"];
     model.Ostatus     = !string.IsNullOrEmpty(Request.Form["OStatus"]) ? 1 : 0;
     return(model);
 }
        public ActionResult DictCache_Edit()
        {
            action = Request.Query["act"];
            long        id    = Utils.StrToInt(Request.Query["id"]);
            NcDictcache model = new NcDictcache();

            if (action.ToLower() == JHEnums.ActionEnum.Edit.ToString().ToLower() && id != 0) //修改
            {
                model = dblEf.Find <NcDictcache>(id);
            }
            else
            {
                model.SortId = 99;
            }
            ViewBag.action = action;
            ViewBag.id     = id;
            return(View(model));
        }
        public JsonResult DictCache_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++)
                    {
                        long id = Utils.StrToInt(arrId[i]);
                        //dblEf.Delete<NcDictcache>(m => m.Cache_ID == id);//删除,linq to entities不识别xx[index]这种格式,需要先赋值临时变量
                        NcDictcache model = dblEf.Find <NcDictcache>(id);
                        if (model != null)
                        {
                            dblEf.Remove <NcDictcache>(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 DictCacheUpdate(NcDictcache model)
 {
     dblEf.Update <NcDictcache>(model);
     return(dblEf.SaveChanges() > 0);
     //return dblEf.Update<NcDictcache>(model);
 }
 public bool DictCacheAdd(NcDictcache model)
 {
     dblEf.Add <NcDictcache>(model);
     return(dblEf.SaveChanges() > 0);
     //return dblEf.Insert<NcDictcache>(model) != null;
 }