示例#1
0
        public async Task <IAccountCreateResult> CreateAsync(string email, string name = null, string password = null, bool sendActivationEmail = true, bool acceptTerms = true)
        {
            // Guard

            if (string.IsNullOrEmpty(password))
            {
                throw new ApplicationException("Password must be specified");
            }

            // Create json to post

            var jaccount = new JAccountCreate
            {
                Email               = email,
                Name                = string.IsNullOrEmpty(name) ? EmailUtility.SniffName(email) : name,
                Password            = password,
                SendActivationEmail = sendActivationEmail,
                AcceptTerms         = acceptTerms
            };

            // Post

            JAccountCreateResult jresult = null;

            using (var client = Settings.HttpClientFactory.Create())
            {
                HttpResponseMessage response = await client.PostAsJsonAsync(Endpoint, jaccount);

                if (response.IsSuccessStatusCode)
                {
                    jresult = await response.Content.ReadAsAsync <JAccountCreateResult>();
                }

                response.EnsureSuccessStatusCode();
            }

            // Map from wire representation

            return(new AccountCreateResult(jresult));
        }
示例#2
0
        // Constructors

        public AccountCreateResult(JAccountCreateResult jresult)
        {
            ActivationCode = jresult.ActivationCode;
            PersonId       = jresult.PersonId;
        }