Ejemplo n.º 1
0
        /// <summary>
        /// Loads the categories
        /// </summary>
        /// <returns></returns>
        public async Task LoadCategoriesAsync()
        {
            try
            {
                // Get the categories from the api
                var result = await KryptPadApi.GetCategoriesAsync();

                // Add the categories
                foreach (var category in result.Categories)
                {
                    Categories.Add(category);
                }
            }
            catch (WebException ex)
            {
                // Something went wrong in the api
                await DialogHelper.ShowMessageDialogAsync(ex.Message);
            }
            catch (Exception ex)
            {
                // Failed
                await DialogHelper.ShowGenericErrorDialogAsync(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads an item into the view model
        /// </summary>
        /// <param name="item"></param>
        public async Task LoadItemAsync(ApiItem selectedItem, ApiCategory category)
        {
            // Prevent change triggers
            _isLoading = true;
            IsBusy     = true;

            try
            {
                // Get list of categories for the combobox control
                var categories = await KryptPadApi.GetCategoriesAsync();

                // Set the category view source for the combobox
                CategoriesView.Source = categories.Categories;

                // Update view
                OnPropertyChanged(nameof(CategoriesView));

                // Set the selected category in the list
                Category = (from c in categories.Categories
                            where c.Id == category.Id
                            select c).SingleOrDefault();

                // Check to make sure our parameters are set
                if (Category == null)
                {
                    // Show error
                    throw new WarningException("The item you are trying to edit does not exist in this category.");
                }

                // Get the item
                var itemResp = await KryptPadApi.GetItemAsync(Category.Id, selectedItem.Id);

                // Get the item
                var item = itemResp.Items.FirstOrDefault();

                // Set item
                Item = item;

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

                // Set fields
                foreach (var field in item.Fields)
                {
                    // Add field to the list
                    AddFieldToCollection(new FieldModel(field));
                }
            }
            catch (WarningException ex)
            {
                // Operation failed
                await DialogHelper.ShowMessageDialogAsync(ex.Message);
            }
            catch (WebException ex)
            {
                // Operation failed
                await DialogHelper.ShowMessageDialogAsync(ex.Message);

                // Navigate back to the items page
                NavigationHelper.Navigate(typeof(ItemsPage), null);
            }
            catch (Exception ex)
            {
                // Failed
                await DialogHelper.ShowGenericErrorDialogAsync(ex);

                // Navigate back to the items page
                NavigationHelper.Navigate(typeof(ItemsPage), null);
            }

            _isLoading = false;
            IsBusy     = false;
        }