Esempio n. 1
0
        // Product
        public Product createProduct(string name, decimal unitprice, int countavailable, string pic, string country, string category, string description, Boolean newP)
        {
            Product p = new Product();
            p.name = name;
            try
            {
                p.picture=convertToByteArray(new BitmapImage(new Uri(@pic)));
            }
            catch
            {
                p.picture = null;
            }
            p.category = category;
            p.description = description;
            p.@new = newP;
            p.unitPrice = unitprice;
            p.rating = 0;
            p.countAvailable = countavailable;
            p.country = country;
            p.monthsale = false;
            db.Products.Add(p);
            db.SaveChanges();

            return p;
        }
Esempio n. 2
0
 public void deleteProduct(Product p)
 {
     if (p != null)
     {
         db.Products.Remove(p);
         db.SaveChanges();
     }
 }
Esempio n. 3
0
 public void updateProduct(Product p, string newName, decimal newUnitprice, int newCountavailable, string newCountry, string newPic, string description, string category, Boolean @new)
 {
     if (newName != null && p != null && newPic != null)
     {
         p.name = newName;
         p.unitPrice = newUnitprice;
         p.countAvailable = newCountavailable;
         p.country = newCountry;
         try {
         p.picture = convertToByteArray(new BitmapImage(new Uri(@newPic)));
         }
         catch
         {
             p.picture = null;
         }
         p.description = description;
         p.category = category;
         p.@new = @new;
         db.SaveChanges();
         filldata(db.Products.ToList());
     }
 }
Esempio n. 4
0
 //Hjælpe event til products: lytter på om selection ændres i datagrided
 private void Event_SelectionChanged(object sender, RoutedEventArgs e)
 {
     List<Product> l = new List<Product>();
     l = db.Products.ToList();
     Product pe = new Product();
     if (grid.SelectedItem != null)
     {
         pe = (Product)grid.SelectedItem;
         img.Source = service.getImage(pe.name);
     }
     else
     {
         grid.SelectedItem = l.ElementAt(0);
     }
 }