Beispiel #1
0
        public List <Order> GetListFromSAP(string customerNumber, string documentDate, string documentDateTo, string salesOrg)
        {
            List <Order> orderList = new List <Order>();

            try
            {
                // Get Status Info Collection
                CustDataCollection customerDataCollection = GetList(customerNumber, documentDate, documentDateTo, salesOrg);

                foreach (var orederHeader in customerDataCollection.d.results)
                {
                    var date = DateTime.ParseExact(orederHeader.DocumentDate,
                                                   "yyyyMMdd",
                                                   CultureInfo.InvariantCulture);
                    foreach (var orderItem in orederHeader.Cust2SalesNav.results)
                    {
                    }
                }
                // TODO : Map Get List to Order List
            }
            catch (Exception)
            {
                throw;
            }

            return(orderList);
        }
Beispiel #2
0
        private CustDataCollection GetList(string customerNumber, string documentDate, string documentDateTo, string salesOrg)
        {
            // Get List as per below inputs
            // {0} Customer Number
            // {1} Document Date
            // {2} Document DateTo
            // {3} Material Number
            // {4} Sales Org

            //string requestURL = "https://gq1.sap.sca.se:443/sap/opu/odata/sap/ZBAPI_SALESORDER_GETLIST_SRV/CustDataSet?$format=json&$expand=Cust2SalesNav&$filter=CustomerNumber eq '0000008542' and DocumentDate eq '20160606' and DocumentDateTo eq '20161206' and SalesOrganization eq 'BE68'&sap-client=006&sap-language=EN";

            //string requestURL = "https://gq1.sap.sca.se:443/sap/opu/odata/sap/ZBAPI_SALESORDER_GETLIST_SRV/CustDataSet?$format=json&$expand=Cust2SalesNav&$filter=CustomerNumber eq '11324' and DocumentDate eq '20160501' and DocumentDateTo eq '20160731' and SalesOrganization eq 'NL68'&sap-client=006&sap-language=EN";
            string          requestURL = string.Format(sapGetListURL, customerNumber, documentDate, documentDateTo, salesOrg);
            HttpWebRequest  req        = (HttpWebRequest)WebRequest.Create(requestURL);
            HttpWebResponse resp; // No Use

            req.Credentials = new NetworkCredential(sapUserName, sapPassword);
            req.Method      = "GET";
            req.Headers.Add("X-CSRF-Token", "Fetch");
            req.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            cookieJar             = new CookieContainer();
            req.CookieContainer   = cookieJar;
            CustDataCollection collection = null;

            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var rawJson = new StreamReader(response.GetResponseStream()).ReadToEnd();

                    collection = JsonConvert.DeserializeObject <CustDataCollection>(rawJson);
                    var    dat1 = collection.d.results[0].Cust2SalesNav.results;
                    string a    = "";
                    string b    = null;
                    dat1 = dat1.Where(q => q.ReqSegment.Equals(a)).ToList();
                    dat1 = dat1.Where(q => q.SalesOrg.Equals(b)).ToList();

                    csrfToken     = response.Headers.GetValues("X-CSRF-TOKEN").FirstOrDefault();
                    setCookie     = response.Headers.Get("Set-Cookie");
                    cookiestopass = response.Cookies;
                }
            }
            return(collection);
        }