} // GetUserExerciseChart public JsonResult GetGlucoseChart() { var data = _glucoseEntryRepo .ReadAll() .OrderBy(o => o.UpdatedAt); return new JsonResult( new { glucoseEntries = data } ); } // GetGlucoseChart
public async Task <IActionResult> CreateGlucoseEntry(string userName, Guid loginToken, GlucoseEntry glucoseEntry) { // Get user from username, verify login token var user = await _users.ReadAsync(userName); if (user.RemoteLoginToken != loginToken) // Check login token { return(new JsonResult( // Return error new { success = false, errorCode = ErrorCode.INVALID_LOGIN_TOKEN } )); } // if if (!_glucose.ReadAll().Any(o => o.Id == glucoseEntry.Id))// Ensure glucose doesn't exist first { return(new JsonResult( // If it does, return error new { success = false, errorCode = ErrorCode.ITEM_ALREADY_EXISTS } )); } if (ModelState.IsValid) { var newGlucoseEntry = await _glucose.CreateAsync(glucoseEntry); return(new JsonResult( // Return success new { success = true, errorCode = ErrorCode.NO_ERROR, newGlucoseEntry.Id } )); } // if return(new JsonResult( // Return unknown error new { success = false, errorCode = ErrorCode.UNKNOWN } )); } // CreateGlucoseEntry