Пример #1
0
        public async void OnCategoryItemClick(object sender, ItemClickEventArgs e)
        {
            if (!(e.ClickedItem is CategoryListViewItemViewModel selectedCategory))
            {
                return;
            }

            var editOperationDialog = new CategoryDialog(new CategoryDialogViewModel(selectedCategory.Model))
            {
                PrimaryButtonText = _localizationService.GetTranslateByKey(Localization.Save),
                CloseButtonText   = _localizationService.GetTranslateByKey(Localization.Cancel)
            };

            await editOperationDialog.ShowAsync();

            switch (editOperationDialog.Result)
            {
            case DialogResult.Save:
                await _model.UpdateCategory(selectedCategory.Model, GetCancellationToken());
                await UpdateCategories();

                break;

            case DialogResult.Delete:
                await _model.DeleteCategory(selectedCategory.Model, GetCancellationToken());
                await UpdateCategories();

                break;
            }
        }
        private async void EditCategory(object sender, RoutedEventArgs e)
        {
            var element  = (FrameworkElement)sender;
            var category = element.DataContext as Category;

            if (category == null)
            {
                return;
            }

            var repository = ServiceLocator.Current.GetInstance <IRepository <Category> >();

            repository.Selected = category;

            var dialog = new CategoryDialog(true);
            await dialog.ShowAsync();
        }
Пример #3
0
        public async void OnAddCategoryClick(object sender, RoutedEventArgs e)
        {
            var newCategory    = new CategoryDialogViewModel(_model.CreateNewCategory());
            var categoryDialog = new CategoryDialog(newCategory)
            {
                PrimaryButtonText = _localizationService.GetTranslateByKey(Localization.Save),
                CloseButtonText   = _localizationService.GetTranslateByKey(Localization.Cancel)
            };

            await categoryDialog.ShowAsync();

            if (categoryDialog.Result == DialogResult.Save)
            {
                await _model.SaveCategory(newCategory.Model, GetCancellationToken());
                await UpdateCategories();
            }
        }