private void FragancexSQLPreparer(ServiceTimeStamp service) { var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); try { var listingApiClient = new FrgxListingApiClient("346c055aaefd", "a5574c546cbbc9c10509e3c277dd7c7039b24324"); // For testing purposes //List<Product> allProducts = new List<Product>(); //var product = listingApiClient.GetProductById("412492"); //allProducts.Add(product); var allProducts = listingApiClient.GetAllProducts(); DBModifierFragrancexAPI dBModifierFragrancexAPI = new DBModifierFragrancexAPI("", upc) { allProducts = allProducts }; dBModifierFragrancexAPI.TableExecutor(); // delete everything from the db, then update using (var tran = _context.Database.BeginTransaction()) { _context.BulkDelete(_context.Wholesaler_Fragrancex.ToList()); tran.Commit(); } using (var tran = _context.Database.BeginTransaction()) { _context.BulkInsertOrUpdate(dBModifierFragrancexAPI.fragrancex); tran.Commit(); } service.TimeStamp = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "API"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { throw e; } }
private void FragancexSQLPreparer(ServiceTimeStamp service) { var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); // TODO: Test this functionality once Alex is done with his development!! try { var listingApiClient = new FrgxListingApiClient("346c055aaefd", "a5574c546cbbc9c10509e3c277dd7c7039b24324"); // For testing purposes //List<Product> allProducts = new List<Product>(); //var product = listingApiClient.GetProductById("412492"); //allProducts.Add(product); var allProducts = listingApiClient.GetAllProducts(); DBModifierFragrancexAPI dBModifierFragrancexAPI = new DBModifierFragrancexAPI("", upc) { allProducts = allProducts }; dBModifierFragrancexAPI.TableExecutor(); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "API"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { } }
internal static void tablePreparer(string path) { FileInfo file = new FileInfo(path); try { using (ExcelPackage package = new ExcelPackage(file)) { StringBuilder sb = new StringBuilder(); ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; // SDK call var listingApiClient = new FrgxListingApiClient("346c055aaefd", "a5574c546cbbc9c10509e3c277dd7c7039b24324"); var allProducts = listingApiClient.GetAllProducts(); int row = 1; foreach (var product in allProducts) { if (row == 1) { worksheet.Cells[row, 1].Value = "ItemID"; worksheet.Cells[row, 2].Value = "BrandName"; worksheet.Cells[row, 3].Value = "Description"; worksheet.Cells[row, 4].Value = "Gender"; worksheet.Cells[row, 5].Value = "Instock"; worksheet.Cells[row, 6].Value = "LargeImageUrl"; worksheet.Cells[row, 7].Value = "MetricSize"; worksheet.Cells[row, 8].Value = "ParentCode"; worksheet.Cells[row, 9].Value = "ProductName"; worksheet.Cells[row, 10].Value = "RetailPriceUSD"; worksheet.Cells[row, 11].Value = "Size"; worksheet.Cells[row, 12].Value = "SmallImageUrl"; worksheet.Cells[row, 13].Value = "Type"; worksheet.Cells[row, 14].Value = "WholesalePriceAUD"; worksheet.Cells[row, 15].Value = "WholesalePriceCAD"; worksheet.Cells[row, 16].Value = "WholesalePriceEUR"; worksheet.Cells[row, 17].Value = "WholesalePriceGBP"; worksheet.Cells[row, 18].Value = "WholesalePriceUSD"; row++; } else { worksheet.Cells[row, 1].Value = Convert.ToInt32(product.ItemId); worksheet.Cells[row, 2].Value = product.BrandName; worksheet.Cells[row, 3].Value = product.Description; worksheet.Cells[row, 4].Value = product.Gender; worksheet.Cells[row, 5].Value = product.Instock; worksheet.Cells[row, 6].Value = product.LargeImageUrl; worksheet.Cells[row, 7].Value = product.MetricSize; worksheet.Cells[row, 8].Value = product.ParentCode; worksheet.Cells[row, 9].Value = product.ProductName; worksheet.Cells[row, 10].Value = product.RetailPriceUSD; worksheet.Cells[row, 11].Value = product.Size; worksheet.Cells[row, 12].Value = product.SmallImageUrl; worksheet.Cells[row, 13].Value = product.Type; worksheet.Cells[row, 14].Value = product.WholesalePriceAUD; worksheet.Cells[row, 15].Value = product.WholesalePriceCAD; worksheet.Cells[row, 16].Value = product.WholesalePriceEUR; worksheet.Cells[row, 17].Value = product.WholesalePriceGBP; worksheet.Cells[row, 18].Value = product.WholesalePriceUSD; row++; } } package.Save(); } } catch (Exception ex) { Console.WriteLine("Some error occurred while importing." + ex.Message); } }