public ActionResult Form(string strEnum, SD_ITEM_INFO model) { model.SD_ITEM_ALGO = HttpUtility.UrlDecode(model.SD_ITEM_ALGO, Encoding.Default); model.SD_ITEM_NAME = HttpUtility.UrlDecode(model.SD_ITEM_NAME, Encoding.Default); model.SD_ITEM_ALIAS = HttpUtility.UrlDecode(model.SD_ITEM_ALIAS, Encoding.Default); var row = 0; SD_ITEM_INFO entity = null; model.SD_ITEM_ALGO = model.SD_ITEM_ALGO.Replace("'", "\""); //保存或修改并更新到数据库 var exist = _itemService.Exists(r => r.SD_ITEM_ID == model.SD_ITEM_ID); if (exist) { entity = _itemService.GetWithTrace(r => r.SD_ITEM_ID == model.SD_ITEM_ID); entity.SD_ITEM_CODE = model.SD_ITEM_CODE; entity.SD_ITEM_NAME = model.SD_ITEM_NAME; entity.SD_ITEM_ALIAS = model.SD_ITEM_ALIAS; entity.SD_ITEM_CAT_ID = model.SD_ITEM_CAT_ID; entity.SD_ITEM_DATA_TYPE = model.SD_ITEM_DATA_TYPE; entity.SD_ITEM_UNIT = model.SD_ITEM_UNIT; entity.NUM_PRECISION = model.NUM_PRECISION; entity.SD_ITEM_SRC = model.SD_ITEM_SRC; entity.IS_RESULT = model.IS_RESULT; entity.ORDER_NO = model.ORDER_NO; entity.SD_ITEM_ALGO = model.SD_ITEM_ALGO; entity.VALID_FLAG = model.VALID_FLAG; //entity.SD_EKPI_DESC = model.SD_EKPI_DESC; entity.IS_PUBLIC = model.IS_PUBLIC; row = _itemService.Update(entity); } else { SD_ITEM_INFO value = new SD_ITEM_INFO() { SD_ITEM_CODE = _projectService.GetCurrentSD().SD_CODE + "_TEST", SD_ITEM_NAME = model.SD_ITEM_NAME, SD_ITEM_ALIAS = model.SD_ITEM_ALIAS, SD_ITEM_CAT_ID = model.SD_ITEM_CAT_ID, SD_ITEM_DATA_TYPE = model.SD_ITEM_DATA_TYPE, SD_ITEM_UNIT = model.SD_ITEM_UNIT, NUM_PRECISION = model.NUM_PRECISION, SD_ITEM_SRC = 2, IS_RESULT = model.IS_RESULT, ORDER_NO = model.ORDER_NO, SD_ITEM_ALGO = model.SD_ITEM_ALGO, VALID_FLAG = model.VALID_FLAG, //SD_EKPI_DESC = model.SD_EKPI_DESC, IS_PUBLIC = 0, }; entity = _itemService.Insert(value); model.SD_ITEM_ID = entity.SD_ITEM_ID; } if (!string.IsNullOrWhiteSpace(strEnum)) { var enumList = JsonConvert.DeserializeObject <Dictionary <string, string> >(strEnum);//strEnum.Split(','); var index = 0; foreach (var enumV in enumList) { var id = enumV.Key.Contains("new") ? 0 : int.Parse(enumV.Key); var enumModel = new SD_ITEM_OPTION() { ITEM_OPTION_ID = id, SD_ITEM_ID = model.SD_ITEM_ID, ITEM_OPTION_NAME = enumV.Value, ORDER_NO = index + 1 }; if (_itemOptionService.Exists(r => r.SD_ITEM_ID == model.SD_ITEM_ID && r.ITEM_OPTION_ID == id)) { _itemOptionService.Update(enumModel); } else { _itemOptionService.Insert(enumModel); } } } if (exist) { return(row > 0 ? Success() : Error()); } return(entity != null?Success() : Error()); }