private async Task InsertVendorProducts() { var count = 0; try { for (var rCnt = (int)_vendor.RowAt; rCnt <= _range.Rows.Count; rCnt++) { var SKU = (_productfileconfig.SKU != -1) ? (_range.Cells[rCnt, (_productfileconfig.SKU + 1)] as Range).Value2 : null; var Name = (_productfileconfig.Name != -1) ? (_range.Cells[rCnt, (_productfileconfig.Name + 1)] as Range).Value2 : null; var Description = (_productfileconfig.Description != -1) ? (_range.Cells[rCnt, (_productfileconfig.Description + 1)] as Range).Value2 : null; var ShortDescription = (_productfileconfig.ShortDescription != -1) ? (_range.Cells[rCnt, (_productfileconfig.ShortDescription + 1)] as Range).Value2 : null; var Category = (_productfileconfig.Category != -1) ? (_range.Cells[rCnt, (_productfileconfig.Category + 1)] as Range).Value2 : null; var UPCCode = (_productfileconfig.UPCCode != -1) ? (_range.Cells[rCnt, (_productfileconfig.UPCCode + 1)] as Range).Value2 : null; var SupplierCost = (_productfileconfig.SupplierCost != -1) ? (_range.Cells[rCnt, (_productfileconfig.SupplierCost + 1)] as Range).Value2 : null; var product = new vendorproduct { VendorId = _vendor.Id, SKU = (SKU != null) ? Convert.ToString(SKU) : "", Name = (Name != null) ? Convert.ToString(Name) : "", Description = (Description != null) ? Convert.ToString(Description) : "", ShortDescription = (ShortDescription != null) ? Convert.ToString(ShortDescription) : "", Category = (Category != null) ? Convert.ToString(Category) : "", UPCCode = (UPCCode != null) ? Convert.ToString(UPCCode) : "", SupplierCost = (SupplierCost != null) ? Convert.ToDecimal(SupplierCost) : 0, ResultDate = _date }; var productId = await VendorsConfig.AddVendorProduct(product); await InsertProductImages(productId, rCnt); count++; var percentage = (((double)count + 1) / _range.Rows.Count) * 100.00; System.Console.WriteLine("{1:#0.00}% Inserted product: {0}", product.SKU, percentage); } System.Console.WriteLine("Uploaded {0} products for {1}", count, _vendor.VendorName); } catch (Exception ex) { System.Console.WriteLine(ex.StackTrace); } }
private async Task InsertVendorProduct(string unSplitRowValues) { var rowValues = unSplitRowValues.Split(_delimiter).ToList(); var product = new vendorproduct { VendorId = _vendor.Id, SKU = rowValues[(int)_productfileconfig.SKU], Name = rowValues[(int)_productfileconfig.Name], Description = rowValues[(int)_productfileconfig.Description], ShortDescription = rowValues[(int)_productfileconfig.ShortDescription], Category = rowValues[(int)_productfileconfig.Category], UPCCode = rowValues[(int)_productfileconfig.UPCCode], SupplierCost = Convert.ToDecimal(rowValues[(int)_productfileconfig.SupplierCost]), ResultDate = _date }; var vendorProductId = await VendorsConfig.AddVendorProduct(product); await InsertProductImages(rowValues, vendorProductId); }