private async void CommandCreateAction() { HasActiveTask = true; var segment = _entity.Content.FirstOrDefault(x => x.Type == ContentSegmentType.Text); if (segment != null) segment.Text = segment.Text?.Trim(); try { if (_entity.ID == null) _entity = await _client.CreatePostAsync(_userID, _entity, CancellationToken.None); else _entity = await _client.UpdatePostAsync(_userID, _entity.ID, _entity, CancellationToken.None); NavigationService.GoBack(); } catch (TaskCanceledException) { } catch (Exception ex) { var template = new DialogTemplate { Title = "Something went wrong", Content = $"There is a problem sending your status. Inquiring minds may find this information helpful: {ex.Message}", PrimaryButtonText = "Close" }; await _dialogService.ShowAsync(template); } HasActiveTask = false; }
public sealed override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> parameters) { base.OnNavigatedTo(e, parameters); _userID = parameters[NavigationParameters.UserID] as string; _entity = parameters[NavigationParameters.PostEntity] as Post; if (e.NavigationMode == NavigationMode.Back) await PopulateDataAsync(); else OnEntityUpdated(); }
public sealed override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary<string, object> parameters) { base.OnNavigatedTo(e, parameters); _userID = parameters[NavigationParameters.UserID] as string; _entity = parameters[NavigationParameters.PostEntity] as Post; OnPropertyChanged(() => Header); OnPropertyChanged(() => Title); OnPropertyChanged(() => Content); OnPropertyChanged(() => IsImportant); }
public PostEntryViewModel(INavigationService navigationService, Post entity, string userID) { if (navigationService == null) throw new ArgumentNullException(nameof(navigationService)); if (entity == null) throw new ArgumentNullException(nameof(entity)); if (userID == null) throw new ArgumentNullException(nameof(userID)); _navigationService = navigationService; _entity = entity; _userID = userID; PopulatePostComments(); _commandNavigateReadPostPage = new DelegateCommand(CommandNavigateReadPostPageAction); }
public static Post Create(Post value) { if (value == null) throw new ArgumentNullException(nameof(value)); var result = new Post(); MigrateTracked(value, result); result.Title = value.Title; result.Importance = value.Importance; MigrateCompositeContent(value.Content, result.Content); return result; }
public async Task<Post> CreatePostAsync(string partyID, Post post, CancellationToken terminator) { if (partyID == null) throw new ArgumentNullException(nameof(partyID)); if (post == null) throw new ArgumentNullException(nameof(post)); VerifyServerAddress(); var uri = new Uri(FormattableString.Invariant($"{_server}/api/parties/{partyID}/posts")); var content = JsonObjectContent.Create(post); using (var response = await _client.PostAsync(uri, content, terminator).ConfigureAwait(false)) { await VerifyResponseAsync(response); return await response.Content.ReadAsJsonObjectAsync<Post>().ConfigureAwait(false); } }
private async Task PopulateDataAsync() { try { HasActiveTask = true; _entity = await _client.FetchPostAsync(_userID, _entity.ID, CancellationToken.None); OnEntityUpdated(); } catch (TaskCanceledException) { } catch (Exception ex) { var template = new DialogTemplate { Title = "Something went wrong", Content = $"There is a problem fetching your status. Inquiring minds may find this information helpful: {ex.Message}", PrimaryButtonText = "Close" }; await _dialogService.ShowAsync(template); } finally { HasActiveTask = false; } }
private void CommandCreateAction() { var entity = new Post { CreatorID = _userID }; var parameters = new Dictionary<string, object> { { NavigationParameters.UserID, _userID }, { NavigationParameters.PostEntity, entity } }; NavigationService.Navigate(NavigationRegistry.WritePostPage, parameters); }