コード例 #1
0
        public async Task <ActionResult> Create([Bind(Include = "SelectedGoodID,OrderID,Quantity,Price,CustomerID")] NewOrderedGoodViewModel neworderedGood)
        {
            if (Session["CurrentUserID"] == null)
            {
                RedirectToAction("Login", "Home");
            }
            int CurrentUserID = (int)Session["CurrentUserID"];


            if (ModelState.IsValid)
            {
                OrderedGood orderedGood = new OrderedGood
                {
                    UserID     = CurrentUserID,
                    CustomerID = neworderedGood.CustomerID,
                    GoodID     = neworderedGood.SelectedGoodID,
                    Quantity   = neworderedGood.Quantity,
                    OrderID    = neworderedGood.OrderID,
                    Price      = neworderedGood.Price,
                    TotalPrice = neworderedGood.Price * neworderedGood.Quantity
                };
                db.OrderedGoods.Add(orderedGood);
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("ProcessOrder", "Orders", new { id = neworderedGood.OrderID }));
        }
コード例 #2
0
        // GET: OrderedGoods/Create
        public ActionResult Create(int OrderID)
        {
            if (Session["CurrentUserID"] == null)
            {
                RedirectToAction("Login", "Home");
            }
            int CurrentUserID = (int)Session["CurrentUserID"];

            List <SelectListItem> goods = new List <SelectListItem>();

            foreach (GoodInfo good in db.GoodInfoes.Where(d => d.UserID == CurrentUserID))
            {
                goods.Add(new SelectListItem {
                    Text = good.Name, Value = good.Id.ToString()
                });
            }
            NewOrderedGoodViewModel neworderedgood = new NewOrderedGoodViewModel
            {
                OrderID    = OrderID,
                CustomerID = db.Orders.Find(OrderID).customerID,
                AllGoods   = goods,
            };

            return(View(neworderedgood));
        }