Пример #1
0
        public IOrderNote AddNote(IPurchaseOrder order, string title, string detail)
        {
            var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();
            var notes   = order.Notes;

            var note = _orderGroupFactory.CreateOrderNote(order);

            note.CustomerId = contact?.PrimaryKeyId ?? PrincipalInfo.CurrentPrincipal.GetContactId();
            note.Type       = OrderNoteTypes.Custom.ToString();
            note.Title      = title;
            note.Detail     = detail;
            note.Created    = DateTime.UtcNow;
            notes.Add(note);

            return(note);
        }
Пример #2
0
 public IOrderNote CreateOrderNote(IOrderGroup orderGroup)
 {
     return(_orderGroupFactory.CreateOrderNote(orderGroup));
 }
Пример #3
0
        //Exercise (E2) Do CheckOut
        public ActionResult CheckOut(CheckOutViewModel model)
        {
            var cart = _orderRepository.LoadCart <ICart>(GetContactId(), DefaultCart);

            var isAutenticated = PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated;

            var orderAddress = AddAddressToOrder(cart);

            AdjustFirstShipmentInOrder(cart, orderAddress, model.SelectedShippingId);

            AddPaymentToOrder(cart, model.SelectedPaymentId);

            var validationMessages = ValidateCart(cart);

            if (!string.IsNullOrEmpty(validationMessages))
            {
                model.Warnings = validationMessages;
            }

            // Adding this for test
            var cartReference = _orderRepository.Save(cart);

            IPurchaseOrder purchaseOrder;
            OrderReference orderReference;

            using (var scope = new TransactionScope())
            {
                var validationIssues = new Dictionary <ILineItem, ValidationIssue>();

                _inventoryProcessor.AdjustInventoryOrRemoveLineItem(cart.GetFirstShipment()
                                                                    , OrderStatus.InProgress, (item, issue) => validationIssues.Add(item, issue));

                if (validationIssues.Count >= 1)
                {
                    throw new Exception("Not possible right now");
                }

                try
                {
                    cart.ProcessPayments();
                }
                catch (Exception e)
                {
                    foreach (
                        var p in cart.GetFirstForm().Payments.Where(p => p.Status != PaymentStatus.Processed.ToString()))
                    {
                        cart
                    }
                    _orderRepository.Save(cart);
                    throw new Exception("Payment failed");
                }

                var totalProcessedAmount = cart.GetFirstForm().Payments.Where
                                               (x => x.Status.Equals(PaymentStatus.Processed.ToString())).Sum(x => x.Amount);

                var cartTotal = cart.GetTotal();

                if (totalProcessedAmount != cart.GetTotal(_orderGroupCalculator).Amount)
                {
                    _inventoryProcessor.AdjustInventoryOrRemoveLineItem(cart.GetFirstShipment()
                                                                        , OrderStatus.Cancelled, (item, issue) => validationIssues.Add(item, issue));


                    throw new InvalidOperationException("Wrong amount"); // maybe change approach
                }


                // ...could do this here
                cart.GetFirstShipment().OrderShipmentStatus = OrderShipmentStatus.InventoryAssigned;

                // decrement inventory and let it go
                _inventoryProcessor.AdjustInventoryOrRemoveLineItem(cart.GetFirstShipment()
                                                                    , OrderStatus.Completed, (item, issue) => validationIssues.Add(item, issue));

                orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
                purchaseOrder  = _orderRepository.Load <IPurchaseOrder>(orderReference.OrderGroupId);
                _orderRepository.Delete(cart.OrderLink);

                scope.Complete();
            }

            var note = _orderGroupFactory.CreateOrderNote(purchaseOrder);

            note.CustomerId = GetContactId();
            note.Title      = "Order Created";
            note.Detail     = "Order Created by Commerce Training Fundamentals";
            note.Type       = OrderNoteTypes.Custom.ToString();

            purchaseOrder.Notes.Add(note);

            _orderRepository.Save(purchaseOrder);

            // Final steps, navigate to the order confirmation page
            StartPage        home = _contentLoader.Get <StartPage>(ContentReference.StartPage);
            ContentReference orderPageReference = home.Settings.orderPage;

            // the below is a dummy, change to "PO".OrderNumber when done
            string passingValue = purchaseOrder.OrderNumber;

            return(RedirectToAction("Index", new { node = orderPageReference, passedAlong = passingValue }));
        }