Пример #1
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.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].ProductId = Convert.ToInt32(rowValues["ProductID"]);

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

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
        public ActionResult AddItemQuantity()
        {
            string rawId = Request.QueryString["ProductId"];
            int    productId;

            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
                {
                    String cartId          = usersShoppingCart.GetCartId();
                    var    allItems        = usersShoppingCart.GetCartItems();
                    int    currentQuantity = 0;
                    foreach (var item in allItems)
                    {
                        if (Convert.ToInt16(rawId) == item.ProductId)
                        {
                            currentQuantity = item.Quantity;
                        }
                    }
                    currentQuantity += 1;
                    usersShoppingCart.UpdateItem(cartId, Convert.ToInt16(rawId), currentQuantity);
                }
            }
            else
            {
                Debug.Fail("ERROR : We should never get to /ShoppingCart/AddItemQuantity without a ProductId.");
                throw new Exception("ERROR : It is illegal to load /ShoppingCart/AddItemQuantity without setting a ProductId.");
            }
            return(RedirectToAction("Index"));
        }
Пример #3
0
        //update cart item with db
        private List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions shopaction = new ShoppingCartActions())
            {
                string cartId = shopaction.GetCartId().ToString();
                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];

                //collect item in cart to update list
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    CheckBox cbRm = CartList.Rows[i].FindControl("Remove") as CheckBox;
                    cartUpdates[i].RemoveItem = cbRm.Checked;

                    TextBox qnt = CartList.Rows[i].FindControl("PurchaseQuantity") as TextBox;
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(qnt.Text);
                }

                shopaction.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = string.Format("{0:c}", shopaction.GetTotal());
                return(shopaction.GetCartItems());
            }
        }
Пример #4
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);

                // Migrate the shopping cart, if necessary, after the user registers and logs in to the application during the checkout process
                using (var usersShoppingCart = new ShoppingCartActions()) {
                    string cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.MigrateCart(cartId, user.UserName);
                }

                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                List <ShoppingCartActions.ShoppingCartUpdates> cartUpdates = new List <ShoppingCartActions.ShoppingCartUpdates>();
                foreach (GridViewRow row in CartList.Rows)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(row);
                    var ControlCheckbox = (CheckBox)row.FindControl("Remove");
                    var TextBox         = (TextBox)row.FindControl("PurchaseQuantity");
                    ShoppingCartActions.ShoppingCartUpdates cartUpdate = new ShoppingCartActions.ShoppingCartUpdates
                    {
                        ProductId        = Convert.ToInt32(rowValues["ProductID"]),
                        RemoveItem       = ControlCheckbox.Checked,
                        PurchaseQuantity = Convert.ToInt16(TextBox.Text.ToString())
                    };
                    cartUpdates.Add(cartUpdate);
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Пример #6
0
        public List <CartItem> UpdateCartItems()
        {
            var cartManager = new Logic.CartManager();
            var cartId      = ShoppingCartActions.GetCartId();

            Domain.Models.ShoppingCartUpdates[] cartUpdates = new Domain.Models.ShoppingCartUpdates[CartList.Rows.Count];
            for (int i = 0; i < CartList.Rows.Count; i++)
            {
                IOrderedDictionary rowValues = new OrderedDictionary();
                rowValues = GetValues(CartList.Rows[i]);
                cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

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

                TextBox quantityTextBox = new TextBox();
                quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
            }
            cartManager.UpdateShoppingCartDatabase(cartId, cartUpdates);
            CartList.DataBind();
            lblTotal.Text = $"{cartManager.GetCartTotal(cartId):c}";
            return(cartManager.GetCartItems(cartId));
        }
Пример #7
0
        //UpdatecartItems Method
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    //The amount of products in the cart.
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);


                    //This the checkbox to tick to remove a product.
                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    //This is the textbox to change the quantity.
                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }

                //This updates the total for all prdoucts in the cart using the GetTotal method.
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Пример #8
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user    = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl  "\">here</a>.");

                IdentityHelper.SignIn(manager, user, isPersistent: false);

                var cartId   = ShoppingCartActions.GetCartId();
                var userCart = new Logic.CartManager();
                userCart.MigrateCart(cartId, user.Id);

                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
Пример #9
0
        public List <CartItem> UpdateRepeats()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.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].ProductId = Convert.ToInt32(rowValues["ProductID"]);

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

                    // DropDownList selectedRepeat = new DropDownList();
                    // selectedRepeat =
                    //(DropDownList)CartList.Rows[i].FindControl("Repeat");
                    // cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */

                    //DropDownList selectedRepeat = new DropDownList();
                    DropDownList selectedRepeat = (DropDownList)CartList.Rows[i].FindControl("RepeatOrder");
                    cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Пример #10
0
    public bool ShortcutExpressCheckout(string amt, ref string token, ref string retMsg)
    {
        if (bSandbox)
        {
            pEndPointURL = pEndPointURL_SB;
            host         = host_SB;
        }

        string returnURL = "https://localhost:44300/Checkout/CheckoutReview.aspx";
        string cancelURL = "https://localhost:44300/Checkout/CheckoutCancel.aspx";

        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"]                         = "SetExpressCheckout";
        encoder["RETURNURL"]                      = returnURL;
        encoder["CANCELURL"]                      = cancelURL;
        encoder["BRANDNAME"]                      = "Wingtip Toys Sample Application";
        encoder["PAYMENTREQUEST_0_AMT"]           = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"]       = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["PAYMENTREQUEST_0_CURRENCYCODE"]  = "USD";

        var cartId      = ShoppingCartActions.GetCartId();
        var cartManager = new CartManager();


        List <CartItem> myOrderList = cartManager.GetCartItems(cartId);

        for (int i = 0; i < myOrderList.Count; i++)
        {
            encoder["L_PAYMENTREQUEST_0_NAME" + i] = myOrderList[i].Product.ProductName.ToString();
            encoder["L_PAYMENTREQUEST_0_AMT" + i]  = myOrderList[i].Product.UnitPrice.ToString();
            encoder["L_PAYMENTREQUEST_0_QTY" + i]  = myOrderList[i].Quantity.ToString();
        }

        string pStrrequestforNvp = encoder.Encode();
        string pStresponsenvp    = HttpCall(pStrrequestforNvp);

        NVPCodec decoder = new NVPCodec();

        decoder.Decode(pStresponsenvp);

        string strAck = decoder["ACK"].ToLower();

        if (strAck != null && (strAck == "success" || strAck == "successwithwarning"))
        {
            token = decoder["TOKEN"];
            string ECURL = "https://" + host + "/cgi-bin/webscr?cmd=_express-checkout" + "&token=" + token;
            retMsg = ECURL;
            return(true);
        }
        else
        {
            retMsg = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                     "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                     "Desc2=" + decoder["L_LONGMESSAGE0"];
            return(false);
        }
    }
Пример #11
0
        public void MigrateShoppingCart(string Username)
        {
            ShoppingCartActions cart = new ShoppingCartActions();
            string _shoppingCartId   = cart.GetCartId();

            cart.MigrateCart(_shoppingCartId, Username);
            System.Web.HttpContext.Current.Session[ShoppingCartActions.cartSessionKey] = Username;
        }
Пример #12
0
        protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e)
        {
            var cartManager = new Logic.CartManager();
            var cartTotal   = cartManager.GetCartTotal(ShoppingCartActions.GetCartId());

            Session["payment_amt"] = cartTotal;

            Response.Redirect("Checkout/CheckoutStart.aspx");
        }
Пример #13
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var cartId    = ShoppingCartActions.GetCartId();
            var userCart  = new Logic.CartManager();
            var itemCount = userCart.GetCountOfItemsInCart(cartId);

            var cartStr = $"Cart ({itemCount}";

            cartCount.InnerText = cartStr;
        }
