//用 productID 新增一筆訂單 public bool AddPorduct(string fProductID) { var findItem = this.cartItems .Where(s => s.fProductID == fProductID) .Select(s => s) .FirstOrDefault(); //判斷裡面有沒有相同的 fProductID if (findItem == default(CartItem)) { //不存在 就新增一筆 using (dbMSIT126TeamEntities db = new dbMSIT126TeamEntities()) { var detial = (from p in db.tOrderDetails where p.fProductID == fProductID select p).FirstOrDefault(); if (detial != default(tOrderDetail)) { this.AddPorduct(detial); } } } else { //如果已經有了 數量+1 findItem.fQuantity += 1; } return(true); }
public ActionResult Registeration(tCustomer p) { try { if (p != null) { dbMSIT126TeamEntities db = new dbMSIT126TeamEntities(); p.fUserName = Session[CDictionary.SK_Logon_UserName].ToString(); db.tCustomers.Add(p); db.SaveChanges(); var q = (from c in db.tCustomers where c.fUserName == p.fUserName select c.fCustomerID).FirstOrDefault(); Session[CDictionary.SK_Logon_ID] = q.ToString(); return(RedirectToAction("Index", "Home")); } return(View()); } catch { p.fUserName = User.Identity.Name; db.tCustomers.Add(p); db.SaveChanges(); var q = (from c in db.tCustomers where c.fUserName == p.fUserName select c.fCustomerID).FirstOrDefault(); Session[CDictionary.SK_Logon_ID] = q.ToString(); return(RedirectToAction("Index", "Manage")); } }
public ActionResult Product() { using (dbMSIT126TeamEntities db = new dbMSIT126TeamEntities()) { var result = from p in db.tProducts select p; return(View(result.ToList())); } }
//GlassID 轉成 Glass Name public static string getTheGlassName(int GlassID) { dbMSIT126TeamEntities db = new dbMSIT126TeamEntities(); string innerText = (from p in db.tGlasses where p.fGlassID == GlassID select p.fGlassName).FirstOrDefault(); return(innerText); }
public ActionResult Edit(int?id) { try { dbMSIT126TeamEntities db = new dbMSIT126TeamEntities(); var q = db.tWorkingTimes.Where(p => p.fWorkingID == id).FirstOrDefault(); return(View(q)); } catch { return(View()); } }
// GET: CheckIn public ActionResult EmpCheckInData() { try { dbMSIT126TeamEntities db = new dbMSIT126TeamEntities(); var q = db.tWorkingTimes.Select(p => p); return(View(q)); } catch { return(View()); } }
// GET: del public void del() { dbMSIT126TeamEntities db = new dbMSIT126TeamEntities(); var x = db.tCustomers.Where(p => p.fUserName == "*****@*****.**").FirstOrDefault(); var y = db.AspNetUsers.Where(p => p.UserName == "*****@*****.**").FirstOrDefault(); if (x != null) { db.tCustomers.Remove(x); db.SaveChanges(); } if (y != null) { db.AspNetUsers.Remove(y); db.SaveChanges(); } }
public ActionResult Index(tOrder theOrder) { //取得購物車 var currentCart = operation.GetCurrentCart(); using (dbMSIT126TeamEntities db = new dbMSIT126TeamEntities()) { //建立 tOrder 物件 var order = new tOrder() { fCustomerID = theOrder.fCustomerID, fDeliverDate1 = theOrder.fDeliverDate1, fDeliverDate2 = theOrder.fDeliverDate1.AddDays(30), fDeliverDate3 = theOrder.fDeliverDate1.AddDays(60), fDeliverDate4 = theOrder.fDeliverDate1.AddDays(180), fOrderDate = theOrder.fOrderDate, fEmployeeID = 18, //預設18號 fMaterialPrice = 140, //鋁料價格寫死 140 fDoorFee = 1.3, //預設 1.3 fScreenFee = 1.3, //預設 1.3 fInstallationFee = 1.3, //預設 1.3 fGlassFee = 1, //預設 1 fWaterwayFee = 1, //預設 1 fCrackFee = 1, //預設 1 fOrderConfirm = "0" //預設 0 (未確認) }; //儲存面更 db.tOrders.Add(order); db.SaveChanges(); //取得購物車裡面的 order detail var orderDetail = currentCart.TOrderDetailList ( order.fOrderID, (decimal)order.fMaterialPrice, (double)order.fDoorFee, (double)order.fScreenFee, (double)order.fInstallationFee, (double)order.fGlassFee, (double)order.fWaterwayFee, (double)order.fCrackFee ); //加入 order detail 資料後儲存 db.tOrderDetails.AddRange(orderDetail); db.SaveChanges(); //把訂單總額寫進 tOrder decimal OrderTotal = (decimal)db.tOrderDetails.Where(p => p.fOrderID == order.fOrderID).Select(p => p.fQuantity * p.fSubTotal).Sum(p => p) * 1.05m; //含稅5% order.fGetMoneyBack1 = OrderTotal * 0.4m; order.fGetMoneyBack2 = OrderTotal * 0.4m; order.fGetMoneyBack3 = OrderTotal * 0.1m; order.fGetMoneyBack4 = OrderTotal * 0.1m; db.SaveChanges(); } //return Content("訂購成功"); return(RedirectToAction("Index", "Home")); }