public ActionResult edit(int id, sysKeyValueView model) { try { if (ModelState.IsValid == false) { return(WriteError("实体验证失败")); } //1.0 将model中的Kid补全 model.KID = id; //2.0 进行数据的编辑 sysKeyValue entity = model.EntityMap(); keyvalSer.Edit(entity, new string[] { "KType", "KName", "Kvalue", "KRemark" }); keyvalSer.SaveChanges(); return(WriteSuccess("数据编辑成功")); } catch (Exception ex) { return(WriteError(ex)); } }
public ActionResult add(sysKeyValueView model) { try { if (!ModelState.IsValid) { return(base.WriteError("实体验证失败")); } //转换实体 sysKeyValue entity = model.EntityMap(); _keyvalSer.Add(entity); _keyvalSer.SaveChanges(); return(base.WriteSuccess("新增成功")); } catch (Exception ex) { return(base.WriteError(ex)); } }
public static sysKeyValue EntityMap(this sysKeyValueView model) { //2.0 将一个实体转换成另外一个实体 return(Mapper.Map <sysKeyValueView, sysKeyValue>(model)); }
public static sysKeyValue EntityMap(this sysKeyValueView model) { return(Mapper.Map <sysKeyValueView, sysKeyValue>(model)); }