public IActionResult AddEdit(int?id) { DbVisaapiVisaInf_VMS VisaInfv = new DbVisaapiVisaInf_VMS(); if (id.HasValue) { DbVisaapiVisaInf VisaInf = context.Set <DbVisaapiVisaInf>().SingleOrDefault(c => c.VisaInfId == id.Value); if (VisaInf != null) { VisaInfv.VisaInfId = VisaInf.VisaInfId; VisaInfv.VisaName = VisaInf.VisaName; VisaInfv.VisaNat = VisaInf.VisaNat; VisaInfv.VisaPrice = VisaInf.VisaPrice; VisaInfv.VisaSettlement = VisaInf.VisaSettlement; VisaInfv.VisaSOM = VisaInf.VisaSOM; VisaInfv.VisaType = VisaInf.VisaType; VisaInfv.VisaYear = VisaInf.VisaYear; VisaInfv.IsDel = VisaInf.IsDel; VisaInfv.ModifiedDate = DateTime.UtcNow.ToString(); VisaInfv.ModifiedUser = VisaInf.ModifiedUser; VisaInfv.VisaEXP = VisaInf.VisaEXP; VisaInfv.VisaGOL = VisaInf.VisaGOL; } } return(PartialView("~/Views/VisaInf/_AddEdit.cshtml", VisaInfv)); }
public IActionResult AddEdit(int?id, DbVisaapiVisaInf_VMS VisaInfv) { var result = new Dictionary <string, object>(); var msg = "出现异常"; var state = false; try { if (ModelState.IsValid) { bool isNew = !id.HasValue; if (VisaInfv.VisaInfId == 0 || VisaInfv.VisaInfId == null) { isNew = true; } else { isNew = false; } DbVisaapiVisaInf VisaInf = isNew ? new DbVisaapiVisaInf { CreatDate = DateTime.UtcNow, CreatUser = "******" } : context.Set <DbVisaapiVisaInf>().SingleOrDefault(b => b.VisaInfId == VisaInfv.VisaInfId); VisaInf.VisaName = VisaInfv.VisaName; VisaInf.VisaNat = VisaInfv.VisaNat; VisaInf.VisaPrice = VisaInfv.VisaPrice; VisaInf.VisaSettlement = VisaInfv.VisaSettlement; VisaInf.VisaSOM = VisaInfv.VisaSOM; VisaInf.VisaType = VisaInfv.VisaType; VisaInf.VisaYear = VisaInfv.VisaYear; VisaInf.IsDel = VisaInfv.IsDel; VisaInf.ModifiedDate = DateTime.UtcNow; VisaInf.ModifiedUser = VisaInfv.ModifiedUser; VisaInf.VisaEXP = VisaInfv.VisaEXP; VisaInf.VisaGOL = VisaInfv.VisaGOL; if (isNew) { context.Add(VisaInf); msg = "添加成功"; } else { msg = "修改成功"; } context.SaveChanges(); state = true; } } catch (Exception ex) { //throw ex; state = false; msg = "修改失败" + ex; } result.Add("state", state); result.Add("msg", msg); return(Json(result)); }
public ActionResult Edit(DbVisaapiVisaInf_VMS VisaInfv, long?id) { Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("success", true); try { if (ModelState.IsValid) { bool isNew = !id.HasValue; DbVisaapiVisaInf VisaInf = isNew ? new DbVisaapiVisaInf { CreatDate = DateTime.UtcNow, CreatUser = VisaInfv.CreatUser } : context.Set <DbVisaapiVisaInf>().SingleOrDefault(b => b.VisaInfId == id.Value); VisaInf.VisaName = VisaInfv.VisaName; VisaInf.VisaNat = VisaInfv.VisaNat; VisaInf.VisaPrice = VisaInfv.VisaPrice; VisaInf.VisaSettlement = VisaInfv.VisaSettlement; VisaInf.VisaSOM = VisaInfv.VisaSOM; VisaInf.VisaType = VisaInfv.VisaType; VisaInf.VisaYear = VisaInfv.VisaYear; VisaInf.IsDel = VisaInfv.IsDel; VisaInf.ModifiedDate = DateTime.UtcNow; VisaInf.ModifiedUser = VisaInfv.ModifiedUser; VisaInf.VisaEXP = VisaInfv.VisaEXP; VisaInf.VisaGOL = VisaInfv.VisaGOL; if (isNew) { context.Add(VisaInf); } context.SaveChanges(); result["success"] = false; result.Add("msg", "修改成功!"); } } catch (Exception ex) { result["success"] = false; result.Add("msg", "修改失败!"); throw ex; } return(Json(result)); }