public JsonResult CreateLevel() { try { var formData = byte.Parse(Request.Form["lv_id"].ToString()); var min = byte.Parse(Request.Form["pos_min"].ToString()); var max = byte.Parse(Request.Form["pos_max"].ToString()); var dbData = dbPcr.TM_Level.Where(w => w.lv_id == formData).FirstOrDefault(); if (dbData == null) { TM_Level data = new TM_Level(); data.lv_id = formData; data.lv_name = Request.Form["lv_name"].ToString(); data.pos_min = min; data.pos_max = max; data.update_dt = DateTime.Now; data.update_by = Session["PCRME_Auth"].ToString(); dbPcr.TM_Level.Add(data); } dbPcr.SaveChanges(); return(Json(new { Result = "OK", Record = dbPcr.TM_Level.OrderByDescending(o => o.update_dt).FirstOrDefault() })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult CreateLevel() { try { var formData = byte.Parse(Request.Form["lv_id"].ToString()); var dbData = dbDC.TM_Level.Where(w => w.lv_id == formData).FirstOrDefault(); if (dbData == null) { TM_Level data = new TM_Level(); data.lv_id = formData; data.lv_name = Request.Form["lv_name"].ToString(); data.position_min = byte.Parse(Request.Form["position_min"].ToString()); data.position_max = byte.Parse(Request.Form["position_max"].ToString()); data.update_dt = DateTime.Now; data.update_by = Session["DC_Auth"].ToString(); dbDC.TM_Level.Add(data); } dbDC.SaveChanges(); //Creating method must return the new created object as Record property. return(Json(new { Result = "OK", Record = dbDC.TM_Level.OrderByDescending(o => o.update_dt).FirstOrDefault() })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }