コード例 #1
0
        /// <summary>
        /// Saves details about an item
        /// </summary>
        private async void SaveItemAsync()
        {
            // If we are loading, do not save the item
            if (_isLoading)
            {
                return;
            }

            try
            {
                // Set item properties
                Item.Name       = ItemName;
                Item.Notes      = Notes;
                Item.Background = SelectedColor;

                var oldCategoryId = Item.CategoryId;

                Item.CategoryId = Category.Id;

                // Update the item
                await KryptPadApi.SaveItemAsync(oldCategoryId, Item);
            }
            catch (WebException ex)
            {
                // Something went wrong in the api
                await DialogHelper.ShowMessageDialogAsync(ex.Message);
            }
            catch (Exception ex)
            {
                // Failed
                await DialogHelper.ShowGenericErrorDialogAsync(ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the move command
        /// </summary>
        /// <param name="obj"></param>
        private async void MoveItemsCommandHandler(object obj)
        {
            // Show a dialog to pick a new category
            var dialog = new ChangeCategoryDialog();

            // Show the dialog
            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                // Get the model
                var m = dialog.DataContext as ChangeCategoryDialogViewModel;

                try
                {
                    // Save each item
                    foreach (var item in SelectedItems)
                    {
                        // Store old category
                        var oldCategoryId = item.CategoryId;
                        // Set new category
                        item.CategoryId = m.SelectedCategory.Id;
                        // Save
                        await KryptPadApi.SaveItemAsync(oldCategoryId, item);
                    }

                    // Refresh the view
                    await RefreshCategoriesAsync();
                }
                catch (WebException ex)
                {
                    // Something went wrong in the api
                    await DialogHelper.ShowMessageDialogAsync(ex.Message);
                }
                catch (Exception ex)
                {
                    // Failed
                    await DialogHelper.ShowGenericErrorDialogAsync(ex);
                }
            }
        }
コード例 #3
0
        private async void AddItemCommandHandler(object p)
        {
            // Prompt to create the new item
            var dialog = new AddItemDialog();

            // Show the dialog and wait for a response
            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                try
                {
                    // Get the category
                    var category = p as ApiCategory;

                    // Create an item
                    var item = new ApiItem()
                    {
                        Name = dialog.ItemName
                    };

                    // Save the item to the api
                    var r = await KryptPadApi.SaveItemAsync(category.Id, item);

                    // Set the item
                    item.Id = r.Id;

                    // If a template was selected, create a couple of fields to start with
                    if (dialog.SelectedItemTemplate != null)
                    {
                        var templateFields = dialog.SelectedItemTemplate.Fields;

                        // A template was selected, add all the fields from the template
                        foreach (var templateField in templateFields)
                        {
                            // Create field
                            var field = new ApiField()
                            {
                                Name      = templateField.Name,
                                FieldType = templateField.FieldType
                            };

                            // Send to api
                            await KryptPadApi.SaveFieldAsync(category.Id, item.Id, field);
                        }
                    }


                    // Navigate to item edit page
                    NavigationHelper.Navigate(typeof(NewItemPage), new EditItemPageParams()
                    {
                        Category = category,
                        Item     = item
                    });
                }
                catch (WebException ex)
                {
                    // Something went wrong in the api
                    await DialogHelper.ShowMessageDialogAsync(ex.Message);
                }
                catch (Exception ex)
                {
                    // Failed
                    await DialogHelper.ShowGenericErrorDialogAsync(ex);
                }
            }
        }