/// <summary> /// Retrieves a Users Shopping Cart Total /// Level: Data /// </summary> /// <param name="UserID">The User ID</param> /// <returns>The Shopping Cart Total Price</returns> public double RetrieveCartTotal(Guid UserID) { try { IQueryable <ShoppingCart> myUserCart = RetrieveAllShoppingCartItems(UserID); User myUser = new UsersRepository().RetrieveUserById(UserID); double TotalPrice = 0; foreach (ShoppingCart myShoppingCartItem in myUserCart) { UserTypeProduct myPriceType = new PriceTypesRepository().RetrievePriceTypeByID(myUser.UserTypeFK, myShoppingCartItem.ProductFK); if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo)) { TotalPrice += Convert.ToDouble(myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price)) * myShoppingCartItem.Quantity; } else { TotalPrice += myPriceType.Price * myShoppingCartItem.Quantity; } } return(TotalPrice); } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Retrieves a Users Shopping Cart Total /// Level: Data /// </summary> /// <param name="UserID">The User ID</param> /// <returns>The Shopping Cart Total Price</returns> public double RetrieveCartTotal(Guid UserID) { try { IQueryable<ShoppingCart> myUserCart = RetrieveAllShoppingCartItems(UserID); User myUser = new UsersRepository().RetrieveUserById(UserID); double TotalPrice = 0; foreach (ShoppingCart myShoppingCartItem in myUserCart) { UserTypeProduct myPriceType = new PriceTypesRepository().RetrievePriceTypeByID(myUser.UserTypeFK, myShoppingCartItem.ProductFK); if ((DateTime.Now >= myPriceType.DiscountDateFrom) && (DateTime.Now <= myPriceType.DiscountDateTo)) { TotalPrice += Convert.ToDouble(myPriceType.Price - ((myPriceType.DiscountPercentage / 100) * myPriceType.Price)) * myShoppingCartItem.Quantity; } else { TotalPrice += myPriceType.Price * myShoppingCartItem.Quantity; } } return TotalPrice; } catch (Exception Exception) { throw Exception; } }