private bool HasAccount(MoodleGetUsersResponseModel responseModel) { List <UserModel> returnedUsers = responseModel.users.ToList <UserModel>(); if (returnedUsers.Count > 0) { return(muModel.username == returnedUsers[0].username); } return(false); }
private UserModel GetUser() { const string logMethodName = ".GetUser() - "; _log.Debug(logMethodName + "Begin Method"); UserModel moodleUser = new UserModel(); string functionName = "core_user_get_users"; String postData = String.Format("{0}={1}", "criteria[0][key]=username&criteria[0][value]", this.muModel.username); //username in moodle is the SALT MemberID string callResult = MoodleServiceCall(functionName, postData); if (callResult.Contains("exception")) { // Error (e.g. invalidtoken) MoodleExceptionModel moodleError = UtilityMethods.DeserializeResponse <MoodleExceptionModel>(callResult); _log.Error("Error in: " + logMethodName + " - " + moodleError.errorcode + " - " + moodleError.message); _log.Debug("Debug info in: " + logMethodName + " - " + moodleError.debuginfo); throw new Exception(moodleError.message); } else { MoodleGetUsersResponseModel responseModel = UtilityMethods.DeserializeResponse <MoodleGetUsersResponseModel>(callResult); if (HasAccount(responseModel)) { if (responseModel.users.Count > 0) { //update Model with the returned id, as update moodle account requires an id returned by get muModel.id = responseModel.users[0].id; moodleUser = responseModel.users[0]; } } } _log.Debug(logMethodName + "End Method"); return(moodleUser); }