Example #1
0
 public void ClearForUser(UserThumbprint userThumbprint)
 {
     using (SqlConnection connection = new SqlConnection(_dbConnection.ConnectionString))
     {
         ClearForUser(userThumbprint, connection);
     }
 }
Example #2
0
        public List <Order> GetForUser(UserThumbprint UserThumbprint)
        {
            List <Order> returnMe = new List <Order>();

            using (SqlConnection connection = new SqlConnection(_dbConnection.ConnectionString))
            {
                using (SqlCommand sqlCommand = new SqlCommand
                {
                    Connection = connection,
                    CommandType = CommandType.Text,
                    CommandText = "SELECT * FROM Orders WHERE UserThumbprint=@USERID"
                })
                {
                    sqlCommand.Parameters.AddWithValue("USERID", UserThumbprint.Value);
                    sqlCommand.Connection.Open();
                    SqlDataReader dbDataReader = sqlCommand.ExecuteReader();

                    if (dbDataReader.HasRows)
                    {
                        while (dbDataReader.Read())
                        {
                            Order obj = dataReaderToObject(dbDataReader);
                            if (obj != null)
                            {
                                returnMe.Add(obj);
                            }
                        }
                    }

                    sqlCommand.Connection.Close();
                }
            }

            return(returnMe);
        }
Example #3
0
        public static ShoppingCartItem ToShoppingCartItem(this Product Product, UserThumbprint userthumbprint, int Quantity)
        {
            // I don't this situation can actually happen, but just in case I'm mistaken
            if (Product == null)
            {
                throw new ProductConversionException("Given product object was null");
            }

            if (userthumbprint == null)
            {
                throw new ProductConversionException("Given user thumbprint was null");
            }

            if (string.IsNullOrEmpty(userthumbprint.Value))
            {
                throw new ProductConversionException("User thumbprint was empty");
            }

            return(new ShoppingCartItem()
            {
                ProductId = Product.Id,
                Product = Product,
                UserThumbprint = userthumbprint.Value,
                Quantity = Quantity
            });
        }
Example #4
0
        public void UserThumbprint_ShouldThrowExceptionOnNullInput()
        {
            string         input = null;
            UserThumbprint thumb;

            Assert.Throws <InvalidUsernameException>(() => thumb = new UserThumbprint(input));
        }
Example #5
0
        public void UserThumbprint_CreatesConsistentValues(string input)
        {
            UserThumbprint thumb1 = new UserThumbprint(input);
            UserThumbprint thumb2 = new UserThumbprint(input);

            Assert.Equal(thumb1.Value, thumb2.Value);
        }
Example #6
0
 public void UpdateUserCartItems(UserThumbprint userThumbprint, List <ShoppingCartItem> items)
 {
     using (SqlConnection connection = new SqlConnection(_dbConnection.ConnectionString))
     {
         this.ClearForUser(userThumbprint, connection);
         this.Create(items, connection);
     }
 }
        public UserFriendlyShoppingCart(DatabaseContext DatabaseContext, string UserAccount)
        {
            this._dbContext                  = DatabaseContext;
            this._userThumbPrint             = new UserThumbprint(UserAccount);
            this._shoppingCartItemRepository = new ShoppingCartItemRepository(this._dbContext);
            this._productRepository          = new ProductRepository(this._dbContext);

            this._items = new Dictionary <int, ShoppingCartItem>();

            // Load this user's shopping cart
            foreach (ShoppingCartItem sci in _shoppingCartItemRepository.GetAllForUser(this._userThumbPrint))
            {
                this.AddItem(sci);
            }
        }
        public UserFriendlyOrders(DatabaseContext dbContext, string UserAccount)
        {
            this._dbContext       = dbContext;
            this._orderRepository = new OrderRepository(this._dbContext);
            this._userThumbPrint  = new UserThumbprint(UserAccount);
            this.UserOrders       = new Dictionary <string, Order>();

            foreach (Order order in _orderRepository.GetForUser(this._userThumbPrint))
            {
                if (!UserOrders.ContainsKey(order.OrderThumbprint))
                {
                    UserOrders.Add(order.OrderThumbprint, order);
                }
            }
        }
