public User AddUser(User user) { var query = (from u in this.context.Users where u.Email == user.Email select u); if (query.SingleOrDefault() == null) { return this.context.Users.Add(user); } else { return null; } }
public async Task<User> GetUserByEmail(String email) { User user = new User(); using (HttpClient client = new HttpClient()) { string url = string.Format("{0}{1}", URL, "/user?email=" + email); using (HttpResponseMessage response = await client.GetAsync(url)) { if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); user = await JsonConvert.DeserializeObjectAsync<User>(content); } } } return user; }
//ADDUSER & LIST OF USERS public async void AddUser(User user) { using (HttpClient client = new HttpClient()) { try { string url = string.Format("{0}{1}", URL, "user/add"); string json = JsonConvert.SerializeObject(user); HttpContent content = new StringContent(json); content.Headers.Clear(); content.Headers.Add("Content-Type", "application/json"); await client.PostAsync(url, content); } catch (Exception ex) { throw ex; } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { getGpsLocation(); try { LiveAuthClient auth = new LiveAuthClient(); LiveLoginResult initializeResult = await auth.InitializeAsync(); try { LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic", "wl.emails" }); if (loginResult.Status == LiveConnectSessionStatus.Connected) { LiveConnectClient connect = new LiveConnectClient(auth.Session); LiveOperationResult operationResult = await connect.GetAsync("me"); dynamic result = operationResult.Result; if (result != null) { User u = new User(); u.FirstName = result.first_name; u.LastName = result.last_name; u.Email = result.emails.account; _vm.SaveUser(u); _vm.ActiveUser = u; } } } catch (LiveAuthException exception) { } catch (LiveConnectException exception) { } } catch (LiveAuthException exception) { } }
public void SaveUser(User user) { shredderService.AddUser(user); }
public async void GetUserByEmail(string email) { ActiveUser = await shredderService.GetUserByEmail(email); }