Пример #14
0
        protected void LogIn(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Validate the user password
                var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();
                var user          = manager.FindByEmail(Email.Text);
                // This doen't count login failures towards account lockout
                // To enable password failures to trigger lockout, change to shouldLockout: true
                if (user != null)
                {
                    if (!user.EmailConfirmed)
                    {
                        FailureText.Text      = "Invalid login attempt, you must have a confirmed email account. Enter email and pass and click 'Resend Confirmation'";
                        ResendConfirm.Visible = true;
                        ErrorMessage.Visible  = true;
                    }

                    else
                    {
                        var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);

                        switch (result)
                        {
                        case SignInStatus.Success:
                            ShoppingCartActions usersShoppingCart = new ShoppingCartActions();
                            String cartId = usersShoppingCart.GetCartId();
                            usersShoppingCart.MigrateCart(cartId, Email.Text);
                            IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                            break;

                        case SignInStatus.LockedOut:
                            Response.Redirect("/Account/Lockout");
                            break;

                        case SignInStatus.RequiresVerification:
                            Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                            Request.QueryString["ReturnUrl"],
                                                            RememberMe.Checked),
                                              true);
                            break;

                        case SignInStatus.Failure:
                        default:
                            FailureText.Text     = "Invalid login attempt";
                            ErrorMessage.Visible = true;
                            break;
                        }
                    }
                }
            }
        }
Пример #15
0
        public JsonResult CheckCart(int productid)
        {
            ShoppingCartActions cart = new ShoppingCartActions();
            string _shoppingCartId   = cart.GetCartId();
            int    returnValue       = 0;
            var    cartItems         = db.SHOPPINGCART.Where(p => p.ProductId == productid && p.CartId == _shoppingCartId).ToList();

            if (cartItems.Count > 0)
            {
                returnValue = 1;
            }
            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
Пример #16
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.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].LivroId = Convert.ToInt32(rowValues["livro_id"]);

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

                    int quantidadeAnterior = GetShoppingCartItems().Cast <CartItem>().ElementAt(i).quantidade;

                    Estoque estoque = commands["CONSULTAR"].execute(new Estoque()
                    {
                        Livro = new Dominio.Livro.Livro()
                        {
                            ID = cartUpdates[i].LivroId
                        }
                    }).Entidades.Cast <Estoque>().ElementAt(0);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");

                    if (estoque.Qtde < Convert.ToInt32(quantityTextBox.Text))
                    {
                        cartUpdates[i].PurchaseQuantity = quantidadeAnterior;
                        lblResultadoCarrinho.Text       = "Quantidade em estoque do livro " + estoque.Livro.Titulo + " é de " + estoque.Qtde + " unidade(s)";
                        lblResultadoCarrinho.Visible    = true;
                    }
                    else
                    {
                        cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                        lblResultadoCarrinho.Text       = "";
                        lblResultadoCarrinho.Visible    = false;
                    }
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblSubtotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Пример #17
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.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].ProductId
                }
            }
        }
Пример #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Verify user has completed the checkout process.
                if ((string)Session["userCheckoutCompleted"] != "true")
                {
                    Session["userCheckoutCompleted"] = string.Empty;
                    Response.Redirect("CheckoutError.aspx?" + "Desc=Unvalidated%20Checkout.");
                }

                NVPAPICaller payPalCaller = new NVPAPICaller();

                string   retMsg             = "";
                string   token              = "";
                string   finalPaymentAmount = "";
                string   PayerID            = "";
                NVPCodec decoder            = new NVPCodec();

                token              = Session["token"].ToString();
                PayerID            = Session["payerId"].ToString();
                finalPaymentAmount = Session["payment_amt"].ToString();

                bool ret = payPalCaller.DoCheckoutPayment(finalPaymentAmount, token, PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    // Retrieve PayPal confirmation value.
                    string PaymentConfirmation = decoder["PAYMENTINFO_0_TRANSACTIONID"].ToString();
                    TransactionId.Text = PaymentConfirmation;

                    var cartManager = new Logic.CartManager();
                    if (int.TryParse(Session["currentOrderID"].ToString(), out int orderId))
                    {
                        cartManager.UpdateOrderPaymentTransactionId(orderId, PaymentConfirmation);
                    }

                    // Empty the Cart
                    cartManager.EmptyCart(ShoppingCartActions.GetCartId());

                    // Clear order id.
                    Session["currentOrderId"] = string.Empty;
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Пример #19
0
        public List<cartitem> delteCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                for (int i = 0; i < usersShoppingCart.GetTotal(); i++)
                {
                   
                    usersShoppingCart.DeleteShoppingCartDatabase(cartId);
                }
               
               // lblTotal.Text = "0";
                return usersShoppingCart.GetCartItems();
            }
        }
