/// <summary>
        /// Starts creating a new category and handles
        /// error messaging.
        /// </summary>
        /// <returns>True, if creation succeeded. Otherwise, false.</returns>
        public async Task <bool> CreateCategory()
        {
            try
            {
                IsBusy = true;
                _categoryMatchFinder.ValidateCategoryAcceptanceCriteria(Category.Name, _categories);
                await _petCareService.CreateCategory(Category.Name);

                return(true);
            }
            catch (CategoryMatchedException)
            {
                await _dialogService.ShowNotification("CategoryAlreadyExists_Message", "CategoryAlreadyExists_Title");

                return(false);
            }
            catch (Exception)
            {
                await _dialogService.ShowGenericServiceErrorNotification();

                return(false);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
        private async void OnAddCategory()
        {
            try
            {
                // Ask user if category should be created.
                var confirmationResult = await
                                         _dialogService.ShowYesNoNotification("CreateCategoryRequestConfirmation_Message",
                                                                              "CreateCategoryRequestConfirmation_Title");

                if (confirmationResult)
                {
                    IsBusy = true;

                    // Validate category name.
                    _categoryMatchFinder.ValidateCategoryAcceptanceCriteria(SearchText, Categories);
                    var category = await _petCareService.CreateCategory(SearchText);

                    // The created category needs to be added to the view
                    // and pre-selected so that the user can continue immediately.
                    Categories.Add(category);
                    RefreshFilteredList(category);
                    SelectedCategory = category;
                }
            }
            catch (CategoryMatchedException)
            {
                await _dialogService.ShowNotification("CategoryAlreadyExists_Message", "CategoryAlreadyExists_Title");
            }
            catch (Exception)
            {
                await _dialogService.ShowGenericServiceErrorNotification();
            }
            finally
            {
                IsBusy = false;
            }
        }