private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (UserName.Text != "" || Product.Text != "" || Price.Text != "")
     {
         using (LoginDBEntities db = new LoginDBEntities())
         {
             float             price = Convert.ToUInt64(Price.Text);
             ProductFromPeople p1    = new ProductFromPeople {
                 UserName = UserName.Text, ProductName = Product.Text, Price = price
             };
             p1 = db.ProductFromPeoples.FirstOrDefault();
             if (p1.ProductName != null)
             {
                 db.Entry(p1).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
             }
         }
         UserName.Text = "";
         Product.Text  = "";
         Price.Text    = "";
     }
     else
     {
         MessageBox.Show("Incorrect");
     }
 }
Exemplo n.º 2
0
 private void AddItem(object sender, RoutedEventArgs e)
 {
     if (ItemBox.Text != "" || PriceBox.Text != "")
     {
         float price = 0;
         price = Convert.ToUInt64(PriceBox.Text);
         using (var context = new LoginDBEntities())
         {
             var product = new ProductFromPeople()
             {
                 UserName    = Person.Login,
                 ProductName = ItemBox.Text,
                 Price       = price
             };
             context.ProductFromPeoples.Add(product);
             context.SaveChanges();
             ItemBox.Clear();
             PriceBox.Clear();
             MessageBox.Show("Wait , when admin to add your thing to the main list");
         }
     }
     else
     {
         MessageBox.Show("Incorrect");
     }
 }