public mpObject toJSON(UserDataAccess user) { return(new mpObject( new mpProperty("name", new mpValue(exerciseName)), new mpProperty("video", new mpValue(youtube)), new mpProperty("user1RM", new mpValue(user.GetMostRecentCalibratedOneRepMax(exerciseName).Value)), new mpProperty("recommendedCalibrationWeight", new mpValue(25)), new mpProperty("calibrationWeight", new mpValue(25)), new mpProperty("calibrationReps", new mpValue(-1)), new mpProperty("hasBeenCalibrated", new mpValue(user.GetMostRecentCalibratedOneRepMax(exerciseName).Exists)))); }
/// <summary> /// takes in calibration information for a certain exercise and returns the calculated 1rm /// for that exercise /// </summary> /// <param name="root"></param> /// <param name="db"></param> /// <param name="manager"></param> static void SetupExerciseCalibrationManager(mpBase root, Database db, UserManager manager) { root.addProperty("exercise-calibration", new mpRestfulTarget( new Func <System.Net.HttpListenerRequest, mpResponse>( req => { return(mpResponse.empty400()); } ), new Func <System.Net.HttpListenerRequest, mpResponse>( req => { Console.Write("Received Exercise Calibration Info..."); string requestData = req.data(); string requestEmail = "", requestPasswordEmailHash = ""; double oneRepMax = -1; try { mpObject requestJSON = (mpObject)mpJson.parse(requestData); requestEmail = ((mpValue)requestJSON.getChild("email")).data.asString(); requestPasswordEmailHash = ((mpValue)requestJSON.getChild("passwordEmailHash")).data.asString(); string exName = ((mpValue)requestJSON.getChild("exercise")).data.asString(); UserDataAccess info = new UserDataAccess(db, manager.getUser(requestEmail, requestPasswordEmailHash)); info.IngestCalibrationInfo( exName, ((mpValue)requestJSON.getChild("reps")).data.asInt(), ((mpValue)requestJSON.getChild("weight")).data.asInt() ); info.Store(); oneRepMax = info.GetMostRecentCalibratedOneRepMax(exName).Value; } catch (Exception ex) { Console.WriteLine("Calibration Info Error: " + ex.Message); return(new mpResponse(new binaryData("{\"good\":false, \"message\":\"" + ex.Message + "\"}"), 400)); } return(new mpResponse(new binaryData("{\"good\":true, \"oneRepMax\":" + oneRepMax + "}"), 200)); } ) ) ); }