Beispiel #1
0
        public ResponseMessage ExecuteOperation(RequestMessage request)
        {
            try
            {
                Order orderToGet = OrderRepository.GetOrder(request.OrderId);

                return(_responseMessageFactory.CreateOrderQueryResponseMessage(request, orderToGet));
            }
            catch (Exception ex)
            {
                _loggerService.WriteLine("Exception during operation GetOrderDetails: " + ex, "GetOrderDetailsError");
                return(_responseMessageFactory.CreateErrorResponseMessage(ex));
            }
        }
Beispiel #2
0
        public ResponseMessage ExecuteOperation(RequestMessage request)
        {
            try
            {
                Order orderToCancel = OrderRepository.GetOrder(request.OrderId);

                switch (orderToCancel.State)
                {
                case OrderState.Shipped:
                    // msg cannot cancel shipped order
                    return(_responseMessageFactory.CreateCancellationResponseMessage(request, orderToCancel,
                                                                                     "Cannot cancel an order that has been shipped."));

                case OrderState.Cancelled:
                    return(_responseMessageFactory.CreateCancellationResponseMessage(request, orderToCancel,
                                                                                     "Order has already been cancelled."));

                default:
                    foreach (OrderItem item in orderToCancel.OrderItems)
                    {
                        InventoryItem inventoryItem = InventoryRepository.GetInventoryItem(item.ItemCode);

                        if (item.State == OrderItemState.Filled)
                        {
                            inventoryItem.QuantityOnHand += item.Quantity;
                        }

                        item.State = OrderItemState.Cancelled;
                    }

                    orderToCancel.State = OrderState.Cancelled;

                    // save inventory
                    InventoryRepository.UpdateInventory();

                    // save order
                    OrderRepository.UpdateOrders();

                    return(_responseMessageFactory.CreateCancellationResponseMessage(request, orderToCancel,
                                                                                     "Order has been cancelled and reserved inventory has been released."));
                }
            }
            catch (Exception ex)
            {
                _loggerService.WriteLine("Exception during operation CancelOrder: " + ex, "CancelOrderError");
                return(_responseMessageFactory.CreateErrorResponseMessage(ex));
            }
        }
Beispiel #3
0
        public ResponseMessage ExecuteOperation(RequestMessage request)
        {
            try
            {
                Order order = OrderRepository.CreateOrder();

                order.OrderItems.AddRange(request.OrderItems);

                foreach (OrderItem item in order.OrderItems)
                {
                    InventoryItem inventoryItem = InventoryRepository.GetInventoryItem(item.ItemCode);

                    if (item.Quantity <= inventoryItem.QuantityOnHand)
                    {
                        inventoryItem.QuantityOnHand -= item.Quantity;
                        item.Weight = item.WeightPerUnit * (float)item.Quantity;

                        _priceCalculator.CalculatePrice(item, inventoryItem);

                        item.State = OrderItemState.Filled;
                    }
                    else
                    {
                        item.State = OrderItemState.NotEnoughQuantityOnHand;
                    }
                }

                order.State = order.OrderItems.All(o => o.State == OrderItemState.Filled)
                    ? OrderState.Filled
                    : OrderState.Processing;

                OrderRepository.AddOrder(order);

                // save inventory
                InventoryRepository.UpdateInventory();

                // save order
                OrderRepository.UpdateOrders();

                return(_responseMessageFactory.CreateOrderSubmissionResponseMessage(request, order));
            }
            catch (Exception ex)
            {
                _loggerService.WriteLine("Exception during operation SubmitOrder: " + ex, "SubmitOrderError");
                return(_responseMessageFactory.CreateErrorResponseMessage(ex));
            }
        }