コード例 #1
0
ファイル: Person.cs プロジェクト: JeffreyQ1/Swarmops
        public static Person Create(string name, string email, string password, string phone, string street,
                                    string postal, string city, string countryCode, DateTime dateOfBirth,
                                    PersonGender gender)
        {
            BasicCountry country = null;

            if (countryCode.Length > 0)
            {
                country = Structure.Country.FromCode(countryCode);
            }

            // Clean data

            while (name.Contains("  "))
            {
                name = name.Replace("  ", " ");
            }

            name   = name.Trim();
            email  = email.ToLower().Trim();
            phone  = LogicServices.CleanNumber(phone);
            postal = postal.Replace(" ", "").Trim();

            int personId = SwarmDb.GetDatabaseForWriting().CreatePerson(name, email, phone, street, postal, city,
                                                                        country == null? 0: country.Identity, dateOfBirth, gender);


            // Resolve the geography

            Person newPerson = Person.FromIdentityAggressive(personId); // aggressive bypasses replication lag, avoids race condition

            newPerson.ResolveGeography();

            // Generate the salted password hash and set it

            if (password.Length > 0)
            {
                newPerson.PasswordHash = Authentication.GenerateNewPasswordHash(personId, password);
            }
            else
            {
                newPerson.PasswordHash = string.Empty; // if no password, prevent matching to anything
            }

            // Return the finished Person object

            return(newPerson);
        }