Ejemplo n.º 1
0
        public void SaveProductData(Product Record, int matchedArticleId)
        {
            decimal castedShipCost;
            decimal castedPrice;
            if (!(decimal.TryParse(Record.DeliveryCost, NumberStyles.Any, CultureInfo.InvariantCulture, out castedShipCost))) { }
            if (!(decimal.TryParse(Record.Price, NumberStyles.Any, CultureInfo.InvariantCulture, out castedPrice))) { }

            webshop webshop = _context.webshop.Where(w => w.url == Record.Webshop).FirstOrDefault();

            if (webshop == default(webshop))
            {
                Console.WriteLine("Could not find webshop {0}, aborting the save.", Record.Webshop);
                return;
            }

            product product = new product
            {
                article_id = matchedArticleId,
                ship_time = Record.DeliveryTime,
                ship_cost = (decimal?)castedShipCost,
                price = castedPrice,
                webshop_url = webshop.url,
                direct_link = Record.Url,
                affiliate_name = Record.Affiliate,
                affiliate_unique_id = Record.AffiliateProdID
            };

            _context.product.Add(product);
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void SaveNewArticle(Product Record, int countryId)
        {
            country cou = _context.country.Where(c => c.id == countryId).FirstOrDefault();
            webshop webshop = _context.webshop.Where(w => w.url == Record.Webshop).FirstOrDefault();

            if (webshop == default(webshop))
            {
                return;
            }

            if (cou == default(country))
            {
                Console.WriteLine("Could not find country id {0}, aborting the save.", countryId);
                return;
            }
            article art = new article
            {
                description = Record.Description,
                brand = Record.Brand,
                image_loc = Record.Image_Loc

            };
            // Do not modify this as this is neccessary to get the last id.
            _context.article.Add(art);

            ean ean = new ean
            {
                ean1 = Record.EAN,
                article_id = art.id
            };
            _context.ean.Add(ean);

            title title = new title
            {
                title1 = Record.Title,
                country_id = (short)countryId,
                article_id = art.id,
                country = cou
            };
            _context.title.Add(title);

            title_synonym ts = new title_synonym
            {
                title = Record.Title,
                title_id = title.id,
                occurrences = 1
            };
            _context.title_synonym.Add(ts);

            if (Record.SKU != "")
            {
                sku sku = new sku
                {
                    sku1 = Record.SKU,
                    article_id = art.id
                };
                _context.sku.Add(sku);
            }

            decimal castedShipCost;
            decimal castedPrice;
            if (!(decimal.TryParse(Record.DeliveryCost, NumberStyles.Any, CultureInfo.InvariantCulture, out castedShipCost))) Console.WriteLine("Cannot cast shipping cost " + Record.DeliveryCost + " to decimal.");
            if (!(decimal.TryParse(Record.Price, NumberStyles.Any, CultureInfo.InvariantCulture, out castedPrice))) Console.WriteLine("Cannot cast price " + Record.Price + " to decimal.");

            product product = new product
            {
                article_id = art.id,
                ship_cost = castedShipCost,
                ship_time = Record.DeliveryTime,
                price = castedPrice,
                webshop_url = webshop.url,
                direct_link = Record.Url,
                affiliate_name = Record.Affiliate,
                affiliate_unique_id = Record.AffiliateProdID
            };
            _context.product.Add(product);
            _context.SaveChanges();
        }