Exemple #1
0
        public void RefreshCart()
        {
            string cartID = String.Empty;

            if (CartSession != null && CartSession.Count > 0)
            {
                cartID = CartSession.First().Id;
            }
            List <SHOPPING_CART> carts = ApplicationContext.Current.Carts.GetShoppingCartItems(cartID);

            decimal total = 0;
            int     i     = 0;

            CartSession = new List <SessionCart>();
            if (carts != null)
            {
                foreach (SHOPPING_CART cart in carts)
                {
                    total += cart.Amount.Value;
                    i     += cart.Quantity;
                    SessionCart sC = new SessionCart(cart);
                    CartSession.Add(sC);
                }
            }
            TotalAmount = total;
        }
Exemple #2
0
        void Page_Init(object sender, EventArgs e)
        {
            //Stopping the one-click attack
            // force the session to exist, so the session id doesn't change with every request
            if (Session.IsNewSession)
            {
                Session["ForceSession"] = DateTime.Now;
            }
            // 'sign' the viewstate with the current session
            ViewStateUserKey = Session.SessionID;


            if (Page.EnableViewState)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["__VIEWSTATE"]))
                {
                    throw new Exception("Viewstate on query string detected!");
                }
            }

            if (String.IsNullOrEmpty(Request.Form["__VIEWSTATE"]) && Page.IsPostBack)
            {
                throw new Exception("Viewstate did not exist on the form!");
            }

            // session terminated, redirect to login
            try
            {
                if (CurrentCustomer == null)
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        FormsAuthentication.SignOut();
                        Response.Redirect(Request.RawUrl);

                        if (CartSession != null && CartSession.Count > 0)
                        {
                            ApplicationContext.Current.Carts.DeleteShoppingCart(CartSession.First().Id);
                        }

                        CartSession = null;
                        Session.Abandon();
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Log(ex, ex.Message, ex.StackTrace, "BasePage.Pre_Init");
                FormsAuthentication.SignOut();
                Response.Redirect(Request.RawUrl);

                Session.Abandon();
            }
        }
