public async Task <IActionResult> Edit(int id, [Bind("JigID,JigNo,Column,Row")] m_Jig m_Jig) { if (id != m_Jig.JigID) { return(NotFound()); } if (ModelState.IsValid) { try { // TODO edit //m_Jig.JigUserDef1 = DateTime.Today; m_Jig.ModifyBy = "Jom"; _context.Update(m_Jig); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!m_JigExists(m_Jig.JigID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(m_Jig)); }
[HttpPost] // Create public IActionResult Post(string values) { var model = new m_Jig(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } //checked duplicate if (_context.m_Jig.Any(o => o.JigNo == model.JigNo)) { ModelState.AddModelError("ModelError", string.Format("JigNo {0} is duplicate.", model.JigNo)); return(BadRequest(GetFullErrorMessage(ModelState))); } int newJigID = 1 + _context.m_Jig.Max(p => p.JigID); model.JigID = newJigID; model.CreateDate = DateTime.Now; //// TODO edit 2 line //model.JigUserDef1 = DateTime.Today; model.ModifyBy = GetUserName(); // "FixIt"; var result = _context.m_Jig.Add(model); _context.SaveChanges(); return(Json(result.Entity.JigID)); }
private void PopulateModel(m_Jig model, IDictionary values) { //string JigID = nameof(m_Jig.JigID); string JigNo = nameof(m_Jig.JigNo); string Column = nameof(m_Jig.Column); string Row = nameof(m_Jig.Row); string JigUserDef1 = nameof(m_Jig.JigUserDef1); string JigUserDef2 = nameof(m_Jig.JigUserDef2); //if (values.Contains(JigID)) { // model.JigID = Convert.ToInt32(values[JigID]); //} if (values.Contains(JigNo)) { model.JigNo = Convert.ToString(values[JigNo]); } if (values.Contains(Column)) { model.Column = Convert.ToInt32(values[Column]); } if (values.Contains(Row)) { model.Row = Convert.ToInt32(values[Row]); } if (values.Contains(JigUserDef1)) { model.JigUserDef1 = Convert.ToString(values[JigUserDef1]); } if (values.Contains(JigUserDef2)) { model.JigUserDef2 = Convert.ToString(values[JigUserDef2]); } }
//public async Task<IActionResult> Create([Bind("JigID,JigNo,Column,Row,JigUserDef1,JigUserDef2,TransDate,CreateDate,ModifyBy")] m_Jig m_Jig) { public async Task <IActionResult> Create([Bind("JigID,JigNo,Column,Row")] m_Jig m_Jig) { if (ModelState.IsValid) { int newJigID = 1 + _context.m_Jig.Max(p => p.JigID); m_Jig.JigID = newJigID; // TODO edit 2 line //m_Jig.JigUserDef1 = DateTime.Today; m_Jig.ModifyBy = "Jom"; _context.Add(m_Jig); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(m_Jig)); }