private void SaveWineRating(int wineListId, UpcDbModel wineInfo) { if (IsNullOrEmpty(wineInfo.Rating)) { return; } ; var stringLength = wineInfo.Rating.Length; if (stringLength > 4) { stringLength = 4; } var wineRating = new WineRatings { WineListWineListId = wineListId, Prefix = wineInfo.Rating.Substring(0, stringLength) }; _context.WineRatings.Add(wineRating); _context.SaveChanges(); _processLog.WriteLine("Adding Ratings: " + wineRating.Prefix); }
private WineList SaveWineItem(UpcDbModel wineInfo, WineVarieties wineVariety) { var wineData = new WineList() { Upc = wineInfo.UpcCode, AlchoholLevel = (int?)wineInfo.AlchoholLevel, WineVarietiesVarietyId = wineVariety.VarietyId, Region = wineInfo.Region, Producer = wineInfo.Winery ?? "N/A", Vintage = wineInfo.Year, Size = wineInfo.Size, }; if (wineData.Upc.IsNullOrEmpty()) { wineData.Upc = GetInternalBarCode(); } if (wineData.Region.IsNullOrEmpty()) { wineData.Region = string.Empty; } if (wineData.Size == 0) { wineData.Size = 750; } wineData.CreatedDate = DateTime.UtcNow; _context.WineList.Add(wineData); _context.SaveChanges(); _processLog.WriteLine("UPC: " + wineData.Upc + " Saving item: " + wineInfo.WineName + " - " + wineInfo.Varietal + ", " + wineInfo.Winery); Console.Write("."); return(wineData); }
private bool InsertItemDetailQueue() { CloudStorageAccount account; CloudStorageAccount.TryParse("DefaultEndpointsProtocol=https;AccountName=winehunter;AccountKey=tuG0LI1tGsBilE+R8GnG0PlWCFvtoULCOwh/IeFydllu7Onc0k4coRXiCFS3d4bDmcBc4oVdBR951PuAW0NjTw==;", out account); var queueClient = account.CreateCloudQueueClient(); // Retrieve a reference to a queue var shopsImportDataQueue = queueClient.GetQueueReference("winelistjson"); // Create the queue if it doesn't already exist shopsImportDataQueue.CreateIfNotExists(); _fileName = @"c:\UPCDB\upc.csv"; var itemDetailUrls = (from line in ReadFrom(_fileName) select line); foreach (var itemUrl in itemDetailUrls) { var splits = itemUrl.Split('/'); //ignore invalid urls if (splits.Last().Length == 5 || splits.Last().Length == 6) { continue; } var getHtmlWeb = new HtmlWeb(); var document = getHtmlWeb.Load(itemUrl); var upcNodes = document.DocumentNode.SelectNodes("//tr").Descendants("td").Where(o => o.GetAttributeValue("width", "") == "80%").ToList(); if (!upcNodes.Any()) { continue; } var wine = new UpcDbModel { WineName = upcNodes[0].InnerText.Replace(" ", string.Empty), Winery = upcNodes[1].InnerText.Replace(" ", string.Empty), Varietal = upcNodes[2].InnerText.Replace(" ", string.Empty), Region = upcNodes[3].InnerText.Replace(" ", string.Empty), UpcCode = upcNodes[12].InnerText.Replace(" ", string.Empty), Rating = upcNodes[6].InnerText.Replace(" ", string.Empty) }; var wineSize = 0; int.TryParse(upcNodes[9].InnerText.Replace(" ", string.Empty).Replace("ml", string.Empty), out wineSize); wine.Size = wineSize; var wineYear = 0; int.TryParse(upcNodes[4].InnerText.Replace(" ", string.Empty).Replace("ml", string.Empty), out wineYear); wine.Year = wineYear; var value = Newtonsoft.Json.JsonConvert.SerializeObject(wine); var message = new CloudQueueMessage(value); System.Threading.Tasks.Task.Run(async() => { await shopsImportDataQueue.AddMessageAsync(message); Console.Write("+"); }); } Console.WriteLine("555.Item Queue complete."); return(true); }