public ActionResult Edit(string id) { FlowDefSub DefSub = ctx.FlowDefSubList.Where(x => x.id == id).FirstOrDefault(); getUserList(ctx); return(View(DefSub)); }
public ActionResult AddDefSub(string pid) { var context = new ApplicationDbContext(); getFlowMainData(context, pid); getUserList(context); FlowDefSub DefSub = new FlowDefSub { pid = pid, id = "", seq = 1, signType = 0, workNo = "" }; ViewBag.EditMode = "Create"; return(View(DefSub)); }
public ActionResult AddDefSub(FlowDefSub model) { dbHelper dbh = new dbHelper(); if (string.IsNullOrEmpty(model.id)) { ViewBag.EditMode = "Create"; model.id = Guid.NewGuid().ToString(); FlowDefMain fmain = ctx.FlowDefMainList.Where(x => x.id == model.pid).FirstOrDefault(); if (fmain.enm == "RealOverTime" && model.signType != 3 && model.signType != 4) { ModelState.AddModelError("signType", "加班單限定為串簽或直接許可"); } if (fmain.enm == "DayOff" && model.signType != 3 && model.signType != 4) { ModelState.AddModelError("signType", "請假單限定為串簽或直接許可"); } if (!string.IsNullOrEmpty(model.workNo)) { int iuser = dbh.sql2count( "select count(workNo) cnt from FlowDefSub where workNo='" + model.workNo + "' and pid='" + model.pid + "'" ); if (iuser > 0) { ModelState.AddModelError("workNo", "工號重複"); } } if (model.signType == 2) { int iSign1 = dbh.sql2count("select count(workNo) cnt from FlowDefSub where signType=1 and pid='" + model.pid + "'"); ModelState.AddModelError("signType", "已有設定【1.會簽】,不允許【2.會簽-全部同意】"); } } else { ViewBag.EditMode = "Edit"; } if (model.signType == 0) { ModelState.AddModelError("signType", "請選擇簽核類別"); } if (!ModelState.IsValid) { getUserList(new ApplicationDbContext()); return(View(model)); } else { ApplicationDbContext context = new ApplicationDbContext(); try { context.FlowDefSubList.Add(model); context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); getUserList(new ApplicationDbContext()); return(View(model)); } return(RedirectToAction("SetupFLow", new { id = model.pid })); } }