コード例 #1
0
        public static int updateProductsBySku(Guid skuId)
        {
            dbDekkOnlineDataContext db = new dbDekkOnlineDataContext();
            string token = generateToken();
            string url   = dekkProURL + "/GetProducts?";

            url += "request.productSkuIds=" + skuId;

            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

            myReq.Accept      = "application/json";
            myReq.ContentType = "application/json";
            //myReq.Method = "POST";
            myReq.Headers["Authorization"] = "Bearer " + token;
            WebResponse  wr            = myReq.GetResponse();
            Stream       receiveStream = wr.GetResponseStream();
            StreamReader reader        = new StreamReader(receiveStream, Encoding.UTF8);
            //string content = reader.ReadToEnd();
            string     json      = reader.ReadToEnd();
            productsDP lis       = JsonConvert.DeserializeObject <productsDP>(json);
            int        inventory = 0;
            var        pdp       = lis.productDP.FirstOrDefault();

            var cBrands = db.brands.ToList();

            string error = "";

            try
            {
                dkGeneralInformation dgi = pdp.GeneralInformation;
                dkTireInformation    dti = pdp.TireInformation;
                dkCategory           dca = pdp.Category;
                dkBrand   dbr            = pdp.Brand;
                dkPricing dbp            = pdp.Pricing;
                Guid      proUUID        = dgi.ProductId;



                try { inventory = pdp.Inventory.Sum(c => c.AvailableUnits); } catch { }



                string fuel  = "";
                string wet   = "";
                string noise = "";
                string speed = "";
                try
                {
                    var FWD = dti.Description.Split('-').ToList();
                    try { fuel = FWD[0].Replace(" ", "").Substring(FWD[0].IndexOf(':') + 1); } catch { }
                    try { wet = FWD[1].Replace(" ", ""); } catch { }
                    try { noise = FWD[2].Replace(" ", ""); } catch { }
                    try { speed = dti.Speed; } catch { }
                }
                catch
                {
                }
                if (fuel.Length > 5)
                {
                    fuel = fuel.Substring(0, 4);
                }
                if (wet.Length > 5)
                {
                    wet = wet.Substring(0, 4);
                }

                if (noise.Length > 5)
                {
                    noise = noise.Substring(0, 4);
                }

                //if (speed == "") continue;



                product nProd = new product();
                var     cProd = db.products.Where(c => c.proSkuId == skuId);
                if (cProd.FirstOrDefault() != null)
                {
                    nProd = cProd.FirstOrDefault();
                }


                nProd.proUUID = dgi.ProductId;

                Guid cdpId = Guid.Parse(dca.ProductCategoryId);

                nProd.cdpId = cdpId;
                Guid braId = Guid.Parse(dbr.BrandId);
                if (cBrands.Where(c => c.braId == braId).Count() == 0)
                {
                    brand nBra = new brand();
                    nBra.braId            = Guid.Parse(dbr.BrandId);
                    nBra.braCode          = dbr.Code;
                    nBra.braName          = dbr.Name;
                    nBra.braNameDP        = dbr.Name;
                    nBra.braCodeDP        = dbr.Code;
                    nBra.barDescriptionDP = "";
                    nBra.braDescription   = "";
                    nBra.braImage         = "";
                    nBra.braEdited        = false;
                    db.brands.InsertOnSubmit(nBra);
                    nProd.brand = nBra;
                }
                else
                {
                    nProd.braId = braId;
                }

                try { nProd.proSkuId = Guid.Parse(dti.ProductSkuId); } catch { }
                nProd.proSkuDP = dti.SkuCode;
                if (nProd.proSkuDP == null)
                {
                    nProd.proSkuDP = "";
                }
                nProd.proNameDP        = dgi.Name;
                nProd.proDescriptionDP = dgi.Name;
                nProd.proCodeDP        = dti.Code;
                try { nProd.proDimensionProfileDP = int.Parse(dti.Dimension.Profile.Replace(".00", "")); } catch { };
                try { nProd.proDimensionWidthDP = int.Parse(dti.Dimension.Width.Replace(".00", "")); } catch { };
                try { nProd.proDimensionDiameterDP = int.Parse(dti.Dimension.Diameter.Replace(".00", "")); } catch { };
                nProd.proCoverPriceDP     = dbp.CoverPrice;
                nProd.proSuggestedPriceDP = dbp.SuggestedPrice;
                nProd.proRCRDP            = dti.RollerCircumReference;
                nProd.proLoadIndexDP      = dti.LoadIndex;
                nProd.proSpeedDP          = dti.Speed;
                nProd.proProductCodeDP    = dgi.ProductCode;
                nProd.proFuelDP           = fuel;
                nProd.proWetDP            = wet;
                nProd.proNoiseDP          = noise;
                string tyreSize = nProd.proDimensionWidthDP.ToString() + nProd.proDimensionProfileDP.ToString() + nProd.proDimensionDiameterDP.ToString();
                nProd.proLastUpdateDP = DateTime.Now;
                if (tyreSize.Length > 10)
                {
                    tyreSize = tyreSize.Substring(0, 9);
                }

                nProd.proTyreSizeDP = tyreSize;

                if (nProd.proEdited != true)
                {
                    nProd.proSku               = nProd.proSkuDP;
                    nProd.proName              = nProd.proNameDP;
                    nProd.proDescription       = nProd.proDescriptionDP;
                    nProd.proCode              = nProd.proCodeDP;
                    nProd.proDimensionProfile  = nProd.proDimensionProfileDP;
                    nProd.proDimensionWidth    = nProd.proDimensionWidthDP;
                    nProd.proDimensionDiameter = nProd.proDimensionDiameterDP;
                    nProd.proCoverPrice        = nProd.proCoverPriceDP;
                    nProd.proSuggestedPrice    = nProd.proSuggestedPriceDP;
                    nProd.proRCR               = nProd.proRCRDP;
                    nProd.proLoadIndex         = nProd.proLoadIndexDP;
                    nProd.proSpeed             = nProd.proSpeedDP;
                    nProd.proProductCode       = nProd.proProductCodeDP;
                    nProd.proFuel              = nProd.proFuelDP;
                    nProd.proWet               = nProd.proWetDP;
                    nProd.proNoise             = nProd.proNoiseDP;
                    nProd.proTyreSize          = nProd.proTyreSizeDP;
                    nProd.proEdited            = false;
                    nProd.proStatus            = true;
                    nProd.proImage             = "";
                }

                nProd.proInventory = inventory;
            }
            catch (Exception ex)
            {
                error += ex.ToString() + " | ";
            }

            db.SubmitChanges();

            return(inventory);
        }
