public void AddStuffToCartCount()
 {
     ShoppingCartActions cartActs = new ShoppingCartActions();
     cartActs.AddToCart(1);
     cartActs.AddToCart(2);
     Assert.AreEqual(2, cartActs.GetCount());
 }
        //method for updating quantities/removing items
        public List<CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions cart = new ShoppingCartActions())
            {
                string cartID = cart.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());
                }
                cart.UpdateShoppingCartDatabase(cartID, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", cart.GetTotal());
                return cart.GetCartItems();
            }
        }
 public void AddToCartCheck()
 {
     ShoppingCartActions cartActs = new ShoppingCartActions();
     cartActs.AddToCart(1);
     List<CartItem> itemsInCart = cartActs.GetCartItems();
     Assert.AreEqual(itemsInCart[0].ProductId, 1);
 }
 public ShoppingCartActions GetCart(HttpContext context)
 {
     using (var cart = new ShoppingCartActions())
     {
         cart.ShoppingCartId = cart.GetCartId();
         return cart;
     }
 }
        public void AddToCartTest()
        {
            int id = -1;
            ShoppingCartActions sca = new ShoppingCartActions();
            sca.ShoppingCartId = "1";
            sca.AddToCart(id);


            throw new NotImplementedException();
        }
        public void TestInitialize()
        {
            //ProductContext context = new ProductContext();
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""));
            var fakeIdentity = new GenericIdentity("User");
            var principal = new GenericPrincipal(fakeIdentity, null);

            HttpContext.Current = MockHelper.FakeHttpContext();
            HttpContext.Current.User = principal;

            Database.SetInitializer(new ProductDatabaseInitializer());

            ShoppingCartActions cartActs = new ShoppingCartActions();
            cartActs.EmptyCart();
        }
 protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e)
 {
     if (Convert.ToString(Session["tipchecked"]) == "true")
     {
        // Session["payment_amt"] = cartTotaltip;
         Response.Redirect("Checkout/CheckoutStart.aspx");
     }
     else
     {
         using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
         {
              Session["payment_amt"] = usersShoppingCart.GetTotal();
              //Session["payment_amt"] = cartTotal;
         }
     }
     Response.Redirect("Checkout/CheckoutStart.aspx");
 }
        public void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
                {
                    usersShoppingCart.AddToCart(Convert.ToInt16(rawId));
                }

            }
            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");
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
     {
         decimal cartTotal = 0;
         cartTotal = usersShoppingCart.GetTotal();
         if (cartTotal > 0)
         {
             lblTotal.Text = String.Format("{0:c}", cartTotal);
         }
         else
         {
             LabelTotalText.Text = "";
             lblTotal.Text = "";
             ShoppingCartTitle.InnerText = "No items added to order...Add some food!";
             UpdateButton.Visible = false;
         }
     }
 }
 public List<CartItem> GetShoppingCartItems()
 {
     ShoppingCartActions actions = new ShoppingCartActions();
     return actions.GetCartItems();
 }
 public void TotalCartPrice()
 {
     ShoppingCartActions cartActs = new ShoppingCartActions();
     cartActs.AddToCart(1);
     cartActs.AddToCart(2);
     cartActs.AddToCart(5);
     decimal expected = (decimal)(5 + 6.79 + 2.99);
     Assert.AreEqual(expected, cartActs.GetTotal());
 }
 public void NewCartStartsEmpty()
 {
     ShoppingCartActions cartActs = new ShoppingCartActions();
     Assert.AreEqual(0, cartActs.GetCount());
 }
        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;


                    ProductContext _db = new ProductContext();
                    // Get the current order id.
                    int currentOrderId = -1;
                    if (Session["currentOrderId"] != string.Empty)
                    {
                        currentOrderId = Convert.ToInt32(Session["currentOrderID"]);
                    }
                    Orders myCurrentOrder;
                    if (currentOrderId >= 0)
                    {
                        // Get the order based on order id.
                        myCurrentOrder = _db.Orders.Single(o => o.OrderId == currentOrderId);
                        // Update the order to reflect payment has been completed.
                        myCurrentOrder.PaymentTransactionId = PaymentConfirmation;
                        // Save to DB.
                        _db.SaveChanges();
                    }

                    // Clear shopping cart.
                    using (CampusCourier.Logic.ShoppingCartActions usersShoppingCart =
                               new CampusCourier.Logic.ShoppingCartActions())
                    {
                        usersShoppingCart.EmptyCart();
                    }

                    // Clear order id.
                    Session["currentOrderId"] = string.Empty;
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
        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 Orders();

                    myOrder.Username = User.Identity.Name;
                    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.
                    ProductContext _db = new ProductContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

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

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

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


                        // Set OrderId. Remove this if it wont work
                        Session["currentOrderId"] = myOrder.OrderId;

                        //Adding data to orders

                        List <CartItem> ordersdatalist = usersShoppingCart.GetCartItems();
                        for (int i = 0; i < ordersdatalist.Count; i++)
                        {
                            var ordersdata = new Orders();
                            ordersdata.OrderId  = myOrder.OrderId;
                            ordersdata.Quantity = ordersdatalist[i].Quantity;
                            int productid = ordersdatalist[i].ProductId;
                            ordersdata.RestName = ordersdatalist[i].Product.Restaurant.RestaurantName;

                            int location = Convert.ToInt32(ordersdatalist[i].Product.RestaurantID);

                            string        Query            = "SELECT LocationName from Locations WHERE LocationID ='" + location + "'";
                            string        connectionstring = ConfigurationManager.ConnectionStrings["CampusCourier"].ConnectionString;
                            SqlConnection conn             = new SqlConnection(connectionstring);
                            SqlCommand    comm             = new SqlCommand(Query, conn);
                            conn.Open();
                            SqlDataReader nwReader = comm.ExecuteReader();

                            while (nwReader.Read())
                            {
                                ordersdata.Location = (string)nwReader["LocationName"];
                            }
                            nwReader.Close();
                            conn.Close();

                            ordersdata.Total  = Convert.ToDecimal(ordersdatalist[i].Product.UnitPrice);
                            ordersdata.Status = "Waiting For Delivery";
                            _db.Orders.Add(ordersdata);
                            _db.SaveChanges();
                        }

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

                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                        Session["userCheckoutCompleted"] = "true";
                        Response.Redirect("~/Checkout/CheckoutComplete.aspx");
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
        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 Orders();

                    myOrder.Username = User.Identity.Name;
                    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.
                    ProductContext _db = new ProductContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

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

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

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

                        // Set OrderId. Remove this if it wont work
                        Session["currentOrderId"] = myOrder.OrderId;

                        //Adding data to orders

                        List<CartItem> ordersdatalist = usersShoppingCart.GetCartItems();
                        for (int i = 0; i < ordersdatalist.Count; i++)
                        {
                            var ordersdata = new Orders();
                            ordersdata.OrderId = myOrder.OrderId;
                            ordersdata.Quantity = ordersdatalist[i].Quantity;
                            int productid = ordersdatalist[i].ProductId;
                            ordersdata.RestName = ordersdatalist[i].Product.Restaurant.RestaurantName;

                            int location = Convert.ToInt32(ordersdatalist[i].Product.RestaurantID);

                            string Query = "SELECT LocationName from Locations WHERE LocationID ='" + location + "'";
                            string connectionstring = ConfigurationManager.ConnectionStrings["CampusCourier"].ConnectionString;
                            SqlConnection conn = new SqlConnection(connectionstring);
                            SqlCommand comm = new SqlCommand(Query, conn);
                            conn.Open();
                            SqlDataReader nwReader = comm.ExecuteReader();

                                while (nwReader.Read())
                                {
                                    ordersdata.Location = (string)nwReader["LocationName"];

                                }
                                nwReader.Close();
                                conn.Close();

                                ordersdata.Total = Convert.ToDecimal(ordersdatalist[i].Product.UnitPrice);
                                ordersdata.Status = "Waiting For Delivery";
                                _db.Orders.Add(ordersdata);
                                _db.SaveChanges();
                            }

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

                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                        Session["userCheckoutCompleted"] = "true";
                        Response.Redirect("~/Checkout/CheckoutComplete.aspx");
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     using (ShoppingCartActions cart = new ShoppingCartActions())
     {
         string cartString = string.Format("Takeout Box ({0} items)", cart.GetCount());
         cartCount.InnerText = cartString;
     }
 }
        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;

                    ProductContext _db = new ProductContext();
                    // Get the current order id.
                    int currentOrderId = -1;
                    if (Session["currentOrderId"] != string.Empty)
                    {
                        //currentOrderId = Convert.ToInt32(Session["currentOrderID"]);
                    }
                    //Orders myCurrentOrder;
                    if (currentOrderId >= 0)
                    {
                        // Get the order based on order id.
                        //myCurrentOrder = _db.Orders.Single(o => o.OrderId == currentOrderId);
                        // Update the order to reflect payment has been completed.
                        //myCurrentOrder.PaymentTransactionId = PaymentConfirmation;
                        // Save to DB.
                        //_db.SaveChanges();
                    }

                    // Clear shopping cart.
                    using (CampusCourier.Logic.ShoppingCartActions usersShoppingCart =
                        new CampusCourier.Logic.ShoppingCartActions())
                    {
                        usersShoppingCart.EmptyCart();
                    }

                    // Clear order id.
                    Session["currentOrderId"] = string.Empty;
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }