private void Button_Click(object sender, RoutedEventArgs e) { ProductsDatabaseEntities db = new ProductsDatabaseEntities(); allProducts.Clear(); db.Products.ToList().ForEach((p) => allProducts.Add(new ProductModel { ProductId = p.ProductId, Quantity = p.Quantity, Price = p.Price, Name = p.Name, Description = p.Description, CoverImage = p.CoverImage })); productsListView.ItemsSource = allProducts; Console.WriteLine(db); db.Products.ToList().ForEach((p) => Console.WriteLine(p.Name)); }
private void addproductbutton_Click(object sender, RoutedEventArgs e) { if (profilePhotoString == null) { MessageBox.Show("Please Select Image First"); return; } Console.WriteLine(productName.Text); Console.WriteLine(productPrice.Text); Console.WriteLine(productQuantity.Text); Console.WriteLine(productDescription.Text); Console.WriteLine(profilePhotoString); Product product = new Product() { Name = productName.Text, Price = int.Parse(productPrice.Text), Quantity = int.Parse(productQuantity.Text), Description = productDescription.Text, CoverImage = profilePhotoString }; try { ProductsDatabaseEntities db = new ProductsDatabaseEntities(); db.Products.Add(product); passedProducts.Add(ProductModel.productModelFromProduct(product)); Console.WriteLine(db.Products.ToList().Count); db.SaveChanges(); Close(); } catch (DbEntityValidationException error) { foreach (var eve in error.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public home(bool isUser) { this.isUser = isUser; InitializeComponent(); navigationRail.SelectedIndex = isUser ? 1 : 0; if (isUser) { navigationRail.Items.RemoveAt(0); } ProductsDatabaseEntities db = new ProductsDatabaseEntities(); db.Products.ToList().ForEach((p) => allProducts.Add(new ProductModel { ProductId = p.ProductId, Quantity = p.Quantity, Price = p.Price, Name = p.Name, Description = p.Description, CoverImage = p.CoverImage })); productsListView.ItemsSource = allProducts; Console.WriteLine(db); db.Products.ToList().ForEach((p) => Console.WriteLine(p.Name)); }