Beispiel #1
0
        private async void AddItem_Button_OnClick(object sender, RoutedEventArgs e)
        {
            AddItemName.Text        = "";
            AddItemName.Description = "";
            AddItemAmount.Value     = 1;

            if (await AddItemDialog.ShowAsync() != ContentDialogResult.Primary)
            {
                return;
            }

            try
            {
                var item = new ItemDTO()
                {
                    Title       = AddItemName.Text,
                    Description = AddItemDesc.Text,
                    Amount      = (int)Math.Ceiling(AddItemAmount.Value)
                };

                var newItem = await _service.AddPackingItem(_tripId, _sectionId, item);

                _items.Add(newItem);
                _tripDetailsPage.UpdateProgressBar();
                Bindings.Update();
            }
            catch
            {
                //TODO exception handling
            }
        }
Beispiel #2
0
        private async void AddItem()
        {
            AddItemDialog dialog = new AddItemDialog(Categories);

            ContentDialogResult result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                if (!String.IsNullOrEmpty(dialog.ItemName) && dialog.SelectedCategory != null)
                {
                    Item itemToAdd = new Item(dialog.ItemName, dialog.SelectedCategory);
                    int  id        = await _itemRepository.Add(itemToAdd);

                    itemToAdd.Id = id;
                    Items.Add(itemToAdd);
                    BuildItemList();
                }
            }
        }
Beispiel #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);
                }
            }
        }