/// <summary> /// Event handler for menu item click. /// After this operation user's current profile updates. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Routed event argument</param> public async void ChangeProfileEventHandler(object sender, RoutedEventArgs e) { var item = (MenuItem)sender; var dictionary = App.Current.Resources; if (item.Header == dictionary[User.Default.CurrentProfile]) { return; } var client = ((App)App.Current).UserApiClient; var currentProfile = (string)item.Header; var profileUpdateInfo = new ProfileUpdateInfo { Id = User.Default.Id, Profile = (string)dictionary[currentProfile] }; var response = await client.UpdateCurrentProfileAsync(profileUpdateInfo); if (response.Status == Status.Ok) { this._vm.CurrentProfile = currentProfile; User.Default.CurrentProfile = profileUpdateInfo.Profile; User.Default.Save(); this.UpdateButtonsVisibilities(); this._vm.PhotoUrl = ConfigurationManager.AppSettings[User.Default.CurrentProfile]; var app = ((App)App.Current); var tokenProvider = app.TokenProvider; var tokenResponse = await tokenProvider.RefreshAccessTokenAsync(); if (tokenResponse == TokenStatus.Error) { return; } app.RiseProfileChanged(); RecipeMessageBox.Show((string)dictionary["current_update_success"]); } else { RecipeMessageBox.Show((string)dictionary["current_update_fail"]); } }
/// <summary> /// Updates current profile /// </summary> /// <param name="profileUpdateInfo">Profile update info</param> /// <returns>response</returns> public async Task <Response <string> > UpdateCurrentProfileAsync(ProfileUpdateInfo profileUpdateInfo) { var response = await this._userApiHttpClient.PutAsync("api/users/profile", this.ConstructContent(profileUpdateInfo)); if (!response.IsSuccessStatusCode) { return(this.ConstructResponse(Status.Error, response.ReasonPhrase)); } return(this.ConstructResponse(Status.Ok, await response.Content.ReadAsStringAsync())); }
public IActionResult Put([FromBody] ProfileUpdateInfo profileUpdateInfo) { // checking id if (profileUpdateInfo.Id != this.GetUserId()) { return(new StatusCodeResult(401)); } // updating current profile var result = (int)this._dataManager .Operate <ProfileUpdateInfo, object>("UpdateCurrentProfile", profileUpdateInfo); // if profile not found return 404 if (result == -1) { return(new StatusCodeResult(404)); } // return 200 return(new StatusCodeResult(200)); }