Exemplo n.º 1
0
 //метод для actionUpdCategories
 private void UpdateCategoriesLB()
 {
     using (var context = new HwContext())
     {
         categories = context.Categories.ToList();
     }
 }
Exemplo n.º 2
0
 private void UpdateBtnClick(object sender, RoutedEventArgs e)
 {
     using (var context = new HwContext())
     {
         books.ToList().ForEach(x => context.Update(x));
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 //метод для Func
 private List <Product> UpdateProductsLB()
 {
     using (var context = new HwContext())
     {
         selectedCategory = context.Categories.FirstOrDefault(x => x.Id == selectedCategory.Id);
         var products = context.Products.Where(x => x.CategoryId == selectedCategory.Id).ToList();
         return(products);
     }
 }
Exemplo n.º 4
0
 public MainWindow()
 {
     InitializeComponent();
     using (var context = new HwContext())
     {
         books = new ObservableCollection <Book>(context.Books.ToList());
     }
     dataGrid.ItemsSource = books;
 }
Exemplo n.º 5
0
 //метод для action
 private void SaveOrUpdateProduct(Product product)
 {
     using (var context = new HwContext())
     {
         if (selectedProduct != null)
         {
             var contextProduct = context.Products.FirstOrDefault(x => x.Id == selectedProduct.Id);
             contextProduct.Name       = product.Name;
             contextProduct.CategoryId = product.CategoryId;
             context.SaveChanges();
             return;
         }
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 //метод для action
 private void SaveOrUpdateCategory(string name)
 {
     using (var context = new HwContext())
     {
         if (selectedCategory != null)
         {
             var contextCategory = context.Categories.FirstOrDefault(x => x.Id == selectedCategory.Id);
             contextCategory.Name = name;
             context.SaveChanges();
             return;
         }
         context.Categories.Add(new Category
         {
             Name = name
         });
         context.SaveChanges();
         categories = context.Categories.ToList();
     }
 }
Exemplo n.º 7
0
 private void AddBtnClick(object sender, RoutedEventArgs e)
 {
     using (var context = new HwContext())
     {
         int.TryParse(priceTB.Text, out var price);
         context.Add(new Book
         {
             Author    = authorTB.Text,
             Price     = price,
             TitleName = titleNameTB.Text
         });
         priceTB.Text     = "";
         authorTB.Text    = "";
         titleNameTB.Text = "";
         context.SaveChanges();
         books = new ObservableCollection <Book>(context.Books.ToList());
         dataGrid.ItemsSource = books;
     }
 }