コード例 #1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
            {
                string clientId = Context.User.Identity.GetUserId();

                if (clientId != null)
                {
                    int id     = Convert.ToInt32(Request.QueryString["id"]);
                    int amount = Convert.ToInt32(ddlAmount.SelectedValue);

                    Cart cart = new Cart
                    {
                        Amount        = amount,
                        ClientID      = clientId,
                        DatePurchased = DateTime.Now,
                        IsInCart      = true,
                        ProductID     = id
                    };

                    Models.CartModel model = new Models.CartModel();
                    lblResult.Text = model.InsertCart(cart);
                }
                else
                {
                    lblResult.Text = "Please log in to order items.";
                }
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = Context.User.Identity;

            if (user.IsAuthenticated)
            {
                lnkLogin.Visible  = false;
                lnkLogout.Visible = true;

                Models.CartModel model  = new Models.CartModel();
                string           userId = HttpContext.Current.User.Identity.GetUserId();
                Literal1.Text = string.Format("({0})", model.GetAmountOfOrders(userId));
            }
            else
            {
                lnkLogin.Visible  = true;
                lnkLogout.Visible = false;
            }
        }