Beispiel #1
0
        public async Task <Models.REST.V1_1.Login.Output.RootObject> RegistrationLogin(string email, string username, string password)
        {
            Models.REST.V1_1.Login.Output.RootObject Result = null;
            var url = new StringBuilder();

            url.Append(BaseUrl).Append(UserRegistration);
            RemoveAuthorizationHeader();
            try
            {
                var userAccount = new Models.REST.V1_1.Registration.Input.RootObject {
                    email = email, password = password, username = username
                };

                var parameters = userAccount.SaveAsJson();

                var request = new HttpRequestMessage(HttpMethod.Post,
                                                     new Uri(url.ToString(), UriKind.RelativeOrAbsolute))
                {
                    Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(parameters)))
                };


                var result = await _client.SendAsync(request);

                var content = await result.Content.ReadAsStringAsync();

                if (!result.IsSuccessStatusCode)
                {
                    var e = JsonConvert.DeserializeObject <Models.REST.V1_1.Registration.Error.RootObject>(content).message;
                    throw new ArgumentException(e);
                }
                Result       = JsonConvert.DeserializeObject <Models.REST.V1_1.Login.Output.RootObject>(content);
                Result.email = email;
            }
            catch (HttpRequestException hex)
            {
                throw hex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Result);
        }
Beispiel #2
0
        public async Task <Models.REST.V1_1.Login.Output.RootObject> DoLogin(string email, string password)
        {
            var Result = new Models.REST.V1_1.Login.Output.RootObject();
            var url    = new StringBuilder();

            url.Append(BaseUrl).Append(Login);
            RemoveAuthorizationHeader();
            try
            {
                var login = new Models.REST.V1_1.Login.Input.RootObject {
                    email = email, password = password
                };

                var parameters = login.SaveAsJson();

                var request = new HttpRequestMessage(HttpMethod.Post,
                                                     new Uri(url.ToString(), UriKind.RelativeOrAbsolute))
                {
                    Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(parameters)))
                };


                var result = await _client.SendAsync(request);

                var content = await result.Content.ReadAsStringAsync();

                Result       = JsonConvert.DeserializeObject <Models.REST.V1_1.Login.Output.RootObject>(content);
                Result.email = email;
            }
            catch (HttpRequestException hex)
            {
                throw hex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Result);
        }