Exemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
                {
                    string clientId = User.Identity.GetUserId();

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

                        Purchase newPurchase = new Purchase
                        {
                            CustomerId    = clientId,
                            ProductId     = productId,
                            Amount        = amount,
                            DatePurchased = DateTime.Now,
                            IsInCart      = true
                        };

                        PurchaseModel model = new PurchaseModel();
                        LabelResult.Text = model.AddPurchase(newPurchase);
                    }
                    else
                    {
                        Response.Redirect("~/Page/Account/login.aspx");
                    }
                }
            }
            catch (Exception)
            {
                LabelResult.Text      = "Purchase Fail";
                LabelResult.ForeColor = System.Drawing.Color.Red;
            }
        }