コード例 #2
0
        public static void updateProductsByCategory(List <string> categories, ref int updates, ref int news, string find = "")
        {
            dbDekkOnlineDataContext db = new dbDekkOnlineDataContext();
            string token = generateToken();
            string url   = dekkProURL + "/GetProducts?";

            url += "request.timeStampFrom=" + lastUpdate.ToString("yyyy-MM-ddTHH:mm:ss") + "&";
            foreach (string cat in categories)
            {
                url += "request.productCategoryIds=" + cat + "&";
            }
            url = url.TrimEnd('&');
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

            myReq.Accept      = "application/json";
            myReq.ContentType = "application/json";
            //myReq.Method = "POST";
            myReq.Headers["Authorization"] = "Bearer " + token;
            WebResponse  wr            = myReq.GetResponse();
            Stream       receiveStream = wr.GetResponseStream();
            StreamReader reader        = new StreamReader(receiveStream, Encoding.UTF8);
            //string content = reader.ReadToEnd();
            string     json = reader.ReadToEnd();
            productsDP lis  = JsonConvert.DeserializeObject <productsDP>(json);

            int count  = 0;
            int nCount = 0;

            var cProds = (from pro in db.products
                          where categories.Contains(pro.categoriesDP.cdpId.ToString())
                          select pro).ToList();

            var cBrands = db.brands.ToList();

            string error = "";

            foreach (productDP pdp in lis.productDP)
            {
                try
                {
                    dkGeneralInformation dgi = pdp.GeneralInformation;
                    dkTireInformation    dti = pdp.TireInformation;
                    dkCategory           dca = pdp.Category;
                    dkBrand   dbr            = pdp.Brand;
                    dkPricing dbp            = pdp.Pricing;
                    Guid      proUUID        = dgi.ProductId;

                    bool findProduct = false;
                    if (dti.Code == find)
                    {
                        findProduct = true;
                    }
                    if (findProduct)
                    {
                        Console.Write(dgi.ProductId);
                    }
                    int inventory = 0;
                    try
                    {
                        string cdpIdCheck = dca.ProductCategoryId.ToUpper();
                        if (!categories.Contains(cdpIdCheck))
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        continue;
                    }



                    try { inventory = pdp.Inventory.Sum(c => c.AvailableUnits); } catch { }



                    string fuel  = "";
                    string wet   = "";
                    string noise = "";
                    string speed = "";
                    try
                    {
                        var FWD = dti.Description.Split('-').ToList();
                        try { fuel = FWD[0].Replace(" ", "").Substring(FWD[0].IndexOf(':') + 1); } catch { }
                        try { wet = FWD[1].Replace(" ", ""); } catch { }
                        try { noise = FWD[2].Replace(" ", ""); } catch { }
                        try { speed = dti.Speed; } catch { }
                    }
                    catch
                    {
                    }
                    if (fuel.Length > 5)
                    {
                        fuel = fuel.Substring(0, 4);
                    }
                    if (wet.Length > 5)
                    {
                        wet = wet.Substring(0, 4);
                    }

                    if (noise.Length > 5)
                    {
                        noise = noise.Substring(0, 4);
                    }

                    //if (speed == "") continue;



                    product nProd = new product();
                    var     cProd = cProds.Where(c => c.proUUID == proUUID);
                    if (cProd.FirstOrDefault() != null)
                    {
                        nProd = cProd.FirstOrDefault();
                    }
                    else
                    {
                        nCount++;
                        db.products.InsertOnSubmit(nProd);
                    }

                    nProd.proUUID = dgi.ProductId;

                    Guid cdpId = Guid.Parse(dca.ProductCategoryId);

                    nProd.cdpId = cdpId;
                    Guid braId = Guid.Parse(dbr.BrandId);
                    if (cBrands.Where(c => c.braId == braId).Count() == 0)
                    {
                        brand nBra = new brand();
                        nBra.braId            = Guid.Parse(dbr.BrandId);
                        nBra.braCode          = dbr.Code;
                        nBra.braName          = dbr.Name;
                        nBra.braNameDP        = dbr.Name;
                        nBra.braCodeDP        = dbr.Code;
                        nBra.barDescriptionDP = "";
                        nBra.braDescription   = "";
                        nBra.braImage         = "";
                        nBra.braEdited        = false;
                        db.brands.InsertOnSubmit(nBra);
                        nProd.brand = nBra;
                    }
                    else
                    {
                        nProd.braId = braId;
                    }

                    try { nProd.proSkuId = Guid.Parse(dti.ProductSkuId); } catch { }
                    nProd.proSkuDP = dti.SkuCode;
                    if (nProd.proSkuDP == null)
                    {
                        nProd.proSkuDP = "";
                    }
                    nProd.proNameDP        = dgi.Name;
                    nProd.proDescriptionDP = dgi.Name;
                    nProd.proCodeDP        = dti.Code;
                    try { nProd.proDimensionProfileDP = int.Parse(dti.Dimension.Profile.Replace(".00", "")); } catch { };
                    try { nProd.proDimensionWidthDP = int.Parse(dti.Dimension.Width.Replace(".00", "")); } catch { };
                    try { nProd.proDimensionDiameterDP = int.Parse(dti.Dimension.Diameter.Replace(".00", "")); } catch { };
                    nProd.proCoverPriceDP     = dbp.CoverPrice;
                    nProd.proSuggestedPriceDP = dbp.SuggestedPrice;
                    nProd.proRCRDP            = dti.RollerCircumReference;
                    nProd.proLoadIndexDP      = dti.LoadIndex;
                    nProd.proSpeedDP          = dti.Speed;
                    nProd.proProductCodeDP    = dgi.ProductCode;
                    nProd.proFuelDP           = fuel;
                    nProd.proWetDP            = wet;
                    nProd.proNoiseDP          = noise;
                    string tyreSize = nProd.proDimensionWidthDP.ToString() + nProd.proDimensionProfileDP.ToString() + nProd.proDimensionDiameterDP.ToString();
                    nProd.proLastUpdateDP = DateTime.Now;
                    if (tyreSize.Length > 10)
                    {
                        tyreSize = tyreSize.Substring(0, 9);
                    }

                    nProd.proTyreSizeDP = tyreSize;

                    if (nProd.proEdited != true)
                    {
                        nProd.proSku               = nProd.proSkuDP;
                        nProd.proName              = nProd.proNameDP;
                        nProd.proDescription       = nProd.proDescriptionDP;
                        nProd.proCode              = nProd.proCodeDP;
                        nProd.proDimensionProfile  = nProd.proDimensionProfileDP;
                        nProd.proDimensionWidth    = nProd.proDimensionWidthDP;
                        nProd.proDimensionDiameter = nProd.proDimensionDiameterDP;
                        nProd.proCoverPrice        = nProd.proCoverPriceDP;
                        nProd.proSuggestedPrice    = nProd.proSuggestedPriceDP;
                        nProd.proRCR               = nProd.proRCRDP;
                        nProd.proLoadIndex         = nProd.proLoadIndexDP;
                        nProd.proSpeed             = nProd.proSpeedDP;
                        nProd.proProductCode       = nProd.proProductCodeDP;
                        nProd.proFuel              = nProd.proFuelDP;
                        nProd.proWet               = nProd.proWetDP;
                        nProd.proNoise             = nProd.proNoiseDP;
                        nProd.proTyreSize          = nProd.proTyreSizeDP;
                        nProd.proEdited            = false;
                        nProd.proStatus            = true;
                        nProd.proImage             = "";
                    }

                    nProd.proInventory = inventory;
                    count++;
                }
                catch (Exception ex)
                {
                    error += ex.ToString() + " | ";
                }
            }
            db.tokens.FirstOrDefault().tokStockLastUpdate = DateTime.Now;
            db.SubmitChanges();

            count   = count - nCount;
            news    = nCount;
            updates = count;
        }