public ActionResult Create(DictionaryDetails model)
 {
     //
     if (ModelState.IsValid)
     {
         db.DictionaryDetailses.Add(model); //添加
         db.SaveChanges();                  //提交至数据库
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public ActionResult Edit(DictionaryDetails model)
 {
     if (ModelState.IsValid)
     {
         //把存储状态修改成“modified”
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
        //
        // GET: /Home/

        public ActionResult Index(int?pageIndex, DictionaryDetails model)
        {
            var    modelTypes = db.DictionaryTypes;
            string options    = String.Empty;
            bool   hasSelect  = false;//是否被选中如果被选中selected=selected

            foreach (var mt in modelTypes)
            {
                if (model.DictTypeID > 0 && model.DictTypeID == mt.DictTypeID)
                {
                    options  += "<option value='" + mt.DictTypeID + "'selected=selected >" + mt.DictTypeValue + "</option>";
                    hasSelect = true;
                }
                else
                {
                    options += "<option value='" + mt.DictTypeID + "'>" + mt.DictTypeValue + "</option>";
                }
            }
            if (hasSelect == false)
            {
                options = "<option value='0' selected=selected>不限</option>" + options;
            }
            else
            {
                options = "<option value='0'>不限</option>" + options;
            }
            ViewBag.Options      = options;
            ViewBag.DictDetValue = model.DictDetValue;
            //linq语法
            var models = from m in db.DictionaryDetailses select m;

            if (model.DictTypeID > 0)
            {
                models = models.Where(m => m.DictTypeID == model.DictTypeID);
            }
            if (!string.IsNullOrEmpty(model.DictDetValue))
            {
                models = models.Where(m => m.DictDetValue == model.DictDetValue);
            }
            models = models.OrderBy(m => m.DictDetID);
            PagedList <DictionaryDetails> pagedList = new PagedList <DictionaryDetails>(models, pageIndex, CommonData.pagesize);

            return(View(pagedList));
        }
        private void SaveAndGoBack(object obj)
        {
            var filteredList = DictionaryDetails.Where(x => x.Key != null && x.Value != null).ToList();
            //avoid case sensitivity
            //Convert all keys to to lower then check duplicacy
            var duplicateKeys = filteredList.Select(x => x.Key.ToUpper()).ToList().GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key).ToList();

            if (duplicateKeys != null && duplicateKeys.Count != 0)
            {
                new DialogService().ShowError("Error!!", "Please remove duplicate keys from dictionary.", "Ok", null);
            }
            else
            {
                var result = App.PritixDB.DeleteDetailsByMappingIndex(UserSelectedDictionaryMapping.MappingIndex).Result;
                App.PritixDB.SaveAllDictionaryDetails(filteredList).Wait();
                var xxxx = App.PritixDB.GetDictionaryDetailsByMappingIndex(UserSelectedDictionaryMapping.MappingIndex);
                Navigation.PopModalAsync();
            }
        }