public async Task <IActionResult> BuyAsync(int?id) { if (!id.HasValue) { return(NotFound("You must pass a product ID in the route, for example, /cart/buy/21")); } List <CartItem> cart = CartDAL.GetCart(HttpContext.Session); int index = isExist(id.Value); if (index != -1) { cart[index].Quantity++; } else { CartProduct cartProduct = await MapNorthwindToCartAsync(id.Value); cart.Add(new CartItem { Product = cartProduct, Quantity = 1 }); } CartDAL.SetCart(HttpContext.Session, cart); return(RedirectToAction("Index")); }
protected void Page_Load(object sender, EventArgs e) { string strSiteCode = string.Empty; string strCustomerID = string.Empty; if (null == Request.QueryString["SiteCode"] || null == Request.QueryString["CustomerID"]) { if (null != Session["SiteCode"]) { Response.Redirect("Login.aspx?SiteCode=" + Session["SiteCode"].ToString(), false); } return; } strSiteCode = Common.Common.NoHtml(Request.QueryString["SiteCode"].ToString()); strCustomerID = Common.Common.NoHtml(Request.QueryString["CustomerID"].ToString()); List <SP_MyCart> liCart = new List <SP_MyCart>(); CartDAL dal = new CartDAL(); //DataSet ds = dal.GetProductList("KM_HLF", "31A10FB1-43C2-48A3-A2BA-5B451DE13276"); //?SiteCode=KM_HLF&CatID=31A10FB1-43C2-48A3-A2BA-5B451DE13276 //?SiteCode=KM_HLF&CatID=02F25D57-1BA6-438A-B965-428160A0AA68 DataSet ds = dal.GetMyCartList(strSiteCode, strCustomerID); foreach (DataRow row in ds.Tables[0].Rows) { //SP_ShoppingCart model = DataConvert.DataRowToModel<SP_ShoppingCart>(row); SP_MyCart model = DataConvert.DataRowToModel <SP_MyCart>(row); liCart.Add(model); } string strReturn = dal.GetMyCatSum(strSiteCode, strCustomerID); //读取模板内容 string text = System.IO.File.ReadAllText(Server.MapPath("Themes/Default/MyCart.html")); JinianNet.JNTemplate.TemplateContext context = new JinianNet.JNTemplate.TemplateContext(); context.TempData["title"] = "我的购物车"; if (null == Session["strName"]) { context.TempData["username"] = "******"; } else { context.TempData["username"] = CustomerSession.strName; } context.TempData["sitecode"] = strSiteCode; context.TempData["customerid"] = strCustomerID; context.TempData["cart_list"] = liCart; context.TempData["footer"] = "奥琦微商易"; context.TempData["cs"] = strReturn.Split('|')[1].ToString(); context.TempData["ps"] = strReturn.Split('|')[2].ToString(); context.TempData["sp"] = strReturn.Split('|')[3].ToString(); JinianNet.JNTemplate.Template t = new JinianNet.JNTemplate.Template(context, text); t.Render(Response.Output); }
public static List <Product> Getcart() { List <Product> CART = new List <Product>(); CART = CartDAL.Getcart(); return(CART); }
public static bool Removecart(Product Prodfound) { bool status = false; status = CartDAL.Removecart(Prodfound); return(status); }
public static bool dropcart() { bool status = false; status = CartDAL.Purge(); return(status); }
public IActionResult Index() { var cart = CartDAL.GetCart(HttpContext.Session); ViewBag.cart = cart; ViewBag.total = cart.Sum(item => item.Product.Price * item.Quantity); return(View()); }
protected void Page_Load(object sender, EventArgs e) { if (null != Request.QueryString["id"]) { strOrderID = Common.Common.NoHtml(Request.QueryString["id"].ToString()); } else { if (null != Session["strSiteCode"]) { Response.Redirect("Login.aspx?SiteCode='" + Session["strSiteCode"].ToString() + "'", false); } return; } List <SP_MyOrderDetail> liOrder = new List <SP_MyOrderDetail>(); CartDAL dal = new CartDAL(); DataSet ds = dal.GetOrderList(strOrderID); if (null != ds && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { iCs = ds.Tables[0].Rows.Count; foreach (DataRow row in ds.Tables[0].Rows) { //SP_ShoppingCart model = DataConvert.DataRowToModel<SP_ShoppingCart>(row); SP_MyOrderDetail model = DataConvert.DataRowToModel <SP_MyOrderDetail>(row); iPs = iPs + model.Quantity; dSp = dSp + model.Quantity * model.UnitCost; liOrder.Add(model); } } //读取模板内容 string text = System.IO.File.ReadAllText(Server.MapPath("Themes/Default/MyOrderDetail.html")); JinianNet.JNTemplate.TemplateContext context = new JinianNet.JNTemplate.TemplateContext(); context.TempData["title"] = "订单详细信息"; if (null == Session["strName"]) { context.TempData["username"] = "******"; } else { context.TempData["username"] = CustomerSession.strName; } context.TempData["order_list"] = liOrder; context.TempData["footer"] = "奥琦微商易"; context.TempData["cs"] = iCs.ToString(); context.TempData["ps"] = iPs.ToString(); context.TempData["sp"] = dSp.ToString(); JinianNet.JNTemplate.Template t = new JinianNet.JNTemplate.Template(context, text); t.Render(Response.Output); }
public IActionResult Remove(int id) { List <CartItem> cart = CartDAL.GetCart(HttpContext.Session); int index = isExist(id); cart.RemoveAt(index); CartDAL.SetCart(HttpContext.Session, cart); return(RedirectToAction("Index")); }
public IActionResult Receipt(CartCheckoutViewModel cartCheckout) { //int employeeID = cartCheckout.EmployeeID; //int shipperID = cartCheckout.ShipperID; //string customerID = cartCheckout.CustomerID; //create order DateTime orderDate = DateTime.Now; Order order = new Order(); var cart = CartDAL.GetCart(HttpContext.Session); order.CustomerID = cartCheckout.CustomerID; order.EmployeeID = cartCheckout.EmployeeID; order.Freight = 10 + (cart.Count * 1); order.OrderDate = orderDate; order.RequiredDate = DateTime.Now.AddDays(7); //order.ShippedDate = DateTime.Now.AddDays(5);// filled out in Admin section order.ShipVia = cartCheckout.ShipperID; if (cartCheckout.CustomerID != null) { Customer customer = _NorthwindDAL.GetCustomer(cartCheckout.CustomerID); order.ShipName = customer.ContactName; // cartCheckout.Name; order.ShipAddress = customer.Address; // cartCheckout.Address; order.ShipCity = customer.City; // cartCheckout.City; order.ShipRegion = customer.Region; // cartCheckout.State; order.ShipPostalCode = customer.PostalCode; // cartCheckout.PostalCode; order.ShipCountry = customer.Country; } int orderID = _NorthwindDAL.AddOrder(order).Value; for (int i = 0; i < cart.Count; i++) { OrderDetail orderDetail = new OrderDetail(); // orderDetail.Discount = 0; orderDetail.OrderID = orderID; orderDetail.ProductID = cart[i].Product.Id; orderDetail.Quantity = cart[i].Quantity; orderDetail.UnitPrice = cart[i].Product.Price; _NorthwindDAL.AddOrderDetail(orderDetail); } CartReceiptViewModel receipt = new CartReceiptViewModel { OrderID = orderID, OrderDate = orderDate }; //clear cart CartDAL.SetCart(HttpContext.Session, null); return(View(receipt)); }
private int isExist(int id) { List <CartItem> cart = CartDAL.GetCart(HttpContext.Session); for (int i = 0; i < cart.Count; i++) { if (cart[i].Product.Id.Equals(id)) { return(i); } } return(-1); }
public Boolean Delete(SqlInt32 CartID, SqlInt32 UserID) { CartDAL dalCart = new CartDAL(); if (dalCart.Delete(CartID, UserID)) { return(true); } else { Message = dalCart.Message; return(false); } }
public Boolean Update(CartENT entCart, SqlInt32 CartID, SqlInt32 UserID) { CartDAL dalCart = new CartDAL(); if (dalCart.Update(entCart, CartID, UserID)) { return(true); } else { Message = dalCart.Message; return(false); } }
public Boolean Insert(CartENT entCart) { CartDAL dalCart = new CartDAL(); if (dalCart.Insert(entCart)) { return(true); } else { Message = dalCart.Message; return(false); } }
protected void Page_Load(object sender, EventArgs e) { //if ( CustomerSession.strCustomerID == null) string strSiteCode = string.Empty; string strCustomerID = string.Empty; if (Session["strCustomerID"] != null) { strCustomerID = Session["strCustomerID"].ToString(); strSiteCode = CustomerSession.strSiteCode; string strProductID = string.Empty; if (null == Request.QueryString["id"]) { return; } CartDAL dal = new CartDAL(); strProductID = Common.Common.NoHtml(Request.QueryString["id"].ToString()); DataSet dsMyProduct = dal.GetMyCartProduct(strSiteCode, strCustomerID, strProductID); if (null != dsMyProduct && dsMyProduct.Tables.Count > 0 && dsMyProduct.Tables[0].Rows.Count > 0) { Response.Redirect("MyCart.aspx?SiteCode=" + CustomerSession.strSiteCode + "&CustomerID=" + CustomerSession.strCustomerID, false); return; } ProductDAL dalProduct = new ProductDAL(); DataSet ds = dalProduct.GetProductDetail(strProductID); decimal dUintCost = decimal.Parse(ds.Tables[0].Rows[0]["MemberPrice"].ToString()); SP_ShoppingCart modelAdd = new SP_ShoppingCart() { ID = Guid.NewGuid().ToString("N").ToUpper(), CustomerID = CustomerSession.strCustomerID, ProductID = strProductID, UnitCost = dUintCost, Quantity = 1, OrderTime = DateTime.Now, SiteCode = GlobalSession.strSiteCode }; if (dal.AddCartData(modelAdd)) { Response.Redirect("MyCart.aspx?SiteCode=" + CustomerSession.strSiteCode + "&CustomerID=" + CustomerSession.strCustomerID, false); } } else { Response.Redirect("Login.aspx?SiteCode='" + strSiteCode + "'", false); } }
public static int AddBookToCart(CartModel cart, BookOrderModel book) { int bookcount = CartDAL.SelectBookCountInCart(cart, book); if (bookcount > 0) { book.quantity += CartDAL.SelectBookQuantityInCart(cart, book); if (book.quantity > 99) { book.quantity = 99; } return(CartDAL.UpdateBookInCart(cart, book)); } else { return(CartDAL.InsertBookToCart(cart, book)); } }
public static CartModel GetUserCart(int userid) { CartModel cart = new CartModel(); cart.user = UserInfoBLL.GetUserInfoByID(userid); var reader = CartDAL.SelectBooksInCart(userid); while (reader.Read()) { BookOrderModel book = new BookOrderModel(); book.book = BookStatBLL.GetBookByID(reader.GetInt32(0)); book.enabled = 1; book.quantity = reader.GetInt32(1); cart.book.Add(book); } reader.Close(); return(cart); }
/// <summary> /// 指定商铺下的所有商品 /// </summary> /// <returns></returns> public ApiMessage <List <StoreGood> > GetAllGood(string userId, BaseParm parm) { var res = _dal.GetAllGood(parm); if (!string.IsNullOrEmpty(userId)) { var cartList = new CartDAL().List(userId); res.Data.ForEach(n => { var node = cartList.Data.FirstOrDefault(m => n.ID == m.ProductID); if (node != null) { n.SelectAmount = node.Amount; } }); } return(res); }
protected void Page_Load(object sender, EventArgs e) { if (null == Request.QueryString["id"]) { return; } strID = Common.Common.NoHtml(Request.QueryString["id"].ToString()); CartDAL dal = new CartDAL(); DataSet ds = dal.GetMyCartProduct(strID); if (null != ds && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { strSiteCode = ds.Tables[0].Rows[0]["SiteCode"].ToString(); strCustomerID = ds.Tables[0].Rows[0]["CustomerID"].ToString(); dal.DelMyCartProduct(strID); Response.Redirect("MyCart.aspx?SiteCode=" + strSiteCode + "&CustomerID=" + strCustomerID, false); } }
protected void Page_Load(object sender, EventArgs e) { string strProductID = Common.Common.NoHtml(Request.QueryString["productid"].ToString()); string strFlag = Common.Common.NoHtml(Request.QueryString["jj"].ToString()); string strRuturn = string.Empty; CartDAL dal = new CartDAL(); if (strFlag == "0") { strRuturn = dal.UpdateCatList(CustomerSession.strSiteCode, CustomerSession.strCustomerID, strProductID, "-"); } else { strRuturn = dal.UpdateCatList(CustomerSession.strSiteCode, CustomerSession.strCustomerID, strProductID, "+"); } //返回说明 当前修改商品的数量|总种数|总金额|总件数 //Response.Write("4|3|5|600"); Response.Write(strRuturn); }
/// <summary> /// Insere um item ao carrinho /// </summary> /// <param name="cart"></param> public void Inserir(Cart cart) { CartDAL dal = new CartDAL(); dal.Inserir(cart); }
public CartENT SelectByPK(SqlInt32 CartID, SqlInt32 UserID) { CartDAL dalCart = new CartDAL(); return(dalCart.SelectByPK(CartID, UserID)); }
public DataTable SelectALL(SqlInt32 UserID) { CartDAL dalCart = new CartDAL(); return(dalCart.SelectALL(UserID)); }
protected void Page_Load(object sender, EventArgs e) { string strSiteCode = string.Empty; string strCustomerID = string.Empty; if (null != Request.QueryString["SiteCode"]) { strSiteCode = Common.Common.NoHtml(Request.QueryString["SiteCode"].ToString()); Session["strSiteCode"] = strSiteCode; } if (null == Request.QueryString["CustomerID"]) { if (null == Session["strCustomerID"]) { Response.Redirect("Login.aspx?SiteCode=" + Session["strSiteCode"].ToString(), false); return; } else { strCustomerID = Session["strCustomerID"].ToString(); } } List <SP_Order> liOrder = new List <SP_Order>(); CartDAL dal = new CartDAL(); DataSet ds = dal.GetMyOrderList(strSiteCode, strCustomerID); foreach (DataRow row in ds.Tables[0].Rows) { SP_Order model = DataConvert.DataRowToModel <SP_Order>(row); liOrder.Add(model); } //读取模板内容 string text = System.IO.File.ReadAllText(Server.MapPath("Themes/Default/MyOrder.html")); JinianNet.JNTemplate.TemplateContext context = new JinianNet.JNTemplate.TemplateContext(); context.TempData["title"] = "我的订单"; if (null == Session["strName"]) { context.TempData["username"] = "******"; } else { context.TempData["username"] = CustomerSession.strName; } context.TempData["stiecode"] = strSiteCode; context.TempData["customerid"] = strCustomerID; if (null == Session["strName"]) { context.TempData["username"] = "******"; } else { context.TempData["username"] = CustomerSession.strName; } context.TempData["order_list"] = liOrder; context.TempData["footer"] = "奥琦微商易"; JinianNet.JNTemplate.Template t = new JinianNet.JNTemplate.Template(context, text); t.Render(Response.Output); }
public static int DeleteBook(int userid, int bookid) { return(CartDAL.UpdateBookEnabledInCart(userid, bookid)); }