public ActionResult AddTool(Models.DormInfo obj) { var rst = Json(new { success = true, message = 1 }, JsonRequestBehavior.AllowGet); if (obj.Broom <= obj.Broom_Max && obj.Mop <= obj.Mop_Max && obj.Trash <= obj.Trash_Max && obj.Water <= obj.Water_Max) { try { var dormInfo = db.DormInfo.FirstOrDefault(); dormInfo.Broom_Max = obj.Broom_Max; dormInfo.Broom = obj.Broom; dormInfo.Mop_Max = obj.Mop_Max; dormInfo.Mop = obj.Mop; dormInfo.Trash_Max = obj.Trash_Max; dormInfo.Trash = obj.Trash; dormInfo.Water_Max = obj.Water_Max; dormInfo.Water = obj.Water; db.SaveChanges(); } catch (Exception) { rst = Json(new { success = true, message = 0 }, JsonRequestBehavior.AllowGet); } } else { rst = Json(new { success = true, message = 0 }, JsonRequestBehavior.AllowGet); } return(rst); }
public string GetTool(Models.DormInfo obj) { var jss = new JavaScriptSerializer(); Models.DormInfo dorm = db.DormInfo.FirstOrDefault(); StringBuilder sb = new StringBuilder(); String json = jss.Serialize(dorm).ToString(); return(json); }