コード例 #1
0
        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;
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
		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);
			}
		}
コード例 #7
0
        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;
            }
        }
コード例 #8
0
        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);
        }