protected override void Process() { _monitoring.Notify(Name, 0); var stock = GetStock(); if (stock == null) { log.AuditError("Nothing to process. Process exiting"); return; } using (var unit = GetUnitOfWork()) { foreach (var vendorStockCollection in stock) { _monitoring.Notify(Name, vendorStockCollection.VendorID); #if DEBUG if (vendorStockCollection.VendorID != 15) { continue; } #endif using (var stockBulk = new VendorStockBulk(vendorStockCollection.StockCollection, vendorStockCollection.VendorID, vendorStockCollection.DefaultVendorID)) { stockBulk.Init(unit.Context); stockBulk.Sync(unit.Context); } } } _monitoring.Notify(Name, 1); }
private void BulkImport(int vendorID, DataSet content, int?parentVendorID) { using (var unit = GetUnitOfWork()) { var dataList = (from d in content.Tables[0].AsEnumerable() let defaultVendorID = parentVendorID.HasValue ? parentVendorID.Value : vendorID select new Concentrator.Objects.Vendors.Bulk.VendorStockBulk.VendorImportStock { VendorID = vendorID, VendorStockType = "Assortment", QuantityOnHand = (int)d.Field <double>("QuantityOnHand") > 0 ? (int)d.Field <double>("QuantityOnHand") : 0, CustomItemNumber = VendorImportUtility.SetDataSetValue("ShortItemNumber", d), defaultVendorID = defaultVendorID, PromisedDeliveryDate = VendorImportUtility.SetDataSetValue("PromisedDeliveryDate", d), QuantityToReceive = VendorImportUtility.SetDataSetValue("QuantityToReceive", d) != null ? int.Parse(VendorImportUtility.SetDataSetValue("QuantityToReceive", d)) : 0, StockStatus = VendorImportUtility.SetDataSetValue("StockStatus", d), UnitCost = null, VendorBrandCode = VendorImportUtility.SetDataSetValue("Brand", d), VendorItemNumber = VendorImportUtility.SetDataSetValue("VendorItemNumber", d), VendorStatus = VendorImportUtility.SetDataSetValue("StockStatus", d) }); log.Debug("dataset to object"); using (var vendorStockBulk = new VendorStockBulk(dataList, vendorID, parentVendorID, "BAS")) { vendorStockBulk.Init(unit.Context); vendorStockBulk.Sync(unit.Context); } } }
protected override void Process() { var config = GetConfiguration(); using (var unit = GetUnitOfWork()) { Vendors.Where(x => ((VendorType)x.VendorType).Has(VendorType.AggregatorRetailStock) && x.IsActive).ForEach((vendor, idx) => { try { var retailDic = (from v in unit.Scope.Repository <VendorMapping>().GetAll(x => x.VendorID == vendor.VendorID) select new { BackendVendorCode = v.Vendor1.BackendVendorCode, VendorID = v.MapVendorID }).ToDictionary(x => x.BackendVendorCode, x => x.VendorID); Dictionary <int, List <VendorStock> > vendorStockList = new Dictionary <int, List <VendorStock> >(); //var translationDic = GetCrossProducts(vendor.VendorID, unit); List <Concentrator.Objects.Vendors.Bulk.VendorStockBulk.VendorImportStock> stockList = new List <Objects.Vendors.Bulk.VendorStockBulk.VendorImportStock>(); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aggregator"].ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(string.Format("select * from {0}", config.AppSettings.Settings["SqlViewName"].Value), connection)) { command.CommandTimeout = new TimeSpan(0, 15, 0).Seconds; using (SqlDataReader r = command.ExecuteReader()) { while (r.Read()) { try { string sapNr = (string)r["ProductId"]; int tempID = !r.IsDBNull(r.GetOrdinal("ConcentratorProductId")) ? (int)r["ConcentratorProductId"] : -1; string backendShopNumber = ((int)r["BackendRelationID"]).ToString(); if (tempID > 0 && retailDic.ContainsKey(backendShopNumber)) //|| translationDic.ContainsKey(sapNr)) ) { int concentratorProductID = tempID; //> 0 ? tempID : translationDic[sapNr]; int retailVendorID = retailDic[backendShopNumber]; int qty = (int)double.Parse(r["QuantityOnHand"].ToString()); var vs = new Concentrator.Objects.Vendors.Bulk.VendorStockBulk.VendorImportStock() { VendorID = retailVendorID, VendorStockType = "Assortment", ProductID = concentratorProductID, QuantityOnHand = qty > 0 ? qty : 0, CustomItemNumber = null, defaultVendorID = retailVendorID, PromisedDeliveryDate = null, QuantityToReceive = 0, StockStatus = null, UnitCost = null, VendorBrandCode = null, VendorItemNumber = null, VendorStatus = null }; stockList.Add(vs); } } catch (Exception ex) { log.AuditError(ex); } } } } } using (var vendorStockBulk = new VendorStockBulk(stockList, vendor.VendorID, vendor.ParentVendorID, "Aggregator")) { vendorStockBulk.Init(unit.Context); vendorStockBulk.Sync(unit.Context); } log.Info("Finish import Aggregator stock for " + vendor.VendorID); } catch (Exception ex) { log.AuditError(ex); } }); } }