Exemple #1
0
        public static int GetPackageId()
        {

            var client = new HttpClient();

            List<Package> _packages = Databases.serverModel.PackageSet.Where(x=> x.Package_id == null).ToList();

            foreach (Package p in _packages)
            {
                if (p.Shipping_company == "Media-log2")
                {
                    userName = userName2;
                    userId = userId2;
                    password = password2;

                }
                else
                {
                    userName = userName1;
                    userId = userId1;
                    password = password1;

                }
                MediaLogBarcodePackage package = new MediaLogBarcodePackage();
                package.user = userId;
                package.package = new MediaLogBarcodePack { package_id = p.Temporary_package_id };
                package.convert = 1;
                string json = JsonConvert.SerializeObject(package);
                
                
                MultipartFormDataContent form = new MultipartFormDataContent();
                StringContent cont = new StringContent(json);
                form.Add(new StringContent(json), "pack");
                HttpResponseMessage response = client.PostAsync("https://csomag.media-log.hu/packages/webservice_get_mlog_orderid", form).Result;

                response.EnsureSuccessStatusCode();
                string sd = response.Content.ReadAsStringAsync().Result;//164058, 000000000009
                if (sd.StartsWith("OK"))
                {
                    p.Package_id = sd.Remove(0, 4);
                    p.Labeled = true;
                    Databases.serverModel.SaveChanges();
                }
                else
                {
                    //gáz van
                }
            }
            return 0;
        }
Exemple #2
0
        public static int GetPackagesStatus()
        {
            var client = new HttpClient();
            DateTime minDate = DateTime.Now.Subtract(new TimeSpan(10, 0, 0, 0));
            List<Package> _packages = Databases.serverModel.PackageSet.Where(x => x.Labeled == true && !x.Status.Contains("Megbízónak visszaszállítva") && !x.Status.Contains("Kézbesítve") && x.Package_id != null && x.Date > minDate).ToList();

            foreach (Package p in _packages)
            {
                if (p.Shipping_company == "Media-log2")
                {
                    userName = userName2;
                    userId = userId2;
                    password = password2;

                }
                else
                {
                    userName = userName1;
                    userId = userId1;
                    password = password1;

                }

                MediaLogBarcodePackage package = new MediaLogBarcodePackage();
                package.user = userId;
                package.package = new MediaLogBarcodePack { package_id = p.Temporary_package_id };
                string json = JsonConvert.SerializeObject(package);

                MultipartFormDataContent form = new MultipartFormDataContent();
                StringContent cont = new StringContent(json);
                form.Add(new StringContent(json), "pack");
                HttpResponseMessage response = client.PostAsync("https://csomag.media-log.hu/packages/get_status", form).Result;
                response.EnsureSuccessStatusCode();
                string sd = response.Content.ReadAsStringAsync().Result;//164058, 000000000009
                if (sd.StartsWith("OK"))
                {
                    string[] s = p.Status.Split('\n');
                    if (s.Last().Replace("\r", "").Split(';').Last() != " " + sd.Remove(0, 4))
                    {
                        p.Status += System.Environment.NewLine + DateTime.Now.ToString() + "; " + sd.Remove(0, 4);
                        Databases.serverModel.SaveChanges();
                    }
                }
                else
                {
                    //gáz van
                }
            }
                return 0;
        }