Пример #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];

            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out var productId))
            {
                var cartId   = ShoppingCartActions.GetCartId();
                var userCart = new Logic.CartManager();
                userCart.AddToCart(cartId, productId);
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
            }
            Response.Redirect("ShoppingCart.aspx");
        }
Пример #21
0
        protected void LogIn(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Validate the user password
                var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();

                // This doen't count login failures towards account lockout
                // To enable password failures to trigger lockout, change to shouldLockout: true
                var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);

                switch (result)
                {
                case SignInStatus.Success:
                    // Migrate a cart the user may have created before logging into the application to checkout
                    using (var usersShoppingCart = new ShoppingCartActions()) {
                        string cartId = usersShoppingCart.GetCartId();
                        usersShoppingCart.MigrateCart(cartId, User.Identity.Name);
                    }

                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    break;

                case SignInStatus.LockedOut:
                    Response.Redirect("/Account/Lockout");
                    break;

                case SignInStatus.RequiresVerification:
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                    Request.QueryString["ReturnUrl"],
                                                    RememberMe.Checked),
                                      true);
                    break;

                case SignInStatus.Failure:
                default:
                    FailureText.Text     = "Invalid login attempt";
                    ErrorMessage.Visible = true;
                    break;
                }
            }
        }
Пример #22
0
        // GET: CartItems
        public async Task <IActionResult> Index()
        {
            var swimmingClubContext = _context.ShoppingCartItems.Include(c => c.Product);
            var user = await GetCurrentUserAsync();

            var usersShoppingCart = new ShoppingCartActions(_httpContextAccessor, _context);
            //var cartID = usersShoppingCart.GetCartId(this.User.FindFirstValue(ClaimTypes.NameIdentifier));
            var cartID = usersShoppingCart.GetCartId(null);


            var cart = await _context.ShoppingCartItems
                       .Include(pr => pr.Product)
                       .Where(i => i.CartId.Equals(cartID))
                       .AsNoTracking()
                       .ToListAsync();

            ViewData["CartTotal"] = cart.Sum(c => c.Quantity * c.Product.SellingPrice);
            return(View(cart));
        }
Пример #23
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.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].ProductId = Convert.ToInt32(rowValues["ProductID"]);

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

                    TextBox priceTextBox = new TextBox();
                    priceTextBox           = (TextBox)CartList.Rows[i].FindControl("PriceBx");
                    cartUpdates[i].PriceBx = Convert.ToDecimal(priceTextBox.Text.ToString());

                    //cartUpdates[i].ItemPrice = Convert.ToInt32(rowValues["OriginalPrice"]);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //GetTotal() suppose to execute after UpdateShoppingCartDatabase
                string x = String.Format("{0:c}", usersShoppingCart.GetTotal());
                if (x != "$0.00")
                {
                    lblTotal.Text = x;
                }
                else
                {
                    lblTotal.Text = "";
                }
                return(usersShoppingCart.GetCartItems());
            }
        }
Пример #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var cartManager = new Logic.CartManager();
            var cartId      = ShoppingCartActions.GetCartId();
            var cartTotal   = cartManager.GetCartTotal(cartId);

            if (cartTotal > 0)
            {
                // Display Total.
                lblTotal.Text = $"{cartTotal:c}";
            }
            else
            {
                LabelTotalText.Text         = "";
                lblTotal.Text               = "";
                ShoppingCartTitle.InnerText = "Shopping Cart is Empty";
                UpdateBtn.Visible           = false;
                CheckoutImageBtn.Visible    = false;
            }
        }
        public ActionResult RemoveItemFromCart()
        {
            string rawId = Request.QueryString["ProductId"];
            int    productsId;

            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productsId))
            {
                using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
                {
                    String cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.RemoveItem(cartId, Convert.ToInt16(rawId));
                }
            }
            else
            {
                Debug.Fail("ERROR : We should never get to /ShoppingCart/AddItemQuantity without a ProductId.");
                throw new Exception("ERROR : It is illegal to load /ShoppingCart/AddItemQuantity without setting a ProductId.");
            }
            return(RedirectToAction("Index"));
        }
