Esempio n. 1
0
        protected void SubmitItemButton_Click(object sender, EventArgs e)
        {
            string ItemName        = ItemNameTextBox.Text;
            string ItemPrice       = ItemPriceTextBox.Text;
            string ItemDescription = ItemDescTextBox.Text;
            string ItemImageURL    = ItemImageURLTextBox.Text;

            var cs = ConfigurationManager.AppSettings["ShopDB"];

            using (var ItemDC = new ItemDataContext(cs))
            {
                var CurrentItems        = ItemDC.Items.ToList();
                var ItemWithTheSameName = (from i in CurrentItems
                                           where i.name == ItemName
                                           select i);
                if (ItemWithTheSameName.Any())
                {
                    Label1.Text = "Przedmiot o tej nazwie już istnieje";
                    return;
                }

                Item newItem = new Item();

                newItem.name        = ItemName;
                newItem.price       = Double.Parse(ItemPrice);
                newItem.description = ItemDescription;
                newItem.image       = ItemImageURL;

                ItemDC.Items.InsertOnSubmit(newItem);
                ItemDC.SubmitChanges();
                Label1.Text              = "Dodano przedmiot";
                ItemNameTextBox.Text     = "";
                ItemPriceTextBox.Text    = "";
                ItemDescTextBox.Text     = "";
                ItemImageURLTextBox.Text = "";

                //HttpContext.Current.Session["item_model"] = new Item_Model();
            }
        }
Esempio n. 2
0
        protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart")
            {
                if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return;
                }

                ShoppingCart shoppingCart = ShoppingCart.Instance;
                int          id           = Int32.Parse(e.CommandArgument.ToString());

                var cs = System.Configuration.ConfigurationManager.AppSettings["ShopDB"];
                using (var ItemDC = new ItemDataContext(cs))
                {
                    Item itemToAdd = (from i in ItemDC.Items.ToList()
                                      where i.id == id
                                      select i).First();

                    shoppingCart.AddItem(itemToAdd);
                }
            }
        }