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);
                }
            }
        }
Ejemplo n.º 2
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();
                    var myAddress = new Address();
                    myOrder.OrderDate  = Convert.ToDateTime(decoder["TIMESTAMP"].ToString());
                    myOrder.Username   = User.Identity.Name;
                    myAddress.UserName = decoder["EMAIL"].ToString();
                    // myAddress = "";
                    myAddress.AddressLine1 = decoder["SHIPTOSTREET"].ToString();
                    myAddress.City         = decoder["SHIPTOCITY"].ToString();
                    myAddress.State        = decoder["SHIPTOSTATE"].ToString();
                    myAddress.PostalCode   = decoder["SHIPTOZIP"].ToString();
                    myAddress.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.
                    ProductContext _db = new ProductContext();

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

                    // Get the shopping cart items and process them.
                    using (fashionUtilityApplication.Logic.ShoppingCartActions usersShoppingCart = new fashionUtilityApplication.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.Username  = User.Identity.Name;
                            myOrderDetail.ProductId = myOrderList[i].ProductId;
                            myOrderDetail.Quantity  = myOrderList[i].Quantity;
                            myOrderDetail.ImagePath = myOrderList[i].ImagePath;
                            myOrderDetail.UnitPrice = myOrderList[i].Product.UnitPrice;

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

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

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

                        List <Address> addressList = new List <Address>();
                        addressList.Add(myAddress);
                        ShipInfo.DataSource = addressList;
                        ShipInfo.DataBind();


                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVPAPICaller paypalCaller = new NVPAPICaller();

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

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

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

                    // Verify total payment amount as set on CheckoutStart.aspx.
                    try
                    {
                        decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString(), CultureInfo.InvariantCulture);
                        decimal paymentAmoutFromPayPal  = Convert.ToDecimal(decoder["AMT"].ToString(), CultureInfo.InvariantCulture);
                        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 (ShoppingCartActions usersShoppingCart = new 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
                            {
                                OrderId   = myOrder.OrderId,
                                Username  = User.Identity.Name,
                                ProductId = myOrderList[i].ProductId,
                                Quantity  = myOrderList[i].Quantity,
                                UnitPrice = myOrderList[i].Product.UnitPrice
                            };

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

                        // 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 = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect($"CheckoutError.aspx?{retMsg}");
                }
            }
        }
Ejemplo n.º 4
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 Order1();
                    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());
                    //myOrder.Total = decimal.Parse(decoder["AMT"].ToString());
                    var culture = CultureInfo.InvariantCulture;


                    //   int total = Convert.ToInt32(decoder["AMT"].ToString());
                    myOrder.Total = Decimal.Parse(decoder["AMT"].ToString(), culture);


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

                    //// Calling ShoppingCart object here

                    ShoppingCart k = new ShoppingCart();

                    //// Save orderDetails  and CustomerDetails to the DB.

                    k.SaveOrderDetails(myOrder);
                    k.SaveCustomerDetails();

                    //Set OrderId.


                    string currentOrderId = ConnectionClass.GetMaxOrderId();

                    Session["currentOrderId"] = currentOrderId;


                    // Get the Shopping Cart Products
                    DataTable dt = (DataTable)Session["MyCart"];


                    DataTable myOrderDetail = new DataTable();
                    myOrderDetail.Columns.Add("ProductID", typeof(string));
                    myOrderDetail.Columns.Add("ProductName", typeof(string));
                    myOrderDetail.Columns.Add("ProductPrice", typeof(string));
                    myOrderDetail.Columns.Add("ProductQuantity", typeof(string));

                    DataRow dr = myOrderDetail.NewRow();

                    // Display OrderDetail information to the Review page for each product purchased.
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dr["ProductID"]       = Convert.ToInt32(dt.Rows[i]["ProductID"]);
                        dr["ProductName"]     = dt.Rows[i]["Name"].ToString();
                        dr["ProductPrice"]    = dt.Rows[i]["Price"].ToString();
                        dr["ProductQuantity"] = Convert.ToInt32(dt.Rows[i]["ProductQuantity"]);

                        myOrderDetail.Rows.Add(dr);
                    }


                    // Display OrderDetails.
                    OrderItemList.DataSource = myOrderDetail;
                    OrderItemList.DataBind();

                    // Add OrderDetail information to the DB for each product purchased.
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        // Create a new OrderDetail object.
                        ShoppingCart orderDetail = new ShoppingCart()
                        {
                            ProductID       = Convert.ToInt32(dt.Rows[i]["ProductID"]),
                            ProductName     = dt.Rows[i]["Name"].ToString(),
                            ProductPrice    = dt.Rows[i]["Price"].ToString(),
                            ProductQuantity = Convert.ToInt32(dt.Rows[i]["ProductQuantity"])
                        };

                        orderDetail.AddOrders();
                    }



                    // Display Order information.

                    List <Order1> orderList = new List <Order1>();
                    orderList.Add(myOrder);
                    ShipInfo.DataSource = orderList;
                    ShipInfo.DataBind();
                }
                else
                {
                    Response.Redirect("~/Checkout/CheckoutError.aspx?" + retMsg);
                }
            }
        }
Ejemplo n.º 5
0
        protected override void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var pedido = new Pedido();
                if (!string.IsNullOrEmpty(Request.QueryString["idPedido"]))
                {
                    pedido.ID = Convert.ToInt32(Request.QueryString["idPedido"]);
                }

                pedido = commands["CONSULTAR"].execute(pedido).Entidades.Cast <Pedido>().ElementAt(0);

                pedido.EnderecoEntrega = commands["CONSULTAR"].execute(new Endereco()
                {
                    ID = pedido.EnderecoEntrega.ID
                }).Entidades.Cast <Endereco>().ElementAt(0);

                pedido.Detalhes = commands["CONSULTAR"].execute(new PedidoDetalhe()
                {
                    IdPedido = pedido.ID
                }).Entidades.Cast <PedidoDetalhe>().ToList();

                pedido.CCs = commands["CONSULTAR"].execute(new CartaoCreditoPedido()
                {
                    IdPedido = pedido.ID
                }).Entidades.Cast <CartaoCreditoPedido>().ToList();

                entidades = new List <EntidadeDominio>();
                entidades = commands["CONSULTAR"].execute(new PedidoXCupom()
                {
                    ID = pedido.ID
                }).Entidades;
                if (entidades.Count > 0)
                {
                    pedido.CupomPromocional = commands["CONSULTAR"].execute(new PedidoXCupom()
                    {
                        ID = pedido.ID
                    }).Entidades.Cast <PedidoXCupom>().ElementAt(0).Cupom;
                }


                entidades = new List <EntidadeDominio>();
                entidades = commands["CONSULTAR"].execute(new Cupom()
                {
                    IdPedido = pedido.ID
                }).Entidades;
                if (entidades.Count > 0)
                {
                    pedido.CuponsTroca = commands["CONSULTAR"].execute(new Cupom()
                    {
                        IdPedido = pedido.ID
                    }).Entidades.Cast <Cupom>().ToList();
                }


                // Set OrderId.
                Session["currentOrderId"] = pedido.ID;

                // Exibi as informações Entrega
                List <Pedido> listaPedido = new List <Pedido>();
                listaPedido.Add(pedido);
                ShipInfo.DataSource = listaPedido;
                ShipInfo.DataBind();

                // Exibi as informações Status
                List <Pedido> listaStatus = new List <Pedido>();
                listaStatus.Add(pedido);
                StatusDetail.DataSource = listaStatus;
                StatusDetail.DataBind();

                // Exibi as informações Total
                List <Pedido> listaTotal = new List <Pedido>();
                listaTotal.Add(pedido);
                TotalDetail.DataSource = listaTotal;
                TotalDetail.DataBind();

                if (pedido.Status.ID == 6 || pedido.Status.ID == 7 || pedido.Status.ID == 8)
                {
                    ShipInfo.Visible = false;
                }
                else
                {
                    ShipInfo.Visible = true;
                }

                // Mostra os detalhes do pedido
                OrderItemList.DataSource = pedido.Detalhes;
                OrderItemList.DataBind();
            }
            else
            {
                //Response.Redirect("./CheckoutError.aspx?Desc=ID%20de%20pedido%20incompatível.");
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var payPalCaller = new NVPAPICaller();

                var retMsg  = "";
                var token   = Session["token"].ToString();
                var payerId = "";
                var decoder = new NVPCodec();

                var 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"]);
                    myOrder.Username   = User.Identity.Name;
                    myOrder.FirstName  = decoder["FIRSTNAME"];
                    myOrder.LastName   = decoder["LASTNAME"];
                    myOrder.Address    = decoder["SHIPTOSTREET"];
                    myOrder.City       = decoder["SHIPTOCITY"];
                    myOrder.State      = decoder["SHIPTOSTATE"];
                    myOrder.PostalCode = decoder["SHIPTOZIP"];
                    myOrder.Country    = decoder["SHIPTOCOUNTRYCODE"];
                    myOrder.Email      = decoder["EMAIL"];
                    myOrder.Total      = Convert.ToDecimal(decoder["AMT"]);

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

                    // Get DB context
                    var _db = new ProductContext();

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

                    // Get the shopping cart items and process them.
                    using (var usersShoppingCart = new ShoppingCartActions()) {
                        var myOrderList = usersShoppingCart.GetCartItems();

                        // Add OrderDetail information to the db for each product purchased
                        foreach (var item in myOrderList)
                        {
                            // Create a new OrderDetail object
                            var myOrderDetail = new OrderDetail {
                                OrderId   = myOrder.OrderId,
                                Username  = User.Identity.Name,
                                ProductId = item.ProductId,
                                Quantity  = item.Quantity,
                                UnitPrice = item.Product.UnitPrice
                            };
                            // Add OrderDetail to db
                            _db.OrderDetails.Add(myOrderDetail);
                            _db.SaveChanges();
                        }
                        // Set OrderId
                        Session["CurrentOrderId"] = myOrder.OrderId;

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

                        // Display OrderDetails
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect($"/Checkout/CheckoutError.aspx?{retMsg}");
                }
            }
        }
Ejemplo n.º 7
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 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);
                }
            }
        }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVAPICaller payPalcaller = new NVAPICaller();

                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());

                    try
                    {
                        decimal paymentAmountOnCheckout =
                            Convert.ToDecimal(Session["payment_amt"].ToString());
                        decimal paymentAmountFromPayPal =
                            Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmountFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    ProductContext _db = new ProductContext();

                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

                    using (Sklep.Logic.ShoppingCartActions usersShoppingCart = new Sklep.Logic.ShoppingCartActions())
                    {
                        List <CartItem> myOrderList = usersShoppingCart.GetCartItems();

                        for (int i = 0; i < myOrderList.Count; i++)
                        {
                            var myOrderDetail = new OrderDetail();
                            myOrderDetail.OrderId   = myOrder.OrderId;
                            myOrderDetail.UserName  = User.Identity.Name;
                            myOrderDetail.ProductId = myOrderList[i].ProductId;
                            myOrderDetail.Quantity  = myOrderList[i].Quantity;
                            myOrderDetail.UnitPrice = myOrderList[i].Product.UnitPrice;

                            _db.OrderDetails.Add(myOrderDetail);
                            _db.SaveChanges();
                        }

                        Session["currentOrderId"] = myOrder.OrderId;

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

                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Ejemplo n.º 9
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);
                }
            }
        }
Ejemplo n.º 10
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 (GetFromCookie("username", null) != null)
                {
                    Session["payerId"] = PayerID;
                    var myOrder = new Order();
                    myOrder.OrderDate  = Convert.ToDateTime(GetFromCookie("timestamp", null));
                    myOrder.Username   = GetFromCookie("username", null);
                    myOrder.FirstName  = GetFromCookie("firstname", null);
                    myOrder.LastName   = GetFromCookie("lastname", null);
                    myOrder.Address    = GetFromCookie("address", null);
                    myOrder.City       = GetFromCookie("city", null);
                    myOrder.State      = GetFromCookie("state", null);
                    myOrder.PostalCode = GetFromCookie("postalcode", null);
                    myOrder.Country    = GetFromCookie("country", null);
                    myOrder.Email      = GetFromCookie("email", null);
                    myOrder.Total      = Convert.ToDecimal(GetFromCookie("total", null));
                    // 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 (WingtipToys.Logic.ShoppingCartActions usersShoppingCart = new
                                                                                     WingtipToys.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.Username  = 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.
                        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 = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string retMsg  = "";
                string token   = "";
                string PayerID = "";

                //TODO: Replace the default value of true with a validation control signal
                if (true)
                {
                    Session["payerId"] = PayerID;

                    var myOrder = new Order
                    {
                        OrderDate  = DateTime.Now,
                        Username   = User.Identity.Name,
                        Total      = Convert.ToDecimal(Session["payment_amt"]),
                        FirstName  = "TestBuyer",
                        LastName   = "Tester",
                        Address    = "Test Street",
                        City       = "Test City",
                        State      = "Test State",
                        PostalCode = "4339",
                        Country    = "South Africa",
                        Email      = "*****@*****.**"
                    };

                    // 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 (FreddyFruit.Logic.ShoppingCartActions usersShoppingCart = new FreddyFruit.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.Username  = 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.
                        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 = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }