public bool Save訂購交易(ShoppingCart cart) { // Todo: // 交由 DAO (Data Access Object) 物件,並透 EF (Entity Framework)將本次訂購商品交易儲存至資料庫 return true; }
public ShoppingCart 確認訂購資訊(ShoppingCart cart) { 烏龜BMO bmo = new 烏龜BMO(); cart = bmo.proc訂購資訊(cart); return cart; }
// 結帳 public ActionResult Checkout(string btnCheckout) { switch (btnCheckout) { case "結帳" : { cart = (ShoppingCart)Session["ShoppingCart"]; ViewData["result"] = this.SaveOrder(cart); // 將處理儲存訂購結果回傳給 View return View(); } case "取消" : return RedirectToAction("Index", "Facade"); default: return View(); } }
public ShoppingCart proc訂購資訊(ShoppingCart cart) { int total = 0; foreach (烏龜商品 item in cart.CartList) { total = total + (item.price * item.quantity); } // Todo: // 實作應有相關於 eCoupon 的處理邏輯︰這裡僅示範簡單的商業邏輯處理 if (cart.eCoupon.Equals("1688")) cart.TotalPrice = Convert.ToInt32(total * 0.9); //九折優惠 else cart.TotalPrice = total; return cart; }
public ActionResult AddToCart() { cart.CartList = new List<烏龜商品>(); 烏龜商品 m_item; string m_id, m_qty; // Get the itemList from Session Object. itemList = (List<烏龜商品>)Session["ItemList"]; // Get the Form's ID string[] keys = Request.Form.AllKeys; foreach (var key in keys) { if (key.Contains("id")) { m_id = Request.Params[key]; m_item = itemList.Where(t => t.id == m_id).SingleOrDefault(); // 取得所相對應烏龜清單內的商品 if (m_item != null) { m_qty = Request.Params["qty_" + m_id]; if (string.IsNullOrEmpty(m_qty)) continue; m_item.quantity = Int32.Parse(m_qty); cart.CartList.Add(m_item); // 將所購買的商品放入 ShoppingCart 物件內 } } } cart.eCoupon = Request["txtCoupon"]; // 取得 Coupon 欄位值 cart = control.確認訂購資訊(cart); // 交由 Facade 物件計算訂購總額,並再將結果傳回 Session["ShoppingCart"] = cart; // Hold the ShoppingCart object to Session return View(cart); }
// 委由 Facade 物件儲存本次的訂購交易 private string SaveOrder(ShoppingCart cart) { if (control.Save訂購交易(cart)) return "訂購完成"; else return "交易失敗"; }