Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "OrderID,CustomerID,EmployeeID,OrderDate,RequiredDate,ShippedDate,ShipperID,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry,productName,UnitPrice,Qty")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                orders.Freight        = (string.IsNullOrEmpty(orders.Freight.ToString())) ? 0 : orders.Freight;
                orders.ShipCountry    = (string.IsNullOrEmpty(orders.ShipCountry)) ? string.Empty : orders.ShipCountry;
                orders.ShipCity       = (string.IsNullOrEmpty(orders.ShipCity)) ? string.Empty : orders.ShipCity;
                orders.ShipRegion     = (string.IsNullOrEmpty(orders.ShipRegion)) ? string.Empty : orders.ShipRegion;
                orders.ShipPostalCode = (string.IsNullOrEmpty(orders.ShipPostalCode)) ? string.Empty : orders.ShipPostalCode;
                orders.ShipAddress    = (string.IsNullOrEmpty(orders.ShipAddress)) ? string.Empty : orders.ShipAddress;
                orders.ShipName       = (string.IsNullOrEmpty(orders.ShipName)) ? string.Empty : orders.ShipName;
                db.Orders.Add(orders);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeID  = new SelectList(db.Employees, "EmployeeID", "FullName");
            ViewBag.CustomerID  = new SelectList(db.Customers, "CustomerID", "CompanyName");
            ViewBag.ShipperID   = new SelectList(db.Shippers, "ShipperID", "CompanyName");
            ViewBag.productName = new SelectList(db.Products, "ProductID", "ProductName");
            return(View(orders));
        }
Ejemplo n.º 2
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        using (TSQL2012Entities myEntities = new TSQL2012Entities())
        {
            var del = (from review in myEntities.Products
                       where review.productid == id
                       select review).SingleOrDefault();

            myEntities.Products.Remove(del);
            myEntities.SaveChanges();
        }

        id_tx.Text = string.Empty;
    }
Ejemplo n.º 3
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     using (TSQL2012Entities myEntities = new TSQL2012Entities())
     {
         var obj = new Product();
         obj.productname  = name_tx.Text;
         obj.supplierid   = Convert.ToInt32(DropDownList1.SelectedValue);
         obj.categoryid   = Convert.ToInt32(DropDownList2.SelectedValue);
         obj.unitprice    = Convert.ToDecimal(price_tx.Text);
         obj.discontinued = Discont_check.Checked;
         myEntities.Products.Add(obj);
         myEntities.SaveChanges();
     }
     name_tx.Text          = string.Empty;
     price_tx.Text         = string.Empty;
     Discont_check.Checked = false;
     grid.Visible          = true;
 }
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (TSQL2012Entities myEntities = new TSQL2012Entities())
        {
            var update = (from review in myEntities.Products
                          where review.productid == id
                          select review).SingleOrDefault();

            update.productname  = name_tx.Text;
            update.supplierid   = Convert.ToInt32(DropDownList1.SelectedValue);
            update.categoryid   = Convert.ToInt32(DropDownList2.SelectedValue);
            update.unitprice    = Convert.ToDecimal(price_tx.Text);
            update.discontinued = Discont_check.Checked;

            myEntities.SaveChanges();
        }


        name_tx.Text          = string.Empty;
        price_tx.Text         = string.Empty;
        Discont_check.Checked = false;
        grid.Visible          = true;
    }