private void ADDToCart(string productId) { if (Session["User"] != null) { if (Session["CartId"] == null) { CartCollection carts = new CartCollection(); Cart newcart = new Cart(); Session["CartId"] = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); ProductCollection temp = new ProductCollection(); temp.ReadList(Cruder.Core.Criteria.NewCriteria(Product.Columns.ProductId, Cruder.Core.CriteriaOperators.Equal, productId)); newcart.ProductId = temp[0].ProductId; newcart.Cost = temp[0].Price; newcart.Date = DateTime.Now.ToString(); newcart.CartId = Session["CartId"].ToString(); newcart.UserId = currentmember.UserId; newcart.Quantity = 1; carts.Add(newcart); Session["Cart"] = carts; } else { CartCollection carts = (CartCollection)Session["Cart"]; Cart newcart = new Cart(); ProductCollection temp = new ProductCollection(); temp.ReadList(Cruder.Core.Criteria.NewCriteria(Product.Columns.ProductId, Cruder.Core.CriteriaOperators.Equal, productId)); //carts.ReadList(Cruder.Core.Criteria.NewCriteria(Cart.Columns.ProductId, Cruder.Core.CriteriaOperators.Equal, // temp[0].ProductId) & Cruder.Core.Criteria.NewCriteria(Cart.Columns.CartId, // Cruder.Core.CriteriaOperators.Like, Session["CartId"].ToString())); //if (carts.Count != 0) //{ // carts[0].Quantity += 1; // carts.UpdateList(true); //} //else //{ newcart.ProductId = temp[0].ProductId; newcart.Cost = temp[0].Price; newcart.Date = DateTime.Now.ToString(); newcart.CartId = Session["CartId"].ToString(); newcart.UserId = currentmember.UserId; newcart.Quantity = 1; carts.Add(newcart); //} Session["Cart"] = carts; } } else { //Session["URLReferer"] = "Default.aspx"; Response.Redirect("Login.aspx"); } }
private void ADDToCart(string productId) { if (Session["User"] != null) { if (Session["CartId"] == null) { CartCollection carts = new CartCollection(); Cart newcart = new Cart(); Session["CartId"] = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString(); ProductCollection temp = new ProductCollection(); temp.ReadList(Cruder.Core.Criteria.NewCriteria(Product.Columns.ProductId, Cruder.Core.CriteriaOperators.Equal, productId)); newcart.ProductId = temp[0].ProductId; newcart.Cost = temp[0].Price; newcart.Date = DateTime.Now.ToString(); newcart.CartId = Session["CartId"].ToString(); newcart.UserId = currentmember.UserId; newcart.Quantity = 1; carts.Add(newcart); Session["Cart"] = carts; } else { CartCollection carts = (CartCollection)Session["Cart"]; Cart newcart = new Cart(); ProductCollection temp = new ProductCollection(); temp.ReadList(Cruder.Core.Criteria.NewCriteria(Product.Columns.ProductId, Cruder.Core.CriteriaOperators.Equal, productId)); newcart.ProductId = temp[0].ProductId; newcart.Cost = temp[0].Price; newcart.Date = DateTime.Now.ToString(); newcart.CartId = Session["CartId"].ToString(); newcart.UserId = currentmember.UserId; newcart.Quantity = 1; carts.Add(newcart); Session["Cart"] = carts; } } else { Response.Redirect("Login.aspx"); } }