Exemple #1
0
 public void Setup()
 {
     this.oir = new OrderItemRepository();
     oir.Create(OI);
 }
        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);
        }