/// <summary> /// Load account details from smartschool. The account must have a valid UID to begin with. /// All other values will be overwritten. /// </summary> /// <param name="account">The account to load.</param> /// <returns>Returns false when failed. Errors will be added to the log object.</returns> public static async Task <bool> Load(IAccount account) { var result = await Task.Run( () => Connector.service.getUserDetails(Connector.password, account.UID) ); try { JSONAccount details = JsonConvert.DeserializeObject <JSONAccount>(result); LoadFromJSON(account, details); return(true); } catch (Exception e) { Error.AddError(e.Message); int iResult = Convert.ToInt32(result); if (iResult != 0) { Error.AddError(iResult); return(false); } return(false); } }
/// <summary> /// Load JSON information retrieved from smartschool into an account. This function is for internal use by the library. /// </summary> /// <param name="account">The target account</param> /// <param name="json">The JSON data to load into this account.</param> internal static void LoadFromJSON(IAccount account, JSONAccount json) { account.UID = json.gebruikersnaam; account.AccountID = json.internnummer != null ? json.internnummer : ""; account.RegisterID = json.rijksregisternummer; if (json.basisrol == "1") { account.Role = AccountRole.Student; } else if (json.basisrol == "2") { account.Role = AccountRole.Teacher; } else if (json.basisrol == "3") { account.Role = AccountRole.Director; } account.GivenName = json.voornaam; account.SurName = json.naam; account.ExtraNames = json.extravoornamen; account.Initials = json.initialen; if (json.geslacht.Equals("m")) { account.Gender = GenderType.Male; } else if (json.geslacht.Equals("f")) { account.Gender = GenderType.Female; } else { account.Gender = GenderType.Transgender; } account.Birthday = Utils.StringToDate(json.geboortedatum); account.BirthPlace = json.geboorteplaats; account.BirthCountry = json.geboorteland; account.Street = json.straat; account.HouseNumber = json.huisnummer; account.HouseNumberAdd = json.busnummer; account.PostalCode = json.postcode; account.City = json.woonplaats; account.Country = json.land; account.MobilePhone = json.mobielnummer; account.HomePhone = json.telefoonnummer; account.Fax = json.fax; account.Mail = json.emailadres; }
/// <summary> /// Get the current account state of the account. /// </summary> /// <param name="account">The target account</param> /// <returns>The current account state</returns> public static async Task <AccountState> GetStatus(IAccount account) { var result = await Task.Run( () => Connector.service.getUserDetails(Connector.password, account.UID) ); try { JSONAccount details = JsonConvert.DeserializeObject <JSONAccount>(result); switch (details.status) { case "actief": case "active": case "enabled": return(AccountState.Active); case "uitgeschakeld": // yes, this correct. Even though you use inactief, inactive or disabled to set this status! return(AccountState.Inactive); case "administrative": case "administratief": return(AccountState.Administrative); default: return(AccountState.Invalid); } } catch (Exception e) { Error.AddError(e.Message); int iResult = Convert.ToInt32(result); if (iResult != 0) { Error.AddError(iResult); return(AccountState.Invalid); } return(AccountState.Invalid); } }