Exemple #1
0
        /// <summary>
        /// Updates user name or email
        /// </summary>
        /// <param name="user">User to update</param>
        /// <param name="password">Password</param>
        /// <returns>Retunr user</returns>
        public async Task<Model.User> UpdateEmailOrUsernameAsync(Model.User user, string password)
        {
            try
            {
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url + "UpdateUserOrMail/" + GameStore.WindowsApp.Common.UserInfo.Id);

                // Content and authorization
                UserEntityToSend modelToSend = new UserEntityToSend(user, password);
                string toSend = JsonConvert.SerializeObject(modelToSend);
                request.Content = new StringContent(toSend, Encoding.UTF8, "application/json");
                request.Headers.Add("Authorization", "Beaerer " + GameStore.WindowsApp.Common.UserInfo.Token);

                // Response
                HttpResponseMessage response = await client.SendAsync(request);

                // Deserialize response
                string result = await response.Content.ReadAsStringAsync();
                User userResult = JsonConvert.DeserializeObject<User>(result);

                return userResult;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Exemple #2
0
        /// <summary>
        /// Register new user
        /// </summary>
        /// <param name="user">User to register</param>
        /// <param name="password">password</param>
        /// <returns>Bool on success</returns>
        public async Task<bool> RegisterUser(Model.User user, string password)
        {
            try
            {
                UserEntityToSend toSend = new UserEntityToSend(user, password);

                string jsonContent = JsonConvert.SerializeObject(toSend);

                HttpResponseMessage response = await client.PostAsync(url + "register", new StringContent(jsonContent, Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                    return true;
                else
                    return false;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }