public CustomerResult Post(ExportToExcelInput input)
        {
            string startDate      = input.StartDate;
            string endDate        = input.EndDate;
            string customerNumber = input.CustomerNumber;
            int    size           = input.Size == 0 ? 100 : input.Size;
            int    page           = input.Page;
            string threadID       = !(string.IsNullOrEmpty(input.ThreadId)) ? input.ThreadId : "";
            string poNumber       = !(string.IsNullOrEmpty(input.PONumber)) ? input.PONumber : "";


            serviceCaller.size = size;
            serviceCaller.from = page;

            CustomerResult result    = new CustomerResult();
            var            lstResult = new List <GetCustomerResult>();

            var pos             = serviceCaller.GetPOS(input);
            var poNumbersSource = JsonConvert.DeserializeObject <PurchaseOrderResult>(pos.Result);
            var poNumbers       = poNumbersSource.hits.hits.Where(x => x._source.ThreadID != null).Select(x => x._source.ThreadID).ToList();

            result.Total = poNumbersSource.hits.total;
            var response  = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, threadID: threadID);
            var objResult = JsonConvert.DeserializeObject <PurchaseOrderResult>(response.Result);

            if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
            {
                //int total = objResult.hits.total;
                //response = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, total);
                //objResult = JsonConvert.DeserializeObject<PurchaseOrderResult>(response.Result);
                if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
                {
                    var group = (from p in objResult.hits.hits.ToList()

                                 //where string.IsNullOrEmpty(id) || p._source.Identity.Contains(id)
                                 group p by new { ThreadID = p._source.ThreadID } into g
                                 select new { ThreadId = g.Key.ThreadID, POResult = g.ToList() }).ToList();

                    foreach (var item in group)
                    {
                        var lstOfSteps = purchaseOrderStatusRetriever.GetSteps(item.POResult.ToList());
                        var po         = item.POResult.Where(x => !string.IsNullOrEmpty(x._source.PONumber)).Count() > 0 ? item.POResult.Where(x => !string.IsNullOrEmpty(x._source.PONumber)).FirstOrDefault()._source.PONumber : "";
                        var identity   = item.POResult.Where(x => x._source != null && x._source.Identity != null).FirstOrDefault();
                        lstResult.Add(new GetCustomerResult
                        {
                            ProfileID  = identity != null ? identity._source.Identity : "",
                            lstOfSteps = lstOfSteps,
                            PONumber   = po,
                            ThreadID   = item.ThreadId
                        });
                    }
                    //result.Total = objResult.hits.total;
                    result.lst = lstResult;
                }
            }
            return(result);
        }
示例#2
0
        public ExcelResult Post(ExportToExcelInput input)
        {
            try
            {
                string startDate      = input.StartDate;
                string endDate        = input.EndDate;
                string customerNumber = input.CustomerNumber;
                int    size           = input.Size == 0 ? 100 : input.Size;
                int    page           = input.Page;
                string threadID       = !(string.IsNullOrEmpty(input.ThreadId)) ? input.ThreadId : "";
                string poNumber       = !(string.IsNullOrEmpty(input.PONumber)) ? input.PONumber : "";

                serviceCaller.size = size;
                serviceCaller.from = page;

                ExcelResult result    = new ExcelResult();
                var         lstResult = new List <GetExcelResult>();

                var pos             = serviceCaller.GetPOS(input);
                var poNumbersSource = JsonConvert.DeserializeObject <PurchaseOrderResult>(pos.Result);
                var poNumbers       = poNumbersSource.hits.hits.Where(x => x._source.ThreadID != null).Select(x => x._source.ThreadID).ToList();
                result.Total = poNumbersSource.hits.total;
                var response  = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, threadID: threadID);
                var objResult = JsonConvert.DeserializeObject <PurchaseOrderResult>(response.Result);
                if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
                {
                    //int total = objResult.hits.total;
                    //response = serviceCaller.SearchForGivenInput(startDate, endDate, customerNumber, poNumbers, total);
                    //objResult = JsonConvert.DeserializeObject<PurchaseOrderResult>(response.Result);
                    if (objResult != null && objResult.hits != null & objResult.hits.hits != null)
                    {
                        var group = (from p in objResult.hits.hits.ToList()

                                     //where string.IsNullOrEmpty(id) || p._source.Identity.Contains(id)
                                     group p by new { p._source.ThreadID, p._source.PONumber } into g
                                     select new { ThreadId = g.Key.ThreadID, PONumber = g.Key.PONumber, POResult = g.ToList() }).ToList();

                        foreach (var item in group)
                        {
                            if (!string.IsNullOrEmpty(input.PONumber))
                            {
                                if (!item.PONumber.Equals(input.PONumber, StringComparison.OrdinalIgnoreCase))
                                {
                                    break;
                                }
                            }


                            var selectedSendPurchaseOrder = item.POResult.Where(x => x._type == CONSTANTS.sendPurchaseOrderstatus).ToList();
                            var date = item.POResult.Max(x => x._source.Date);

                            if (selectedSendPurchaseOrder != null && selectedSendPurchaseOrder.Count > 0)
                            {
                                foreach (var sendPO in selectedSendPurchaseOrder)
                                {
                                    var lstOfSteps = purchaseOrderStatusRetriever.GetStepsForExcel(item.POResult.ToList(), sendPO);

                                    lstResult.Add(new GetExcelResult
                                    {
                                        lstOfSteps = lstOfSteps,
                                        PONumber   = item.PONumber,
                                        ThreadID   = item.ThreadId,
                                        Date       = date
                                    });
                                }
                            }
                            else
                            {
                                var lstOfSteps = purchaseOrderStatusRetriever.GetStepsForExcel(item.POResult.ToList(), null);

                                lstResult.Add(new GetExcelResult
                                {
                                    lstOfSteps = lstOfSteps,
                                    PONumber   = item.PONumber,
                                    ThreadID   = item.ThreadId,
                                    Date       = date
                                });
                            }
                        }
                        //result.Total = objResult.hits.total;
                        result.lst = lstResult;
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(new ExcelResult {
                    Message = ex.Message + Environment.NewLine + ex.StackTrace
                });
                //System.IO.File.AppendAllText(@"E:\inetpub\wwwroot\b2bdiceapiprod\bin\\ErrorText.txt", ex.Message + DateTime.Now + Environment.NewLine);
                // throw;
            }
        }