Beispiel #1
0
 [Authorize] //設定此Action須登入
 public ActionResult Put(int Id, string toPage)
 {
     //若Session中無購物車資料,以使用者名稱與時間,新增一購物車資料
     if (HttpContext.Session["Cart"] == null)
     {
         HttpContext.Session["Cart"] =
             DateTime.Now.ToString() + User.Identity.Name;
     }
     //藉由Service來將商品放入購物車中
     cartService.AddtoCart(HttpContext.Session["Cart"].ToString(), Id);
     //判斷傳入的toPage來決定導向
     if (toPage == "Item")
     {
         return(RedirectToAction("Item", "Home", new { Id = Id }));
     }
     else if (toPage == "ItemBlock")
     {
         return(RedirectToAction("ItemBlock", "Home", new { Id = Id }));
     }
     else
     {
         //重新導向頁面至開始頁面
         return(RedirectToAction("Index"));
     }
 }