Exemple #3
0
        protected void rptDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandSource is LinkButton)
            {
                LinkButton lnk = e.CommandSource as LinkButton;
                if (!String.IsNullOrWhiteSpace(lnk.CommandArgument))
                {
                    int prodAttrID;
                    if (Int32.TryParse(lnk.CommandArgument, out prodAttrID))
                    {
                        if (lnk.ID == "lnkEdit")
                        {
                            RepeaterItem item = (RepeaterItem)lnk.NamingContainer;

                            DropDownList ddlQty = (DropDownList)item.FindControl("ddlQty");
                            ddlQty.Visible = true;
                            lnk.Visible    = false;

                            List <int>        qtyList;
                            PRODUCT_ATTRIBUTE prodAttr = ApplicationContext.Current.Products.GetProductAvailability(prodAttrID, out qtyList, Int32.Parse(lnk.Text));

                            // updating version
                            SessionCart cart = CartSession.Find(c => c.ProductAttributeId == prodAttrID);
                            cart.ProductAttributeVersion = prodAttr.Version;
                            ddlQty.DataSource            = qtyList;
                            ddlQty.DataBind();
                            ddlQty.SelectedValue = lnk.Text;
                        }
                        else if (lnk.ID == "lnkRemove")
                        {
                            ApplicationContext.Current.Carts.DeleteById(CartSession.First().Id, prodAttrID);
                            DataBind();
                        }
                        if (CartSession == null || CartSession.Count == 0)
                        {
                            lblMessage.Text    = Resources.Lang.EmptyCartLabel;
                            rptDetails.Visible = false;
                        }
                        else
                        {
                            lblMessage.Text = String.Empty;
                        }
                    }
                }
            }
        }
 protected void lnkCancel_Click(object sender, EventArgs e)
 {
     try
     {
         if (CartSession != null && CartSession.Count > 0)
         {
             ApplicationContext.Current.Carts.DeleteShoppingCart(CartSession.First().Id);
         }
         CartSession = null;
         Response.Redirect("/home/");
     }
     catch (System.Threading.ThreadAbortException ex)
     {
     }
     catch (Exception ex)
     {
         Log(ex, ex.Message, ex.StackTrace, "Checkout - Cancel");
     }
 }
        private void prepareEasyPayForm()
        {
            Session["AddrForEasyPay"]  = address1.AddrID;
            Session["BonForEasyPay"]   = BonusUsed;
            Session["BonIdForEasyPay"] = ddlBonus.SelectedValue;

            CultureInfo         culture       = new CultureInfo("en-US");
            NameValueCollection paypalCreator = new NameValueCollection();

            paypalCreator.Add("Orderid", CartSession.First().Id);
            paypalCreator.Add("Mer_refno", Configuration.EasyPayMerchantRef);
            paypalCreator.Add("Mer_username", Configuration.EasyPayMerchantUser);

            decimal rate   = ApplicationContext.Current.Payments.GetLastConversionRate().CurrencyRate + Configuration.CurrencyDelta;
            decimal amount = (decimal)rate * TotalOrder;

            paypalCreator.Add("Amount", amount.ToString("N2", culture));

            RedirectAndPOST(this, paypalCreator, Configuration.EasyPayEnv);

            lblModalMessage.Text = Resources.Lang.PassingToEasypayLabel;
            btnModalOk.Visible   = false;
            modalPopup.Show();
        }
        private void preparePayPalForm()
        {
            CultureInfo         culture       = new CultureInfo("en-US");
            NameValueCollection paypalCreator = new NameValueCollection();

            paypalCreator.Add("cmd", "_cart");
            paypalCreator.Add("upload", "1");
            paypalCreator.Add("return", Configuration.PaypalReturnUrl);
            //paypalCreator.Add("notify_url", Configuration.PaypalNotifyUrl);
            paypalCreator.Add("cancel_return", Configuration.PaypalCancelUrl);
            paypalCreator.Add("business", Configuration.PaypalSellerEmail);
            paypalCreator.Add("currency_code", Configuration.PaypalCurrency);
            paypalCreator.Add("discount_amount_cart", BonusUsed.ToString("N2", culture));
            paypalCreator.Add("invoice", CartSession.First().Id);
            if (BonusUsed > 0)
            {
                paypalCreator.Add("custom", address1.AddrID.ToString() + "-" + ddlBonus.SelectedValue + "-" + BonusUsed.ToString("N2", culture));
            }
            else
            {
                paypalCreator.Add("custom", address1.AddrID.ToString());
            }
            for (int i = 1; i <= CartSession.Count; i++)
            {
                paypalCreator.Add("item_number_" + i, CartSession.ElementAt(i - 1).ProductAttributeId.ToString());
                paypalCreator.Add("item_name_" + i, CartSession.ElementAt(i - 1).FullName);

                paypalCreator.Add("amount_" + i, CartSession.ElementAt(i - 1).Price.ToString("N2", culture));
                paypalCreator.Add("quantity_" + i, CartSession.ElementAt(i - 1).Quantity.ToString());
            }

            RedirectAndPOST(this, paypalCreator, Configuration.PaypalEnv);
            lblModalMessage.Text = Resources.Lang.PassingToPaypalLabel;
            btnModalOk.Visible   = false;
            modalPopup.Show();
        }
