public JsonResult Create(FormCollection col) { try { Guid id = Tool.String2Guid(col["GUID"]); VEGETABLESTYPE model = new VEGETABLESTYPE(); if(id == Guid.Empty) { model.GUID = Guid.NewGuid(); model.CREATEDATETIME = DateTime.Now; FillModel(ref model, col); DbContext.VEGETABLESTYPE.Add(model); }else { model = DbContext.VEGETABLESTYPE.FirstOrDefault(n => n.GUID == id); FillModel(ref model, col); DbContext.Entry(model).State = EntityState.Modified; } DbContext.SaveChanges(); return new JsonM().ToJson(true, MsgHelper.SaveSuccess); } catch (Exception ex) { return new JsonM().ToJson(false, MsgHelper.SaveFail, ex.Message); } }
private void FillModel(ref VEGETABLESTYPE m,FormCollection col) { m.PARENTTYPEID = Tool.String2Guid(col["parentID"]); m.VEGETABLESNAME = col["VEGETABLESNAME"]; m.SEQUENCE = Tool.String2Decimal(col["SEQUENCE"]); m.CREATEUSERID = null; m.CREATEUSERNAME = null; m.ISDELETED = 0; }