public ActionResult Edit(string id) { Mpr_Material MaterialMod = MaterialService.GetModel(s => s.ID == id); if (MaterialMod == null) { MaterialMod = new Mpr_Material(); } return(View(MaterialMod)); }
public ActionResult Edit(Mpr_Material Mod) { ReturnJson Rejson = new ReturnJson(); //修改 //尝试通过ID获取数据库内已有信息 Mpr_Material DBmod = MaterialService.GetModel(s => s.ID == Mod.ID); if (DBmod != null) { //EntityToEntity(Mod, ref DBmod); DBmod.TypeID = Mod.TypeID; Mpr_Material_Type TypeMod = new Mpr_Material_TypeService().GetModel(s => s.ID == DBmod.TypeID); if (TypeMod != null) { DBmod.TypeName = TypeMod.TypeName; } DBmod.Title = Mod.Title; DBmod.Des = Mod.Des; DBmod.Context = Mod.Context; DBmod.UpdateTime = DateTime.Now; DBmod.UpdateUser = currentadminUser.ID; DBmod = MaterialService.Update(DBmod); CreateDataIndex <Mpr_Material>(DBmod, DBmod.ID, "db_MaterialTure", "Mpr_MaterialTure"); if (DBmod != null) { ReturnAlert("保存成功!", 1); } else { ReturnAlert("保存失败!", 0); } } else { Mpr_Material DBmodArticle = new Mpr_Material(); DBmodArticle.ID = Guid.NewGuid().ToString("N"); DBmodArticle.TypeID = Mod.TypeID; Mpr_Material_Type TypeMod = new Mpr_Material_TypeService().GetModel(s => s.ID == DBmodArticle.TypeID); if (TypeMod != null) { DBmodArticle.TypeName = TypeMod.TypeName; } DBmodArticle.Title = Mod.Title; DBmodArticle.Des = Mod.Des; DBmodArticle.Context = Mod.Context; DBmodArticle.AddTime = DateTime.Now; DBmodArticle.AddUser = currentadminUser.ID; DBmodArticle = MaterialService.Insert(DBmodArticle); CreateDataIndex <Mpr_Material>(DBmodArticle, DBmodArticle.ID, "db_MaterialTure", "Mpr_MaterialTure"); if (DBmodArticle != null) { ReturnAlert("保存成功!", 1); } else { ReturnAlert("保存失败!", 0); } } return(View(Mod)); }