public List <cartitem> Getcoursecartitems() { ShoppingCartActions actions = new ShoppingCartActions(); return(actions.GetCartItems()); }
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}"); } } }
public void GetCartQuantity() { ShoppingCartActions actions = new ShoppingCartActions(); cartQuantity.InnerText = actions.GetCartItemsQuantity().ToString(); }
public IEnumerable <CartItem> GetShoppingCartItems() { var actions = new ShoppingCartActions(); return(actions.GetCartItems()); }
public async Task <ActionResult> Complete(OrderViewModel order) { try { // TODO: Complete the payment processing via the gateway and update the order... NVPAPICaller gatewayCaller = new NVPAPICaller(); string token = ""; string finalPaymentAmount = ""; NVPCodec decoder = new NVPCodec(); token = Session["token"].ToString(); //PayerID = Session["payerId"].ToString(); //finalPaymentAmount = Session["payment_amt"].ToString(); finalPaymentAmount = order.Total.ToString("C2"); bool ret = gatewayCaller.DoCheckoutPayment(finalPaymentAmount, token, ref decoder); if (ret) { // Retrieve PayPal confirmation value. string PaymentConfirmation = decoder[NVPProperties.Properties.TRANSACTIONID].ToString(); order.PaymentTransactionId = PaymentConfirmation; ProductContext _db = new ProductContext(); // Get the current order id. int currentOrderId = -1; if (Session["currentOrderId"] != null && Session["currentOrderId"].ToString() != string.Empty) { currentOrderId = Convert.ToInt32(Session["currentOrderID"]); } Order 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(); // Queue up a receipt generation request, asynchronously. await new AzureQueueHelper().QueueReceiptRequest(currentOrderId); // Report successful event to Application Insights. var eventProperties = new Dictionary <string, string>(); eventProperties.Add("CustomerEmail", order.Email); eventProperties.Add("OrderTotal", finalPaymentAmount); eventProperties.Add("PaymentTransactionId", PaymentConfirmation); TelemetryHelper.TrackEvent("OrderCompleted", eventProperties); } // Clear shopping cart. using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions(cartId)) { usersShoppingCart.EmptyCart(); } // Clear order id. Session["currentOrderId"] = string.Empty; } else { var error = gatewayCaller.PopulateGatewayErrorModel(decoder); // Report failed event to Application Insights. Exception ex = new Exception(error.ToString()); ex.Source = "Contoso.Apps.SportsLeague.Web.CheckoutController.cs"; TelemetryHelper.TrackException(ex); // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } } catch (WebException wex) { ExceptionUtility.LogException(wex, "CheckoutController.cs Complete Action"); var error = new CheckoutErrorViewModel { ErrorCode = wex.Message }; if (wex.Response != null && wex.Response.GetType() == typeof(HttpWebResponse)) { // Extract the response body from the WebException's HttpWebResponse: error.LongMessage = ((HttpWebResponse)wex.Response).StatusDescription; } // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } catch (Exception ex) { ExceptionUtility.LogException(ex, "CheckoutController.cs Complete Action"); var error = new CheckoutErrorViewModel { ErrorCode = ex.Message }; // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } return(View(order)); }
public ActionResult Review(CheckoutViewModel data) { if (ModelState.IsValid) { try { NVPAPICaller gatewayCaller = new NVPAPICaller(); string token = ""; NVPCodec decoder = new NVPCodec(); // Call the gateway payment authorization API: bool ret = gatewayCaller.DoCheckoutAuth(data.Order, ref token, ref decoder); // If authorizaton is successful: if (ret) { // Hydrate a new Order model from our OrderViewModel. var myOrder = Mapper.Map <Data.Models.Order>(data.Order); // Timestamp with a UTC date. myOrder.OrderDate = DateTime.UtcNow; // 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(cartId)) { 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.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; Session["Token"] = token; // Report successful event to Application Insights. var eventProperties = new Dictionary <string, string>(); eventProperties.Add("CustomerEmail", data.Order.Email); eventProperties.Add("NumberOfItems", myOrderList.Count.ToString()); eventProperties.Add("OrderTotal", data.Order.Total.ToString("C2")); eventProperties.Add("OrderId", myOrder.OrderId.ToString()); TelemetryHelper.TrackEvent("SuccessfulPaymentAuth", eventProperties); data.Order.OrderId = myOrder.OrderId; if (data.Order.CreditCardNumber.Length > 4) { // Only show the last 4 digits of the credit card number: data.Order.CreditCardNumber = "xxxxxxxxxxx" + data.Order.CreditCardNumber.Substring(data.Order.CreditCardNumber.Length - 4); } } } else { var error = gatewayCaller.PopulateGatewayErrorModel(decoder); // Report failed event to Application Insights. Exception ex = new Exception(error.ToString()); ex.Source = "Contoso.Apps.SportsLeague.Web.CheckoutController.cs"; TelemetryHelper.TrackException(ex); // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } } catch (WebException wex) { ExceptionUtility.LogException(wex, "CheckoutController.cs Complete Action"); var error = new CheckoutErrorViewModel { ErrorCode = wex.Message }; if (wex.Response != null && wex.Response.GetType() == typeof(HttpWebResponse)) { // Extract the response body from the WebException's HttpWebResponse: error.LongMessage = ((HttpWebResponse)wex.Response).StatusDescription; } // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } catch (Exception ex) { ExceptionUtility.LogException(ex, "CheckoutController.cs Review Action"); var error = new CheckoutErrorViewModel { ErrorCode = ex.Message }; // Redirect to the checkout error view: return(RedirectToAction("Error", error)); } } return(View(data)); }
public IQueryable <Product> GetProducts( [QueryString("id")] int?categoryId, [RouteData] string categoryName) { var _db = new WingtipToys.Models.ProductContext(); bool isIntel = false; bool isAmd = false; ShoppingCartActions actions = new ShoppingCartActions(); List <CartItem> items = actions.GetCartItems(); List <Product> products = new List <Product>(); foreach (CartItem item in items) { products.Add(_db.Products.SingleOrDefault(Product => Product.ProductID == item.Product.ProductID)); } //Filtere nach Mainboards List <Product> mainboards = new List <Product>(); foreach (Product product in products) { if (product.CategoryID == 1) { mainboards.Add(product); } } IQueryable <Product> query = _db.Products; query = query.Where(p => p.CategoryID == 2); if (mainboards.Any()) { foreach (Product mainboard in mainboards) { if (mainboard.isIntel) { isIntel = true; } if (mainboard.isAmd) { isAmd = true; } } if (isIntel == false && isAmd == true) { query = query.Where(p => p.isAmd == true); } else if (isIntel == true && isAmd == false) { query = query.Where(p => p.isIntel == true); } else if (isIntel == false && isAmd == false) { query = query.Where(p => p.isIntel == false); query = query.Where(p => p.isAmd == false); } //Falls beide true, dann einfach alles zurueckgeben } //if (categoryId.HasValue && categoryId > 0) //{ // query = query.Where(p => p.CategoryID == categoryId); //} //if (!String.IsNullOrEmpty(categoryName)) //{ // query = query.Where(p => // String.Compare(p.Category.CategoryName, // categoryName) == 0); //} return(query); }
// The return type can be changed to IEnumerable, however to support // paging and sorting, the following parameters must be added: // int maximumRows // int startRowIndex // out int totalRowCount // string sortByExpression public List <WingtipToys.Models.CartItem> GetShoppingCartItems() { ShoppingCartActions actions = new ShoppingCartActions(); return(actions.GetCartItems()); }
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); } } }
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()); try { decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString()); decimal paymentAmountFromPayPal = Convert.ToDecimal(decoder["AMT"].ToString()); if (paymentAmountOnCheckout != paymentAmountFromPayPal / 100) { 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 (ShoppingCartActions userShoppingCart = new ShoppingCartActions()) { List <CartItem> myOrderList = userShoppingCart.GetCartItems(); foreach (var item in myOrderList) { var myOrderDetail = new OrderDetail(); myOrderDetail.OrderId = myOrder.OrderId; myOrderDetail.Username = User.Identity.Name; myOrderDetail.ProductId = item.ProductId; myOrderDetail.Quantity = item.Quantity; myOrderDetail.UnitPrice = item.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); } } }
public List <CartItem> GetShoppingCartItems() { ShoppingCartActions run = new ShoppingCartActions(); return(run.GetCartItems()); }
public List <CartItem> GetShoppingCartItems() { var cartManager = new Logic.CartManager(); return(cartManager.GetCartItems(ShoppingCartActions.GetCartId())); }
public ShoppingCartActions GetCart(HttpContext context) { using (var cart = new ShoppingCartActions(GetCartId())) { return(cart); } }
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; ApplicationDbContext _db = new ApplicationDbContext(); // Get the current order id. int currentOrderId = -1; var temp = Session["currentOrderId"]; if (Convert.ToString(temp) != string.Empty) { currentOrderId = Convert.ToInt32(temp); } Order 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 (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.EmptyCart(); } // Clear order id. Session["currentOrderId"] = string.Empty; } else { Response.Redirect("CheckoutError.aspx?" + retMsg); } } }
public List <CartItem> GetShoppingCartItems() { ShoppingCartActions sca = new ShoppingCartActions(); return(sca.GetCartItems()); }
public List <CartItem> GetShoppingCartItems() { ShoppingCartActions actions = new ShoppingCartActions(); return(actions.GetCartItems()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Verify user has completed the checkout process if (Session["UserCheckoutCompleted"].ToString() != "true") { Session["UserCheckoutCompleted"] = string.Empty; Response.Redirect("/Checkout/CheckoutError.aspx?Desc=Unvalidated@20Checkout."); } var payPalCaller = new NVPAPICaller(); var retMsg = ""; var token = ""; var finalPaymentAmount = ""; var payerId = ""; var decoder = new NVPCodec(); token = Session["token"].ToString(); payerId = Session["payerId"].ToString(); finalPaymentAmount = Session["payment_amt"].ToString(); var ret = payPalCaller.DoCheckoutPayment(finalPaymentAmount, token, payerId, ref decoder, ref retMsg); if (ret) { // Retrieve PayPal confirmation value var PaymentConfirmation = decoder["PAYMENTINFO_0_TRANSACTIONID"]; TransactionId.Text = PaymentConfirmation; var _db = new ProductContext(); // Get the current order id var currentOrderId = -1; if (Session["currentOrderId"].ToString() != string.Empty) { currentOrderId = Convert.ToInt32(Session["CurrentOrderId"]); } Order 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 (var usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.EmptyCart(); } // Clear order id Session["CurrentOrderId"] = string.Empty; } else { Response.Redirect($"/Checkout/CheckoutError.aspx?{retMsg}"); } } }