private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (var storageContext = new StorageContext())
            {
                storageContext.Categories.Load();
                storageContext.Models.Load();

                var categoriesList = storageContext.Categories.Local.ToList();
                categoriesList.Insert(0, new Category { Name = "Vælg venligst", CategoryId = -1 });
                var modelsList = storageContext.Models.Local.ToList();
                modelsList.Insert(0, new Model { Name = "Vælg venligst", ModelId = -1 });

                categoryViewSource.Source = categoriesList;
                modelViewSource.Source = modelsList;
            }
        }
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            using (var storageContext = new StorageContext())
            {
                storageContext.Types.Load();

                var queryCategoryTypes =
                    from categories in storageContext.Categories
                    join types in storageContext.Types on categories.CategoryId equals types.CategoryId
                    where categories.CategoryId == (int)ComboBoxCategory.SelectedValue
                    select types;

                var queryCategoryTypesList = queryCategoryTypes.ToList();
                if (queryCategoryTypesList.Count > 0)
                    queryCategoryTypesList.Insert(0, new Type { Name = "Vælg venligst", TypeId = -1 });
                else
                    queryCategoryTypesList.Insert(0, new Type { Name = "Ingen data", TypeId = -1 });

                typeViewSource.Source = queryCategoryTypesList;
            }
        }
 private void ButtonDelete_Click(object sender, RoutedEventArgs e)
 {
     using (var storageContext = new StorageContext())
     {
         storageContext.Products.Remove(storageContext.Products.Find(Convert.ToInt32(TextBoxProductNumber.Text)));
         storageContext.SaveChanges();
     }
     Close();
 }
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            bool allRequiredBoxesValidated = true;

            if (TextBoxName.Text.Equals(""))
                allRequiredBoxesValidated = false;
            else if (ComboBoxCategory.SelectedValue.Equals(-1))
                allRequiredBoxesValidated = false;
            else if (ComboBoxModel.SelectedValue.Equals(-1))
                allRequiredBoxesValidated = false;
            else if (ComboBoxType.SelectedValue.Equals(-1))
                allRequiredBoxesValidated = false;
            else if (TextBoxAmount.Text.Equals(""))
                allRequiredBoxesValidated = false;

            if (allRequiredBoxesValidated)
            {
                using (var storageContext = new StorageContext())
                {
                    var product = new Product();

                    if (!TextBoxProductNumber.Text.Equals(""))
                    {
                        product = storageContext.Products.Find(Convert.ToInt32(TextBoxProductNumber.Text));
                    }
                    else
                    {
                        storageContext.Products.Add(product);
                    }

                    product.Name = TextBoxName.Text;
                    product.ModelId = (int)ComboBoxModel.SelectedValue;
                    product.TypeId = (int)ComboBoxType.SelectedValue;
                    product.Quantity = Convert.ToInt32(TextBoxAmount.Text);
                    product.Comment = new TextRange(RichTextBoxComment.Document.ContentStart, RichTextBoxComment.Document.ContentEnd).Text;

                    storageContext.SaveChanges();

                    var productsList =
                        from products in storageContext.Products
                        orderby products.ProductId descending
                        select products;

                    productViewSource.Source = productsList.ToList();

                    Title = "Se produkt";
                    UpdateUI();
                }

            }
        }
        private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            ProductPage productPage = new ProductPage();

            DataRowView row = (DataRowView)products_ViewDataGrid.SelectedItems[0];

            productPage.Title = "Se produkt";
            productPage.UpdateUI();
            using (var storageContext = new StorageContext())
            {
                var product = storageContext.Products.Find(Convert.ToInt32(row["Product_Number"].ToString()));
                productPage.TextBoxName.Text = product.Name;
                productPage.TextBoxProductNumber.Text = product.ProductId.ToString();
                productPage.ComboBoxCategory.SelectedValue = product.Type.CategoryId;
                productPage.ComboBoxModel.SelectedValue = product.ModelId;
                productPage.ComboBoxType.SelectedValue = product.TypeId;
                productPage.TextBoxAmount.Text = product.Quantity.ToString();
                productPage.RichTextBoxComment.AppendText(product.Comment);
            }
            productPage.ShowDialog();
            populateView();
        }