コード例 #1
0
        private object GetQueryObject(string startDate, string endDate, string customerNumber, List <string> pos, int total = 0, string threadID = "", string poNumber = "")
        {
            object queryObj;
            var    phrasePrefix = !string.IsNullOrEmpty(customerNumber) || !string.IsNullOrEmpty(threadID) || !string.IsNullOrEmpty(poNumber);
            var    must_not     = new List <object>
            {
                new
                {
                    match = new
                    {
                        Transaction = "Punchout"
                    }
                }
            };
            var sort = new SortField
            {
                Date = new OrderDate
                {
                    order = "desc"
                }
            };
            var must = new List <object>();

            if (!string.IsNullOrEmpty(customerNumber))
            {
                must.Add(new { match_phrase_prefix = new matchIdentity {
                                   Identity = customerNumber
                               } });
            }
            if (!string.IsNullOrEmpty(threadID))
            {
                must.Add(new { match_phrase_prefix = new { ThreadID = threadID } });
            }
            if (!string.IsNullOrEmpty(poNumber))
            {
                must.Add(new { match_phrase_prefix = new matchPONumber {
                                   PONumber = poNumber
                               } });
            }

            must.Add(new { range = new range {
                               Date = new Date {
                                   gte = startDate, lte = endDate, time_zone = "+00:00"
                               }
                           } });

            queryObj = new queryWithBoolMust
            {
                boole = new booleWithMust
                {
                    must     = must,
                    filter   = new { terms = new { ThreadID = pos } },
                    must_not = must_not
                }
            };
            return(queryObj);
        }
コード例 #2
0
        public async Task <string> GetPOS(ExportToExcelInput input, List <string> searchFor = null)
        {
            string startDate      = input.StartDate;
            string endDate        = input.EndDate;
            string customerNumber = input.CustomerNumber;
            int    size           = input.Size;
            int    page           = input.Page;
            string threadID       = input.ThreadId;
            string poNumber       = input.PONumber;
            string sortcolumn     = !string.IsNullOrEmpty(input.SortColumn) ? input.SortColumn.ToLower() : "";

            string result     = string.Empty;
            var    uri        = GetURI(CONSTANTS.submittedpodetails);
            var    httpClient = new HttpClient();
            object query;


            var phrasePrefix = !string.IsNullOrEmpty(customerNumber) || !string.IsNullOrEmpty(threadID) || !string.IsNullOrEmpty(poNumber);
            var must_not     = new List <object>
            {
                new
                {
                    match = new
                    {
                        Transaction = "Punchout"
                    }
                }
            };
            object sort;

            switch (sortcolumn)
            {
            case "threaid":
                sort = new SortFieldWithThreadId
                {
                    ThreadID = input.SortOrder
                };
                break;

            case "ponumber":
                sort = new SortFieldWithPONumber
                {
                    PONumber = input.SortOrder
                };
                break;

            default:
                sort = new SortField
                {
                    Date = new OrderDate
                    {
                        order = "desc"
                    }
                };
                break;
            }



            var must   = new List <object>();
            var should = new List <object>();

            if (!string.IsNullOrEmpty(customerNumber))
            {
                must.Add(new { match_phrase_prefix = new matchIdentity {
                                   Identity = customerNumber
                               } });
            }
            if (!string.IsNullOrEmpty(threadID))
            {
                must.Add(new { match = new { ThreadID = threadID } });
            }
            if (!string.IsNullOrEmpty(poNumber))
            {
                must.Add(new { match_phrase_prefix = new matchPONumber {
                                   PONumber = poNumber
                               } });
            }

            must.Add(new { range = new range {
                               Date = new Date {
                                   gte = startDate, lte = endDate, time_zone = "+00:00"
                               }
                           } });
            if (phrasePrefix)
            {
                query = new queryWithBoolMust
                {
                    boole = new booleWithMust
                    {
                        should = should,
                        must   = must
                                 //  must_not = must_not
                    }
                };
            }
            else
            {
                query = new querywithmustnotbool
                {
                    boole = new boolWithMustNot
                    {
                        must     = must,
                        must_not = must_not
                    }
                };
            }


            var response = httpClient.PostAsJsonAsync(uri, new
            {
                _source = (searchFor != null) ? searchFor : new List <string> {
                    "ThreadID", "ThreadId"
                },
                sort  = new { Date = new { order = "desc" } },
                from  = page,
                size  = size,
                query = query
            }).Result;


            //will throw an exception if not successful
            response.EnsureSuccessStatusCode();

            result = await response.Content.ReadAsStringAsync();

            return(result);
        }