예제 #1
0
        public ActionResult SubmitOrder(long orderId)
        {
            Order order = new Order();

            try
            {
                order = _orderRepository.GetOrderByOrderId(orderId);
                _orderRepository.UpdateOrder(order);

                //Generate delivery order
                string beginSerialNumber    = "CK-" + DateTime.Now.ToString("yyyyMMdd");
                string maxDeliveryNumberStr = _deliveryOrderRepository.GetMaxDeliveryOrderNumber(beginSerialNumber);

                DeliveryOrder deliveryOrder = new DeliveryOrder();
                deliveryOrder.DeliveryOrderNumber = beginSerialNumber + "-" + maxDeliveryNumberStr;
                deliveryOrder.DeliveryDate        = DateTime.Now;
                deliveryOrder.TotalRMBInChinese   = MathHelper.ConvertToChinese((Double)order.TotalAmount);
                deliveryOrder.TotalRMBInNumberic  = order.TotalAmount.ToString();
                deliveryOrder.OrderId             = order.Id;

                long             currentDeliveryOrderId = _deliveryOrderRepository.AddDeliveryOrder(deliveryOrder);
                List <OrderItem> orderItems             = order.OrderItems.ToList();
                foreach (var item in orderItems)
                {
                    DeliveryOrderItem deliveryOrderItem = new DeliveryOrderItem();
                    deliveryOrderItem.ProductName     = item.Product.ProductName;
                    deliveryOrderItem.Unit            = "件";
                    deliveryOrderItem.OutNumber       = item.Quantity;
                    deliveryOrderItem.PricePerProduct = item.UnitPrice;
                    deliveryOrderItem.TotalPrice      = item.Quantity * item.UnitPrice;
                    deliveryOrderItem.DeliveryOrderId = currentDeliveryOrderId;

                    _deliveryOrderItemRepository.AddDeliveryOrderItem(deliveryOrderItem);
                }

                //Generate delivery note
                DeliveryNote deliveryNote = new DeliveryNote();
                deliveryNote.DeliveryNoteNumber = "PS-" + DateTime.Now.ToString("yyyyMMdd") + "-" + maxDeliveryNumberStr;
                //Generate QR Code
                deliveryNote.QRCodeImgURL = QRCodeHelper.GetQRImage(deliveryNote.DeliveryNoteNumber);
                deliveryNote.OrderId      = order.Id;

                _deliveryNoteRepository.AddDeliveryNote(deliveryNote);
            }
            catch (Exception ex)
            {
            }
            return(View("SubmitOrder", order));
        }