public IEnumerable <FBAMasterOrderDto> QureyInboundOrders(OrderStatusQureyBody qurey, out List <QureyStatus> qureyStatus)
        {
            var qureyStatusList = new List <QureyStatus>();

            var results = _context.FBAMasterOrders
                          .Where(x => x.CreateDate >= qurey.FromDate && x.CreateDate <= qurey.ToDate)
                          .Select(Mapper.Map <FBAMasterOrder, FBAMasterOrderDto>);

            if (qurey.Reference.Count() == 0)
            {
                qureyStatusList.Add(new QureyStatus {
                    OrderType = "Inbound",
                    Reference = "NA",
                    Status    = "Success",
                    Message   = "No reference filter applied."
                });

                qureyStatus = qureyStatusList;

                if (qurey.Status == "" || qurey.Status == null || qurey.Status == "NA")
                {
                    return(results);
                }
                else
                {
                    return(results.Where(x => x.Status == qurey.Status));
                }
            }
            else
            {
                var qureyResults = new List <FBAMasterOrderDto>();

                foreach (var reference in qurey.Reference)
                {
                    var result = results.SingleOrDefault(x => x.Container == reference);

                    if (result == null)
                    {
                        qureyStatusList.Add(new QureyStatus
                        {
                            OrderType = "Inbound",
                            Reference = reference,
                            Status    = "Failed",
                            Message   = "Contianer: " + reference + " was not found in system."
                        });
                    }
                    else
                    {
                        qureyStatusList.Add(new QureyStatus
                        {
                            OrderType = "Inbound",
                            Reference = reference,
                            Status    = "Success",
                            Message   = "Container: " + reference + " existed in system."
                        });

                        qureyResults.Add(result);
                    }
                }

                qureyStatus = qureyStatusList;

                if (qurey.Status == "" || qurey.Status == null || qurey.Status == "NA")
                {
                    return(qureyResults);
                }
                else
                {
                    return(qureyResults.Where(x => x.Status == qurey.Status));
                }
            }
        }
        public IHttpActionResult GetOrderStatus([FromUri] string appKey, [FromUri] string customerCode, [FromUri] string requestId, [FromUri] string version, [FromUri] string sign, [FromBody] OrderStatusQureyBody body)
        {
            // 验证签名
            var customerInDb = _context.UpperVendors.SingleOrDefault(x => x.CustomerCode == customerCode);
            var jsonResult   = _validator.ValidateSign(appKey, customerInDb, requestId, version, sign);

            if (jsonResult.Code != 200)
            {
                return(Ok(jsonResult));
            }

            var qureyStauts = new List <QureyStatus>();

            if (body.OrderType == FBAOrderType.Inbound)
            {
                var qureyResults = QureyInboundOrders(body, out qureyStauts).Select(x => new { x.Container, x.Status });
                jsonResult.QureyStatus  = qureyStauts;
                jsonResult.QureyResults = new QureyResults {
                    InboundOrders = qureyResults
                };
            }
            else if (body.OrderType == FBAOrderType.Outbound)
            {
                var qureyResults = QureyOutboundOrders(body, out qureyStauts).Select(x => new { x.ShipOrderNumber, x.Status });
                jsonResult.QureyStatus  = qureyStauts;
                jsonResult.QureyResults = new QureyResults {
                    OutboundOrders = qureyResults
                };
            }
            else
            {
                jsonResult.Message = "No operation applied.";
            }

            return(Ok(jsonResult));
        }