Пример #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ShoppingCartActions actions = new ShoppingCartActions();

            this.CartId = actions.GetCartId();

            this.ShoppingCart_Object = new ShoppingCartObject(this.CartId);

            if (this.ShoppingCart_Object.sc_CartItemList.Count > 0)
            {
                lblTotal.Text = String.Format("{0:c}", ShoppingCart_Object.getTotal());
            }
            else
            {
                LabelTotalText.Text         = "";
                lblTotal.Text               = "";
                ShoppingCartTitle.InnerText = "Shopping Cart is Empty";
                UpdateBtn.Visible           = false;
                CheckoutImageBtn.Visible    = false;
            }
        }
        public List <EntityCartItem> GetEntityCartItems()
        {
            ShoppingCartActions actions = new ShoppingCartActions();
            String cartId = actions.GetCartId();

            //Call Cart Durable Entity Function API
            List <EntityCartItem> items = new List <EntityCartItem>();
            var response = client.GetAsync("http://localhost:7071/api/CartView?CartId=" + cartId).Result;

            if (response.IsSuccessStatusCode)
            {
                var        str  = response.Content.ReadAsStringAsync();
                EntityCart cart = JsonConvert.DeserializeObject <EntityCart>(str.Result);
                foreach (var item in cart.Items)
                {
                    items.Add(new EntityCartItem {
                        Id = item.Id, Price = item.Price
                    });
                }
            }

            return(items);
        }
Пример #28
0
        // GET: Products
        public async Task <IActionResult> Index()
        {
            var user = await GetCurrentUserAsync();

            var cartID = usersShoppingCart.GetCartId(this.User.FindFirstValue(ClaimTypes.NameIdentifier));
            //ViewData["CartCount"] = usersShoppingCart.GetCartItems().Count;
            List <Product> products = await _context.Products.ToListAsync();

            List <CartItem> cartItems = await _context.ShoppingCartItems
                                        .Where(i => i.CartId.Equals(cartID))
                                        .ToListAsync();

            var ProductsList = from p in products
                               join c in cartItems on p.ID equals c.ProductId into cp
                               from ProductCart in cp.DefaultIfEmpty()
                               select new { p.ID, p.ShortName, p.Description, p.SellingPrice, p.ImageFileName
                                            , Quantity = (ProductCart == null ? 0 : ProductCart.Quantity
                                                          ) };

            ViewData["CartCount"] = ProductsList.Sum(cart => cart.Quantity);

            return(View(products));
        }
Пример #29
0
        public List <CartItem> GetShoppingCartItems()
        {
            var cartManager = new Logic.CartManager();

            return(cartManager.GetCartItems(ShoppingCartActions.GetCartId()));
        }
Пример #30
0
        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 paymentAmourFromPayPal  = Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmourFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    var cartId      = ShoppingCartActions.GetCartId();
                    var cartManager = new Logic.CartManager();
                    var orderSaved  = cartManager.AddOrder(myOrder);

                    var cartItems = cartManager.GetCartItems(cartId);

                    // Get the shopping cart items and process them.


                    // Add OrderDetail information to the DB for each product purchased.
                    for (int i = 0; i < cartItems.Count; i++)
                    {
                        // Create a new OrderDetail object.
                        var myOrderDetail = new OrderDetail();
                        myOrderDetail.OrderId   = myOrder.OrderId;
                        myOrderDetail.Username  = User.Identity.Name;
                        myOrderDetail.ProductId = cartItems[i].ProductId;
                        myOrderDetail.Quantity  = cartItems[i].Quantity;
                        myOrderDetail.UnitPrice = cartItems[i].Product.UnitPrice;

                        var cartItemSaved = cartManager.SaveOrderDetail(myOrderDetail);
                    }

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

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

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