Exemple #7
0
        protected void lnkAddToBasket_Click(object sender, EventArgs e)
        {
            string CartID = String.Empty;

            Guid g = Guid.NewGuid();
            UniqueIdGenerator unique = UniqueIdGenerator.GetInstance();
            string            cartId = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower();

            if (CartSession == null || CartSession.Count == 0)
            {
                CartID      = cartId;
                CartSession = new List <SessionCart>();
            }
            else
            {
                List <SessionCart> cSession    = CartSession.OrderByDescending(c => c.DateAdded).ToList();
                SessionCart        sessionCart = cSession.First();
                if (sessionCart.DateAdded.AddMinutes(Configuration.CartExpirationValue) < DateTime.Now)
                {
                    RefreshCart();
                    CartID = cartId;
                }
                else
                {
                    CartID = CartSession.First().Id;
                }
            }

            SHOPPING_CART cart = new SHOPPING_CART();

            cart.ID         = CartID;
            cart.FrontEnd   = true;
            cart.CampaignID = CampaignID;
            cart.CustomerID = CurrentCustomer.Id;
            cart.DateAdded  = DateTime.Now;
            cart.ProductID  = ProductID;
            int num = 0;

            if (!Int32.TryParse(ddlSize.SelectedValue, out num))
            {
                return;
            }
            cart.ProdAttrID = num;

            num = 0;
            if (!Int32.TryParse(ddlQuantity.SelectedValue, out num) || num == 0)
            {
                return;
            }
            cart.Quantity = num;



            // the versions list of lists is created each time the product popup is shown, and destroyed each time it is closed
            if (Version != null)
            {
                cart.ProductAttributeVersion = Version;
            }
            else
            {
                throw new ApplicationException("Session is compromised! Cannot proceed.");
            }

            SessionCart sC;

            try
            {
                // already in the cart
                if (CartSession != null && CartSession.Count > 0 && (sC = CartSession.Find(c => c.ProductAttributeId == cart.ProdAttrID)) != null)
                {
                    // sum with old quantity
                    cart.Quantity += sC.Quantity;
                    ApplicationContext.Current.Carts.Update(cart, sC.Quantity);

                    // updating session with last quantity and last prod-attr version
                    sC.Quantity = cart.Quantity;
                    sC.ProductAttributeVersion = cart.ProductAttributeVersion;
                }
                else
                {
                    ApplicationContext.Current.Carts.Insert(cart);
                    sC = new SessionCart(cart);
                    CartSession.Add(sC);
                }
                TotalAmount = ApplicationContext.Current.Carts.GetShoppingCartTotalAmount(CartID);
            }
            catch (Exception ex)
            {
                //TODO log error
                Log(ex, ex.Message, ex.StackTrace, "Product.AddToCart");

                List <int>        qtyList;
                PRODUCT_ATTRIBUTE prodAttr = ApplicationContext.Current.Products.GetProductAvailability(cart.ProdAttrID, out qtyList);

                Version = prodAttr.Version;

                ddlQuantity.DataSource = qtyList;
                ddlQuantity.DataBind();
                if (!qtyList.Contains(cart.Quantity))
                {
                    lblMessage.Text = Resources.Lang.InsufficientAvailabilityMessage;
                }
                if (qtyList.Count == 0)
                {
                    ddlQuantity.Enabled    = false;
                    lnkAddToBasket.Enabled = false;
                    loadProductAttributes();
                }
                //refreshing the size ddl
                loadProductAttributes();
                updPanelDDL.Update();
                return;
            }


            Version = null;
            Response.Redirect("/cart/mycart/");
        }
Exemple #8
0
        public void DataBind()
        {
            List <SHOPPING_CART> carts = ApplicationContext.Current.Carts.GetShoppingCartItems(CartSession.First().Id);

            decimal total = 0;
            int     i     = 0;

            CartSession = new List <SessionCart>();
            if (carts != null)
            {
                foreach (SHOPPING_CART cart in carts)
                {
                    total += cart.Amount.Value;
                    i     += cart.Quantity;
                    SessionCart sC = new SessionCart(cart);
                    CartSession.Add(sC);
                }
            }
            TotalAmount           = total;
            rptDetails.DataSource = carts;
            rptDetails.DataBind();

            ((Secure.cart.mycart)Page).RefreshCartNumber();

            if (NeedRefresh != null)
            {
                NeedRefresh(null, null);
            }
        }
        private void saveOrder()
        {
            ORDERS order = new ORDERS();

            order.TotalAmount = TotalAmount.Value + ShipCost;

            order.BonusUsed  = 0;
            order.AmountPaid = TotalOrder;
            order.Verified   = false;

            order.Canceled  = false;
            order.Completed = false;

            order.Status = 1;

            string paymentType = String.Empty;

            int i;

            try
            {
                order.CustomerID = CurrentCustomer.Id;
                if (Int32.TryParse(selectedPayment.Value, out i))
                {
                    if (i == 3 || i == 4)
                    {
                        order.PAYMENT = new PAYMENT()
                        {
                            Type = (int)PaymentType.CA
                        };
                        order.PAYMENT.CASH_PAYMENT = new CASH_PAYMENT()
                        {
                            Amount = TotalOrder
                        };
                        if (i == 3)
                        {
                            order.PAYMENT.CASH_PAYMENT.Comments = txtCashComments.Text;
                            order.PAYMENT.CASH_PAYMENT.Receiver = "Korrier";
                            //TODO paid date
                            order.ShippingID = 3;
                            paymentType      = "Korrier";
                        }
                        else
                        {
                            order.PAYMENT.CASH_PAYMENT.Receiver = "Zyra";
                            order.ShippingID = 1;
                            paymentType      = "Zyra";
                        }
                    }
                }
                if ((ddlShippingAddress.SelectedValue == "0" || ddlShippingAddress.Items.Count == 0) && i == 3)
                {
                    writeResult(Resources.Lang.SpecifyShippingAddress);
                    radioBtnCarrier.Checked = true;
                    divConfirmLink.Visible  = true;
                    return;
                }
                // setting used bonuses in the order object
                setBonus(order);
                order.DateCreated = DateTime.Now;

                if (i == 3)
                {
                    // addresses
                    ADDRESSINFO shipping = new ADDRESSINFO(address1.GetAddress());
                    //ADDRESSINFO billing = new ADDRESSINFO(address2.GetAddress());
                    order.ADDRESSINFO = shipping;
                    //order.ADDRESSINFO1 = billing;
                }

                //inserting and not saving if there are any details, as the saving will be done in the details insertion
                ApplicationContext.Current.Orders.Insert(order, true, false);

                // inserting the products of this order
                List <SHOPPING_CART> carts = ApplicationContext.Current.Carts.GetShoppingCartItems(CartSession.First().Id);

                ApplicationContext.Current.Orders.InsertDetailsFromCart(order, carts, false);

                List <ORDER_DETAIL> details = ApplicationContext.Current.Orders.GetDetails(order.ID);

                Thread thread = new Thread(() => sendOrderMailToAdmins(details, paymentType, txtCashComments.Text, TotalOrder, CurrentCustomer.FullName));
                thread.Start();

                CUSTOMER customer = ApplicationContext.Current.Customers.GetByEmail(User.Identity.Name);

                Thread thread2 = new Thread(() => sendOrderMailToCustomer(customer, details, "Porosia ne FZone.al"));
                thread2.Start();

                CartSession = null;

                Response.Redirect("/personal/orderDet/" + FashionZone.BL.Util.Encryption.Encrypt(order.ID.ToString()));
            }
            catch (System.Threading.ThreadAbortException ex)
            {
            }
            catch (Exception e)
            {
                //TODO log exception
                Log(e, e.Message, e.StackTrace, "Checkout.Save");
                writeResult(Resources.Lang.ErrorVerifiedLabel);
            }
        }
        private void DataBind()
        {
            rptDetails.DataSource = ApplicationContext.Current.Carts.GetShoppingCartItems(CartSession.First().Id);
            rptDetails.DataBind();


            loadCustomerBonus();

            //List<SHIPPING> shippings = ApplicationContext.Current.Orders.GetShippings();
            //ddlShipping.DataSource = shippings;
            //if (shippings != null && shippings.Count > 0)
            //{
            //    ShipCost = shippings.ElementAt(0).ShippingCost;
            //}

            //ddlShipping.DataBind();
        }