Esempio n. 1
0
        /// <summary>
        /// The update order.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The TdService.Services.Messaging.Order.UpdateOrderResponse.
        /// </returns>
        public UpdateOrderResponse UpdateOrder(UpdateOrderRequest request)
        {
            OrderStatus orderStatus;
            Enum.TryParse(request.Status, true, out orderStatus);
            var order = new Order(orderStatus)
                {
                    Id = request.Id,
                    CreatedDate = DateTime.UtcNow,
                    OrderNumber = request.OrderNumber,
                    TrackingNumber = request.TrackingNumber
                };
            var response = new UpdateOrderResponse { BrokenRules = order.GetBrokenRules().ToList() };
            if (response.BrokenRules.Any())
            {
                response.MessageType = MessageType.Warning;
                return response;
            }

            try
            {
                ////var orderToUpdate = this.orderRepository.GetOrderById(order.Id);
                order.Update(order.OrderNumber, order.TrackingNumber);
                var updatedOrder = this.orderRepository.UpdateOrder(order);
                response = updatedOrder.ConvertToUpdateOrderResponse();
                response.Message = CommonResources.OrderUpdateSuccessMessage;
            }
            catch (Exception e)
            {
                response.MessageType = MessageType.Error;
                response.ErrorCode = e.Message;
                this.Logger.Error(CommonResources.OrderUpdateErrorMessage, e);
            }

            return response;
        }