Esempio n. 1
0
        private async void SaveModel()
        {
            try
            {
                if (_updatingPage)
                {
                    PrepareModelForSave();

                    await _specRepo.UpdateAsync(SpecModel);

                    await _specRepo.SaveChangesAsync();

                    TriggerSaveEvent();
                }
                else
                {
                    PrepareModelForSave();

                    _specRepo.Add(SpecModel);
                    await _specRepo.SaveChangesAsync();

                    // Forces the product form and category form to be refreshed the next time they're opened, because the products and categories are dependent on the specifications
                    var window = (NavigationWindow)GetParentWindow();
                    window.ccProductForm.Content  = null;
                    window.ccCategoryForm.Content = null;

                    TriggerSaveEvent();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected override async void Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                SpecificationOverviewItem ToBeDeleted = ((FrameworkElement)sender).DataContext as SpecificationOverviewItem;

                string messageboxTitle   = String.Format(LangResource.MBTitleDeleteObj, ToBeDeleted.SpecName);
                string messageboxContent = String.Format(LangResource.MBContentDeleteObj, LangResource.TheSpec.ToLower(), ToBeDeleted.SpecName);

                MessageBoxManager.Yes = LangResource.Yes;
                MessageBoxManager.No  = LangResource.No;
                MessageBoxManager.Register();

                if (MessageBox.Show(messageboxContent,
                                    messageboxTitle,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning)
                    == MessageBoxResult.Yes)
                {
                    MessageBoxManager.Unregister();

                    _specRepo.Delete(ToBeDeleted.ID);
                    SpecList.Remove(ToBeDeleted);

                    await _specRepo.SaveChangesAsync();

                    BindData();
                }
                else
                {
                    MessageBoxManager.Unregister();
                }
            }
            catch (Exception)
            { MessageBoxManager.Unregister();
              MessageBox.Show(LangResource.ErrUpdateOverviewFailed); }
        }