Exemplo n.º 1
0
        public static List<Order> MakeOrder(orderListItem[] _orders)
        {
            List<Order> _innerOrders = new List<Order>();
            foreach (orderListItem oli in _orders)
            {
                if (Databases.serverModel.OrderSet.Where(x => x.Partner_site.Name == "Grando" && x.External_Id == oli.id).ToList().Count > 0)
                    continue;

                Random r = new Random();
                Order o = new Order();
                o.External_dealID = oli.productId;
                o.External_Id = oli.id;
                o.External_payment_mode = oli.payMethod;
                o.External_shipping_mode = oli.shippingType;
                o.Payment_mode = Databases.serverModel.Payment_associationSet.Where(x => x.Partner_siteName == "Grando" && x.External_value == o.External_payment_mode).FirstOrDefault().Payment_mode;
                o.Shipping_mode = Databases.serverModel.Shipping_associationSet.Where(x => x.Partner_siteName == "Grando" && x.External_value == o.External_shipping_mode).FirstOrDefault().Shipping_mode;
                o.Products_price = int.Parse(oli.productPrice);
                o.Shipping_price = int.Parse(oli.shippingFee);
                o.External_dealName = oli.productTitle;

                o.Date = DateTime.Now;
                o.Deleted = false;
                o.Email = oli.email;
                o.Phone = oli.shippingPhone;
                o.Pin = r.Next(1000, 9999);
                o.Priority = "Normál";
                o.Quantity = int.Parse(oli.productQuantity);

                Shipping_data sd = new Shipping_data();
                sd.Name = oli.shippingFamilyName + " " + oli.shippingGivenName;
                sd.Zip_code = int.Parse(oli.shippingZip);
                sd.City = oli.shippingCity;
                sd.Address = oli.shippingAddress;
                sd.Id = Globals.GetId("ISD");
                o.Shipping_data = sd;

                Billing_data bd = new Billing_data();
                bd.Name = oli.billingFamilyName + " " + oli.billingGivenName;
                bd.Zip_code = int.Parse(oli.billingZip);
                bd.Address = oli.billingAddress;
                bd.City = oli.billingCity;
                bd.Tax_number = "";
                bd.Id = Globals.GetId("IBD");
                o.Billing_data = bd;

                o.Created_by = Globals.ActualUser;
                o.Last_modified = DateTime.Now;
                o.Last_modified_by = Globals.ActualUser;
                o.Need_bill = true;
                o.Partner_site = Databases.serverModel.Partner_siteSet.Find("Grando");
                o.Properties = "";
                o.Comment = oli.info.Replace("\n", " ").Replace("\r\n", " ");
                o.Ready_to_labeling = false;
                o.Ready_to_ship = false;
                o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Feldolgozás alatt");
                o.History = DateTime.Now.ToString() + ": Feldolgozva"+ System.Environment.NewLine;
                o.Id = Globals.GetId("IRO");
                if (o.Payment_mode.Name == "Utánvét")
                    o.Transfer_completed = true;
                _innerOrders.Add(o);
            }
            return _innerOrders;
        }
Exemplo n.º 2
0
        public static int getOrders()
        {
            XDocument feedback = new XDocument();
            XElement root = new XElement("Feedback");
            root.SetAttributeValue("action",GruppiFeedbackAction.order_confirmation);
            Random r = new Random();
            Partner_site partner = Databases.serverModel.Partner_siteSet.Find("Gruppi Otthon");
            List<Order> _orders = new List<Order>();

            WebClient client = new WebClient();
            client.Credentials = new NetworkCredential("electroinvest", "ELectroInvestAuth2014");
            int count = 0;
            byte[] data;
            do
            {
                _orders = new List<Order>();
                try
                {
                    data = client.DownloadData("http://gruppiotthon.hu/adminisztracio/index.php?option=com_xadmin&controller=xml&task=electroInvestXml");
                }
                catch (Exception ex)
                {
                    return -1;
                }
                string s = Encoding.UTF8.GetString(data);
                XDocument xdoc = XDocument.Parse(s);

                foreach (XElement xe in xdoc.Element("orders").Elements("order"))
                {
                    string externalId = xe.Element("rendelesikod").Value;

                    List<Order> tempOrders = Databases.serverModel.OrderSet.Where(x => x.External_Id == externalId && x.Partner_site.Name == "Gruppi Otthon").ToList();
                    if (tempOrders.Count > 0)
                        continue;

                    Order o = new Order();
                    Billing_data bd = new Billing_data();
                    bd.Name = xe.Element("szamlazasinev").Value;
                    int irsz;
                    if (int.TryParse(xe.Element("szamlazasiirsz").Value.Trim().Replace(" ", ""), out irsz) == false)
                        irsz = 0;

                    o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Feldolgozás alatt");

                    bd.Zip_code = irsz;
                    bd.City = xe.Element("szamlazasivaros").Value;
                    bd.Address = xe.Element("szamlazasicim").Value;
                    bd.Tax_number = "";
                    bd.Id = Globals.GetId("IBD");

                    Shipping_data sd = new Shipping_data();
                    sd.Name = xe.Element("szallitasinev").Value;

                    if (int.TryParse(xe.Element("szallitasiirsz").Value.Trim().Replace(" ", ""), out irsz) == false)
                    {
                        irsz = 0;
                        o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Várakozik");

                    }
                    sd.Zip_code = irsz;
                    sd.City = xe.Element("szallitasivaros").Value;
                    sd.Address = xe.Element("szallitasicim").Value;
                    sd.Id = Globals.GetId("ISD");
                    string cityc = sd.City;
                    if (!Globals.CheckCityZip(ref cityc, sd.Zip_code))
                    {
                        sd.City = "?"+sd.City;
                        o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Várakozik");

                    }
                    else
                    {
                        sd.City = cityc;
                    }

                    o.Shipping_data = sd;
                    o.Billing_data = bd;
                    o.Phone = xe.Element("telefonszam").Value;
                    o.All_products_available = false;
                    o.All_products_selected = false;
                    o.Comment = "";
                    o.Created_by = Globals.ActualUser;
                    o.Date = DateTime.Parse(xe.Element("idopont").Value);
                    o.Deleted = false;
                    o.External_dealID = xe.Element("termekkod").Value;
                    o.External_dealName = xe.Element("termeknev").Value;
                    o.External_Id = xe.Element("rendelesikod").Value;
                    o.External_payment_mode = xe.Element("fizetesimod").Value;
                    o.External_shipping_mode = xe.Element("szallitasimod").Value;
                    o.Shipping_mode = partner.Shipping_associations.Where(x => x.External_value == o.External_shipping_mode).First().Shipping_mode;
                    o.Payment_mode = partner.Payment_associations.Where(x => x.External_value == o.External_payment_mode).First().Payment_mode;
                    o.History = DateTime.Now.ToString() + ": Feldolgozva" + System.Environment.NewLine;
                    o.Id = Globals.GetId("IRO");
                    o.Last_modified = DateTime.Now;
                    o.Last_modified_by = Globals.ActualUser;
                    o.Need_bill = true;
                    o.Partner_site = partner;
                    o.Pin = r.Next(1111, 9999);
                    o.Priority = "Normál";
                    o.Properties = xe.Element("variacio").Value;
                    o.Quantity = int.Parse(xe.Element("mennyiseg").Value);
                    o.Ready_to_labeling = false;
                    o.Ready_to_ship = false;
                    o.Transfer_completed = true;
                    o.Shipping_price = int.Parse(xe.Element("szallitas").Value);
                    o.Products_price = int.Parse(xe.Element("ar").Value);
                    _orders.Add(o);

                }

            if (Globals.AddOrders(_orders, Databases.serverModel))
            {
                feedback = new XDocument();
                root = new XElement("Feedback");
                root.SetAttributeValue("action", GruppiFeedbackAction.order_confirmation);
                count += _orders.Count;
                int gruppiCount = 0;
                foreach (Order o in _orders)
                {
                    XElement order = new XElement("order");
                    order.Add(new XElement("order_id", o.External_Id));
                    order.Add(new XElement("iris_order_id", o.Id));
                    root.Add(order);
                    gruppiCount++;
                }
                if (gruppiCount > 0)
                {
                    feedback.Add(root);
                    sendFeedback(feedback);
                }
            }
            else count = -1;

            }
            while (_orders.Count == 100);

            return count;
        }
