public JsonResult CreateMold() { try { var mold_code = Request.Form["mold_code"]; var data = db.td_mold.Find(mold_code); if (data == null) { td_mold mold = new td_mold(); mold.mold_code = mold_code; mold.item_code = Request.Form["item_code"] != null ? Request.Form["item_code"].ToString() : null; mold.mold_type = byte.Parse(Request.Form["mold_type"].ToString()); mold.unit = Request.Form["unit"]; mold.location = Request.Form["location"]; mold.mold_diameter = Request.Form["mold_diameter"] != null ? Request.Form["mold_diameter"].ToString() : null; mold.create_dt = DateTime.Now; mold.create_by = Session["MCS_Authen"].ToString(); db.td_mold.Add(mold); db.SaveChanges(); } return(Json(new { Result = "OK", Record = db.td_mold.OrderByDescending(o => o.create_dt).FirstOrDefault() })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult CreateMold() { try { string moldcode = Request.Form["moldcode"]; td_mold mold = new td_mold(); mold.mold_code = moldcode; mold.mold_type = byte.Parse(Request.Form["moldtype"].ToString()); mold.item_code = Request.Form["itemcode"] != null ? Request.Form["itemcode"].ToString() : null; mold.location = Request.Form["location"]; mold.unit = Request.Form["unit"]; mold.mold_diameter = Request.Form["molddiameter"] != null ? Request.Form["molddiameter"].ToString() : null; mold.create_dt = DateTime.Now; mold.create_by = Session["MCS_Authen"].ToString(); db.td_mold.Add(mold); db.SaveChanges(); return(RedirectToAction("AddLedger", "Home", new { mold_code = moldcode })); } catch (Exception ex) { TempData["ErrorMessage"] = ex; return(View("AddMold")); } }
public ActionResult CreateMold() { try { var mold_code = Request.Form["mold_code"]; var mold_no = int.Parse(Request.Form["mold_no"]); var mold_exist = dbTEMS.td_mold.Any(w => w.mold_code == mold_code && w.mold_no == mold_no); if (!mold_exist) { td_mold newmold = new td_mold(); newmold.mold_code = mold_code; newmold.mold_no = mold_no; newmold.item_code = Request.Form["item_code"]; newmold.status_id = int.Parse(Request.Form["status"]); newmold.location_id = byte.Parse(Request.Form["location"]); newmold.cav_per_unit = int.Parse(Request.Form["cav_per_unit"]); newmold.unit_id = byte.Parse(Request.Form["unit"]); dbTEMS.td_mold.Add(newmold); var ulv = byte.Parse(Session["TEMS_ULv"].ToString()); var org = int.Parse(Session["TEMS_Org"].ToString()); var actor = Session["TEMS_Auth"].ToString(); ManageTran(mold_code, mold_no, 0, ulv, org, 1, "-", actor); dbTEMS.SaveChanges(); TempData["alert-success"] = "New Mold received successfully."; } else { TempData["alert-danger"] = "This mold already exist."; } } catch (Exception ex) { TempData["alert-danger"] = "Error on receive mold -> " + ex; } return(RedirectToAction("Receive", "Mold")); }