示例#1
0
        /// <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);
            }
        }
示例#2
0
        /// <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);
            }
        }
示例#3
0
        /// <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 ?? "";
            account.RegisterID = json.Rijksregisternummer;
            try
            {
                account.StemID = Convert.ToInt32(json.Stamboeknummer);
            } catch (Exception)
            {
                // ignore this Connector.Log.AddError(Origin.Smartschool, "Ongeldig stamboeknummer bij account " + json.Gebruikersnaam);
            }


            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;
            account.Status      = json.Status;
        }