Exemplo n.º 3
0
        public static int getOrders()
        {
            Random r = new Random();
            Partner_site partner = Databases.serverModel.Partner_siteSet.Find("Deal24");
            string dateFrom;
            if (partner.Last_sync != null)
            {
                dateFrom = partner.Last_sync.Value.Date.ToShortDateString();
            }
            else
                dateFrom = DateTime.Now.Date.ToShortDateString();
            dateFrom = dateFrom.Remove(dateFrom.Length - 1, 1).Replace(".","-");

            string dateTo = DateTime.Now.Date.AddDays(1).ToShortDateString();
            dateTo = dateTo.Remove(dateTo.Length - 1, 1).Replace(".", "-");
            List<Order> _orders = new List<Order>();
            WebClient client = new WebClient();
            byte[] data;
            try
            {
                data = client.DownloadData("http://deal24.hu/transactions/list_buyers?api&from=" + dateFrom + "&to=" + dateTo);
            }
            catch (Exception ex)
            {
                return -1;
            }
            string s = Encoding.UTF8.GetString(data);
            if(s.Length>0)
            s = s.Remove(s.Length-1,1);
            string[] externalOrders = s.Split('\n').Skip(1).ToArray();

            foreach(string externalOrder in externalOrders)
            {

                string[] temp = externalOrder.Split(';');

                if (temp[16] != "Electro Invest Kft" && temp[16] != "Napiajánlat")
                    continue;

                string extId = temp[17];
                List<Order> tempOrders = Databases.serverModel.OrderSet.Where(x => x.External_Id == extId).ToList();
                if(tempOrders.Count>0)
                    continue;
                Order o = new Order();
                Shipping_data sd = new Shipping_data();
                Billing_data bd = new Billing_data();
                sd.Zip_code = int.Parse(temp[7]);
                sd.City = temp[6];
                sd.Address = temp[8];
                sd.Name = temp[10];
                sd.Id = Globals.GetId("ISD");
                o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Feldolgozás alatt");

                string cityc = sd.City;
                if (!Globals.CheckCityZip(ref cityc, sd.Zip_code))
                {
                    sd.City = "?" + sd.City;
                    o.System_order_status = Databases.serverModel.System_order_statusSet.Find("Várakozik");

                }
                else
                {
                    sd.City = cityc;
                }

                bd.Name = sd.Name;
                bd.Address = sd.Address;
                bd.City = sd.City;
                bd.Name = sd.Name;
                bd.Zip_code = sd.Zip_code;
                bd.Id = Globals.GetId("IBD");

                o.Billing_data = bd;
                o.Shipping_data = sd;

                o.External_payment_mode = temp[13];
                o.External_shipping_mode = "Futárszolgálat";
                o.Shipping_mode = partner.Shipping_associations.Where(x=>x.External_value==o.External_shipping_mode).First().Shipping_mode;
                o.Payment_mode = partner.Payment_associations.Where(x=>x.External_value == o.External_payment_mode).First().Payment_mode;

                o.Email = temp[11];
                o.External_dealID = temp[1];
                o.External_dealName = temp[1];
                o.External_Id = extId;
                o.Quantity = int.Parse(temp[2]);
                o.Products_price = int.Parse(temp[3]) * o.Quantity;
                o.Shipping_price = int.Parse(temp[4]);
                o.Phone = temp[9];

                o.All_products_available=false;
                o.All_products_selected = false;
                o.Comment ="";
                o.Created_by = Globals.ActualUser;
                o.Date = DateTime.Parse(temp[15]);
                o.Deleted=false;
                o.Id = Globals.GetId("IRO");
                o.Last_modified =DateTime.Now;
                o.Last_modified_by = Globals.ActualUser;
                o.Need_bill = true;
                o.Partner_site = partner;
                o.Pin = r.Next(1111, 9999);
                o.Priority = "Normál";
                o.Properties = "";
                o.Ready_to_labeling = false;
                o.Ready_to_ship = false;
               // o.Transfer_completed = temp[12] == "waiting" ? false : true;,
                o.Transfer_completed = true;
                o.History = DateTime.Now.ToString() + ": Feldolgozva" + System.Environment.NewLine;
                _orders.Add(o);

            }
            if (Globals.AddOrders(_orders, Databases.serverModel))
            {
                partner.Last_sync = DateTime.Now.Subtract(new TimeSpan(0, 10, 0));
                //Databases.serverModel.SaveChanges();
                return _orders.Count;
            }
            else
                return -1;
        }