Example #9
0
 public void ClearForUser(UserThumbprint userThumbprint, SqlConnection connection)
 {
     using (SqlCommand sqlCommand = new SqlCommand
     {
         Connection = connection,
         CommandType = CommandType.Text,
         CommandText = "DELETE FROM ShoppingCartItems WHERE UserThumbprint=@USERID;"
     })
     {
         sqlCommand.Parameters.AddWithValue("USERID", userThumbprint.Value);
         sqlCommand.Connection.Open();
         sqlCommand.ExecuteNonQuery();
         sqlCommand.Connection.Close();
     }
 }
        public void ProductExtensions_ShouldThrowExceptionIfUserThumbIsNull()
        {
            UserThumbprint nullUser = null;

            Assert.Throws <ProductConversionException>(() => testProduct.ToShoppingCartItem(nullUser));
        }
        public Order CreateOrder(IEnumerable <ShoppingCartItem> items, string BudgetAccountNumber, string SubmittedByName, string SubmittdByEmail, UserThumbprint userThumbprint, string customerNotes)
        {
            OrderStatusDetailRepository orderStatusDetailRepository = new OrderStatusDetailRepository(this._dbContext);
            OrderItemRepository         orderItemRepository         = new OrderItemRepository(this._dbContext);

            // We need to get a new OrderID or make one somehow
            // Hash the user thumbprint and the date and time together, and it should be fairly unique...

            List <OrderItem> newOrderItems = new List <OrderItem>();

            foreach (ShoppingCartItem scitem in items)
            {
                if (scitem.Quantity > 0)
                {
                    newOrderItems.Add(new OrderItem()
                    {
                        OrderThumbprint   = "WILL-GET-REPLACED",
                        Name              = scitem.Product.Name,
                        ItemBasePrice     = scitem.Product.BasePrice,
                        ItemGST           = scitem.Product.GSTAmount,
                        ItemPST           = scitem.Product.PSTAmount,
                        ItemEHF           = scitem.Product.RecyclingFee,
                        ItemPriceWithTax  = scitem.Product.TotalPrice,
                        TotalBasePrice    = (decimal)(scitem.Product.BasePrice * scitem.Quantity),
                        TotalEHF          = (decimal)(scitem.Product.RecyclingFee * scitem.Quantity),
                        TotalPST          = (decimal)(scitem.Product.PSTAmount * scitem.Quantity),
                        TotalGST          = (decimal)(scitem.Product.GSTAmount * scitem.Quantity),
                        TotalPriceWithTax = (decimal)(scitem.Product.TotalPrice * scitem.Quantity),
                        ProductId         = scitem.ProductId,
                        Quantity          = scitem.Quantity,
                    });
                }
            }

            OrderStatusDetail newOrderStatusDetail = new OrderStatusDetail()
            {
                OrderThumbprint = "WILL-GET-REPLACED",
                Status          = "Order Submitted",
                Timestamp       = DateTime.Now,
                UpdatedBy       = SubmittedByName,
                Notes           = string.Empty
            };


            Order newOrder = new Order()
            {
                OrderThumbprint      = "WILL-GET-REPLACED",
                UserThumbprint       = userThumbprint.Value,
                OrderDate            = DateTime.Now,
                CustomerFullName     = SubmittedByName,
                CustomerEmailAddress = SubmittdByEmail,
                BudgetAccountNumber  = BudgetAccountNumber,
                CustomerNotes        = customerNotes,
                StatusDetails        = new List <OrderStatusDetail>()
                {
                    newOrderStatusDetail
                },
                Items           = newOrderItems,
                OrderTotalItems = newOrderItems.Sum(x => x.Quantity),
                OrderSubTotal   = newOrderItems.Sum(x => x.TotalBasePrice),
                OrderGrandTotal = newOrderItems.Sum(x => x.TotalPriceWithTax),
                TotalEHF        = newOrderItems.Sum(x => x.TotalEHF),
                TotalGST        = newOrderItems.Sum(x => x.TotalGST),
                TotalPST        = newOrderItems.Sum(x => x.TotalPST)
            };

            string orderThumbprint = _orderRepository.Create(newOrder);

            // Update the order thumbprint for things that need it
            newOrder.OrderThumbprint = orderThumbprint;
            newOrder.StatusDetails.ForEach(x => x.OrderThumbprint = orderThumbprint);
            newOrder.Items.ForEach(x => x.OrderThumbprint         = orderThumbprint);

            orderItemRepository.Create(newOrder.Items);
            orderStatusDetailRepository.Create(newOrder.StatusDetails);

            return(newOrder);
        }
Example #12
0
 public static ShoppingCartItem ToShoppingCartItem(this Product Product, UserThumbprint userthumbprint)
 {
     return(ToShoppingCartItem(Product, userthumbprint, 1));
 }
Example #13
0
        public void UserThumbprint_HasValue(string input)
        {
            UserThumbprint thumb = new UserThumbprint(input);

            Assert.NotEmpty(thumb.Value);
        }