Beispiel #1
0
        public ActionResult Save(OrderViewModel model)
        {
            if (ModelState.IsValid)
            {
                Order anOrder = new Order();
                anOrder.OrderId    = model.OrderId;
                anOrder.CustomerId = model.CustomerId;
                anOrder.ItemId     = model.ItemId;
                anOrder.Date       = model.Date;
                anOrder.Quantity   = model.Quantity;
                anOrder.Unitprice  = model.Unitprice;
                anOrder.TotalPrice = model.TotalPrice;

                if (model.OrderId > 0)
                {
                    db.Entry(anOrder).State = EntityState.Modified;
                }
                else
                {
                    db.Orders.Add(anOrder);
                }
                int saveChanges = db.SaveChanges();

                if (saveChanges > 0)
                {
                    return(RedirectToAction("Index", model));
                }
            }
            model.Customers = db.Customers.ToList();
            model.Items     = db.Items.ToList();

            return(View("Edit", model));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "ItemId,ItemName,Description")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
Beispiel #3
0
 public ActionResult Edit([Bind(Include = "CustomerId,Name,Email,Address")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }