public ActionResult DeleteToCar(int id = 0) { B_ShoppingCar b_ShoppingCar = db.B_ShoppingCar.Find(id); db.B_ShoppingCar.Remove(b_ShoppingCar); db.SaveChanges(); return(RedirectToAction("CartList")); }
public void DeleteShoppingCar(int userID) { B_ShoppingCar sc = new B_ShoppingCar(); var q = from n in db.B_ShoppingCar where n.UserID == userID select n; db.B_ShoppingCar.RemoveRange(q); db.SaveChanges(); }
public string AddCart(int userID, int classID) { B_ShoppingCar car = CheckCart(userID, classID); var Check_OrderDetail = db.B_OrderDetail.Where(o => o.B_Order.UserID == userID && o.ClassID == classID).FirstOrDefault(); string s = string.Empty; if (Check_OrderDetail != null) { s = "已報名此課程"; return(s); } if (car == null) { car = new B_ShoppingCar(); car.UserID = userID; car.ClassID = classID; db.B_ShoppingCar.Add(car); db.SaveChanges(); s = ""; return(s); } s = "課程已在購物車"; return(s); }