Example #1
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usc = new Logic.ShoppingCartActions())
            {
                String cartId = usc.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ObjectId = rowValues["CatalogObject.ObjectId"].ToString();

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("RemoveItem");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("txtServiceQty");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }

                usc.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotalText.Text = string.Format("{0:c}", usc.GetTotal());
                return(usc.GetCartItems());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string inCatalogObjectId = Request.QueryString["ObjectId"];

            if (!String.IsNullOrEmpty(inCatalogObjectId))
            {
                ShoppingCartActions shoppingCart = new Logic.ShoppingCartActions();
                shoppingCart.AddToCart(inCatalogObjectId);
            }
            else
            {
                throw new Exception("No Catalog Item Received.");
            }

            Response.Redirect("ShoppingCart.aspx");
        }
Example #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (ShoppingCartActions usc = new Logic.ShoppingCartActions())
     {
         decimal cartTotal = 0;
         cartTotal = usc.GetTotal();
         if (cartTotal > 0)
         {
             // Display Total.
             lblTotalText.Text = string.Format("{0:c}", cartTotal);
         }
         else
         {
             lblTotalText.Text = "";
             lblTotal.Text     = "";
             CatalogServiceOrders.InnerText = "Currently no orders";
             UpdateBtn.Visible        = false;
             CheckoutImageBtn.Visible = false;
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVPAPICaller payPalCaller = new NVPAPICaller();

                string   retMsg  = "";
                string   token   = "";
                string   PayerID = "";
                NVPCodec decoder = new NVPCodec();
                token = Session["token"].ToString();

                bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    Session["payerId"] = PayerID;

                    var myOrder = new Order();
                    myOrder.OrderDate  = Convert.ToDateTime(decoder["TIMESTAMP"].ToString());
                    myOrder.Username   = User.Identity.Name;
                    myOrder.FirstName  = decoder["FIRSTNAME"].ToString();
                    myOrder.LastName   = decoder["LASTNAME"].ToString();
                    myOrder.Address    = decoder["SHIPTOSTREET"].ToString();
                    myOrder.City       = decoder["SHIPTOCITY"].ToString();
                    myOrder.State      = decoder["SHIPTOSTATE"].ToString();
                    myOrder.PostalCode = decoder["SHIPTOZIP"].ToString();
                    myOrder.Country    = decoder["SHIPTOCOUNTRYCODE"].ToString();
                    myOrder.Email      = decoder["EMAIL"].ToString();
                    myOrder.Total      = Convert.ToDecimal(decoder["AMT"].ToString());

                    // Verify total payment amount as set on CheckoutStart.aspx.
                    try
                    {
                        decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString());
                        decimal paymentAmoutFromPayPal  = Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    // Get DB context.
                    CatalogObjectContext _db = new CatalogObjectContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    try
                    {
                        _db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }

                    // Get the shopping cart items and process them.
                    using (CatalogiaWebForms.Logic.ShoppingCartActions usersShoppingCart = new CatalogiaWebForms.Logic.ShoppingCartActions())
                    {
                        List <CartItem> orders = usersShoppingCart.GetCartItems();

                        // Add OrderDetail information to the DB for each catalog item ordered.
                        for (int i = 0; i < orders.Count; i++)
                        {
                            // Create a new OrderDetail object.
                            var currentDetail = new OrderDetail();
                            currentDetail.OrderId   = myOrder.OrderId;
                            currentDetail.Username  = User.Identity.Name;
                            currentDetail.ObjectId  = orders[i].CatalogObject.ObjectId;
                            currentDetail.Quantity  = orders[i].Quantity;
                            currentDetail.UnitPrice = orders[i].CatalogObject.Price;

                            // Add OrderDetail to DB.
                            _db.OrderDetails.Add(currentDetail);
                            _db.SaveChanges();
                        }

                        // Set OrderId.
                        Session["currentOrderId"] = myOrder.OrderId;

                        // Display Order information.
                        List <Order> orderList = new List <Order>();
                        orderList.Add(myOrder);
                        ShipInfo.DataSource = orderList;
                        ShipInfo.DataBind();

                        // Display OrderDetails.
                        OrderItemList.DataSource = orders;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }