public string[] CheckProductQuantities() { try { if (Context.User.IsInRole("User")) { User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name); List<ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList(); List<string> ViolatingIDs = new List<string>(); foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems) { if (!new OrdersLogic().HasSufficientQuantity(myShoppingCartItem.ProductFK, myShoppingCartItem.Quantity)) { ViolatingIDs.Add(myShoppingCartItem.ProductFK.ToString()); } } return ViolatingIDs.ToArray(); } else { return new string[] { "" }; } } catch (Exception Exception) { throw Exception; } }
public string LoadShoppingCartItems() { try { if (Context.User.IsInRole("User")) { string HTML = ""; User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name); List<ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList(); List<Product> myProductList = new List<Product>(); foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems) { myProductList.Add(new ProductsLogic().RetrieveProductByID(myShoppingCartItem.ProductFK.ToString())); } Product[] myProducts = myProductList.ToArray(); if (myProducts.Length > 0) { for (int i = 1; i <= (myProducts.Length + 4 / 4); i++) { int Counter = i * 4; HTML += "<tr>"; for (int j = (Counter - 3); j <= Counter; j++) { HTML += "<td>"; HTML += TDContents(myProducts[j - 1]); HTML += "</td>"; if (j == myProducts.Length) { goto LoopEnd; } } HTML += "</tr>"; } } LoopEnd: return HTML; } else { return ""; } } catch (Exception Exception) { throw Exception; } }
public void CompleteCheckout(string CreditCard) { try { if (Context.User.IsInRole("User")) { User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name); List<ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList(); List<OrderItem> myOrderItems = new List<OrderItem>(); foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems) { UserTypeProduct myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myShoppingCartItem.ProductFK); OrderItem myOrderItem = new OrderItem(); myOrderItem.Id = myShoppingCartItem.ProductFK; double myPrice = 0; if (myPriceType != null) { myPrice = myPriceType.Price; double? NewPrice = 0; if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null)) { if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo)) { NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price); myPrice = Convert.ToDouble(NewPrice); } } } myOrderItem.Price = myPrice; myOrderItem.Quantity = myShoppingCartItem.Quantity; myOrderItems.Add(myOrderItem); } //if ( new OrdersLogic().AddOrder(null, myLoggedUser.Id, CreditCard.Trim(), myOrderItems); //{ //new UsersLogic().InsertCreditCardNumber(CreditCard.Trim(), myLoggedUser.Id); //new ShoppingCartLogic().EmptyCart(myLoggedUser.Id); //} } } catch (Exception Exception) { throw Exception; } }
//ProductsView myCurrentProduct /// <summary> /// Generates TD Contents for Each Product /// Level: External /// </summary> /// <param name="myProduct">The Product to Display</param> /// <returns>HTML</returns> private string TDContents(Product myProduct) { try { string Name = myProduct.Name; string ImageURL = VirtualPathUtility.ToAbsolute(myProduct.ImageURL); string ProductID = myProduct.Id.ToString(); string ProductLink = "/user/viewproduct.aspx?id=" + new Encryption().Encrypt(myProduct.Id.ToString()); User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name); UserTypeProduct myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myProduct.Id); ShoppingCart myShoppingCartItem = new ShoppingCartLogic().RetrieveShoppingCartItemByID(myLoggedUser.Id, myProduct.Id); string Price = ""; if (myPriceType != null) { Price = "€" + myPriceType.Price.ToString("F"); double? NewPrice = 0; if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null)) { if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo)) { NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price); string myDisplayedNewPrice = Convert.ToDouble(NewPrice).ToString("F"); Price = myPriceType.DiscountPercentage + "% Off : €" + myDisplayedNewPrice; } } } //string Price = new ProductsLogic().RetrieveProductPrice(_UserType, myProduct.Id).ToString("F"); string ButtonHTML = "<input type=\"image\" class=\"ProductButton\" alt=\"\" ProductID=\"" + ProductID + "\" ClickAction=\"Add\" src=\"/images/Add.jpg\" onclick=\"return false;\" />" + "<div class=\"ProductButtonSpacer\"></div>" + "<input type=\"image\" class=\"ProductButton\" alt=\"\" ProductID=\"" + ProductID + "\" ClickAction=\"Remove\" src=\"/images/Remove.jpg\" onclick=\"return false;\"/>"; string OutOfStock = "No Stock "; string LowOnStock = "Low Stock "; string TextBox = "<div class=\"MiniFontGrey\"><div style=\"padding-top: 5px; float: left;\">Quantity </div><input type=\"text\" value=\"" + myShoppingCartItem.Quantity + "\" name=\"" + ProductID + "\" class=\"CatalogTextBox\"></div>" + "<br />"; if (myProduct.StockQuantity == 0) { ButtonHTML = ""; LowOnStock = ""; TextBox = "<div style=\"height: 27px; width: 1px\"></div>"; } else if (myProduct.StockQuantity <= myProduct.ReorderLevel) { OutOfStock = ""; } else { LowOnStock = ""; OutOfStock = ""; } string HTML = "<div>" + "<div class=\"ProductContent\">" + "<img class=\"ProductImage\" alt=\"\" src=\"" + ImageURL + "\" />" + "<br />" + "<a href=\"" + ProductLink + "\" target=\"_blank\" class=\"MiniFontGrey\">" + Name + "</a><br />" + "<div class=\"MiniFontBlue\">" + OutOfStock + LowOnStock + Price + "</div>" + "<br />" + TextBox + "</div>" + "<div class=\"ProductButtons\">" + ButtonHTML + "</div>"; return HTML; } catch (Exception Exception) { throw Exception; } }
public string LoadShoppingCartItems() { try { if (Context.User.IsInRole("User")) { string HTML = ""; User myLoggedUser = new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name); List<ShoppingCart> myShoppingCartItems = new ShoppingCartLogic().RetrieveAllShoppingCartItems(myLoggedUser.Id).ToList(); HTML += "<table>"; int Counter = 0; foreach (ShoppingCart myShoppingCartItem in myShoppingCartItems) { UserTypeProduct myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myLoggedUser.UserTypeFK, myShoppingCartItem.ProductFK); string PriceOutput = ""; if (myPriceType != null) { PriceOutput = myPriceType.Price.ToString("F"); double? NewPrice = 0; if ((myPriceType.DiscountDateFrom != null) && (myPriceType.DiscountDateTo != null) && (myPriceType.DiscountPercentage != null)) { if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo)) { NewPrice = myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price); string myDisplayedNewPrice = Convert.ToDouble(NewPrice).ToString("F"); PriceOutput = myDisplayedNewPrice + " : " + myPriceType.DiscountPercentage + " % Off"; } } } HTML += "<tr class=\"GridViewTuple\">"; HTML += "<td>"; HTML += new ProductsLogic().RetrieveProductByID(myShoppingCartItem.ProductFK.ToString()).Name; HTML += "</td>"; HTML += "<td>"; HTML += "<div style=\"padding-top: 4px; float: left;\">x </div><input class=\"CatalogTextBox\" id=\"" + myShoppingCartItem.ProductFK + "\" Use=\"Quantity\" type=\"text\" value=\"" + myShoppingCartItem.Quantity.ToString() + "\">"; HTML += "</td>"; HTML += "<td> at </td>"; HTML += "<td>"; HTML += "€ " + PriceOutput; HTML += "</td>"; HTML += "<td>"; HTML += "<div Use=\"ErrorDiv\" ProductID=\"" + myShoppingCartItem.ProductFK + "\" class=\"MiniFontBlue\">Not Enough Stock</div>"; HTML += "</td>"; HTML += "</tr>"; Counter++; } HTML += "</table>"; return HTML; } else { return ""; } } catch (Exception Exception) { throw Exception; } }