Пример #1
0
        public static void CookiesImportDataBase(int userID, string userName)
        {
            List <CartInfo>       list        = CartHelper.ReadCart();
            Dictionary <int, int> dictionary  = new Dictionary <int, int>();
            Dictionary <int, int> dictionary2 = new Dictionary <int, int>();

            foreach (CartInfo info in list)
            {
                bool flag = false;
                if (info.GiftPackID > 0)
                {
                    flag = true;
                }
                else if (((info.FatherID == 0) && !IsProductInCart(info.ProductID, info.ProductName, userID)) || ((info.FatherID > 0) && dictionary.ContainsKey(info.FatherID)))
                {
                    flag = true;
                    dictionary.Add(info.ID, 1);
                }
                if (flag)
                {
                    if (info.FatherID > 0)
                    {
                        info.FatherID = dictionary2[info.FatherID];
                    }
                    info.UserID   = userID;
                    info.UserName = userName;
                    int num = dal.AddCart(info);
                    dictionary2.Add(info.ID, num);
                }
            }
            CartHelper.ClearCart();
        }
Пример #2
0
        public void ClearShoppingCart()
        {
            Stopwatch watch = Stopwatch.StartNew();

            //Add new Item to the cart.
            Profile profile = null;

            using (var context = new PetShopDataContext())
            {
                profile = context.Profile.GetProfile(NAME);
                profile.Detach();
            }

            CartHelper.Add(profile.ShoppingCart, ID, profile.UniqueID, true);


            //Clear the cart.
            using (var context = new PetShopDataContext())
            {
                profile = context.Profile.GetProfile(NAME);
                profile.Detach();
            }

            CartHelper.ClearCart(profile.ShoppingCart);

            using (var context = new PetShopDataContext())
            {
                Assert.IsTrue(context.Profile.GetProfile(NAME).ShoppingCart.Count == 0);
            }

            Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
        }
Пример #3
0
 public static void ClearCart(int userID)
 {
     if (userID > 0)
     {
         dal.ClearCart(userID);
     }
     else
     {
         CartHelper.ClearCart();
     }
 }
Пример #4
0
 public static void Clear(int userId)
 {
     if (userId > 0)
     {
         dal.Clear(userId);
     }
     else
     {
         CartHelper.ClearCart();
     }
 }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            return;
        }
        try
        {
            CartHelper.ClearCart();
            var transactionResultNode = GetTransactionResult();
            if (GetTransactionResult() == null)
            {
                return;
            }
            ltrEsito.Text = "GetTransactionResult ok";
            var orderNumber = GetOrderNumber(transactionResultNode);
            if (orderNumber == null)
            {
                return;
            }

            var resultResponse = CheckTransactionResult(transactionResultNode);
            ltrEsito.Text += "GetTransactionResult ok";
            if (resultResponse == false)
            {
                ShowMessage(MessageType.Error, string.Format(_errorMsg, orderNumber));
                _repository.SetOrderStatus(int.Parse(orderNumber), OrderStatusType.Canceled);
                return;
            }

            // Recupera l'ordine relativo
            var orderDetails = _repository.GetOrderInfos(int.Parse(orderNumber));

            // recupera le info del customer che ha effettuato l'ordine
            var customer = _repository.GetCustomerById(int.Parse(orderDetails.customer_id));

            var mailBody = CreateMailLayout(customer, orderDetails, orderNumber);
            SendMailToUser(orderDetails, customer, orderNumber, mailBody);

            ShowMessage(MessageType.Success, string.Format(_successMsg, orderNumber));
            // Aggiorna qta prodotto
        }
        catch (Exception ex)
        {
            var stack = ex.StackTrace ?? ex.StackTrace.ToString();
            //var source = ex.InnerException.Source ?? ex.InnerException.Source.ToString();

            ltrEsito.Text += stack;
        }
    }
Пример #6
0
 /// <summary>
 /// 用户登录之后Cookies购物转入到数据库
 /// </summary>
 public static void CookiesImportDataBase(int userId, string userName)
 {
     foreach (CartInfo cart in CartHelper.ReadCart())
     {
         var dbCart = CartBLL.Read(cart.ProductId, cart.ProductName, userId);
         if (dbCart.Id < 1)
         {
             cart.UserId   = userId;
             cart.UserName = userName;
             dal.Add(cart);
         }
     }
     CartHelper.ClearCart();
 }
Пример #7
0
        /// <summary>
        /// Process the order
        /// </summary>
        protected void wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            using (var context = new PetShopDataContext())
            {
                var profile = context.Profile.GetProfile(User.Identity.Name);
                if (profile.ShoppingCart.Count > 0)
                {
                    // display ordered items
                    CartListOrdered.Bind(profile.ShoppingCart);

                    // display total and credit card information
                    ltlTotalComplete.Text      = ltlTotal.Text;
                    ltlCreditCardComplete.Text = ltlCreditCard.Text;

                    #region Create Order

                    var order = new Order();

                    order.UserId              = profile.UniqueID.ToString();
                    order.OrderDate           = DateTime.Now;
                    order.CreditCard          = GetCreditCard();
                    order.Courier             = order.CreditCard.CardType;
                    order.TotalPrice          = CartHelper.GetTotal(profile.ShoppingCart);
                    order.AuthorizationNumber = 0;
                    order.Locale              = "en-us";

                    #region Shipping Information

                    order.ShipAddr1       = billingForm.Address.Address1;
                    order.ShipAddr2       = billingForm.Address.Address2;
                    order.ShipCity        = billingForm.Address.City;
                    order.ShipState       = billingForm.Address.State;
                    order.ShipZip         = billingForm.Address.Zip;
                    order.ShipCountry     = billingForm.Address.Country;
                    order.ShipToFirstName = billingForm.Address.FirstName;
                    order.ShipToLastName  = billingForm.Address.LastName;

                    #endregion

                    #region Billing Information

                    order.BillAddr1       = shippingForm.Address.Address1;
                    order.BillAddr2       = shippingForm.Address.Address2;
                    order.BillCity        = shippingForm.Address.City;
                    order.BillState       = shippingForm.Address.State;
                    order.BillZip         = shippingForm.Address.Zip;
                    order.BillCountry     = shippingForm.Address.Country;
                    order.BillToFirstName = shippingForm.Address.FirstName;
                    order.BillToLastName  = shippingForm.Address.LastName;

                    #endregion
                    context.Order.InsertOnSubmit(order);
                    context.SubmitChanges();

                    #endregion

                    int itemsOnBackOrder = 0;
                    //Decrement and check the Inventory.
                    foreach (Cart cart in profile.ShoppingCart)
                    {
                        var inventory = context.Inventory.GetByKey(cart.ItemId);

                        if (cart.Quantity > inventory.Qty)
                        {
                            itemsOnBackOrder += cart.Quantity - inventory.Qty;
                        }

                        inventory.Qty -= cart.Quantity;
                        context.SubmitChanges();
                    }

                    if (itemsOnBackOrder > 0)
                    {
                        ItemsOnBackOrder.Text = string.Format("<br /><p style=\"color:red;\"><b>Backorder ALERT:</b> {0} items are on backorder.</p>", itemsOnBackOrder);
                    }

                    CartHelper.SaveOrderLineItems(profile.ShoppingCart, order.OrderId);

                    // destroy cart
                    CartHelper.ClearCart(profile.ShoppingCart);
                }
                else
                {
                    lblMsg.Text =
                        "<p><br>Can not process the order. Your cart is empty.</p><p class=SignUpLabel><a class=linkNewUser href=Default.aspx>Continue shopping</a></p>";
                    wzdCheckOut.Visible = false;
                }
            }
        }