private bool EnsureProductContext(PRO_PICTURE product) { using(var erpDb= new ErpContext()) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var colorEntity = db.Set<ProductPropertyValueEntity>().Where(ppv => ppv.ChannelValueId == product.PRO_COLOR_SID) .Join(db.Set<ProductPropertyEntity>().Join(db.Set<ProductMapEntity>().Where(pm=>pm.ChannelPId==product.PRODUCT_SID),o=>o.ProductId,i=>i.ProductId,(o,i)=>o), o=>o.PropertyId,i=>i.Id,(o,i)=>o).FirstOrDefault(); if (colorEntity == null) { var exProduct = erpDb.Set<SUPPLY_MIN_PRICE_MX>().Where(ep => ep.PRODUCT_SID == product.PRODUCT_SID && ep.PRO_COLOR_SID == product.PRO_COLOR_SID).FirstOrDefault(); if (exProduct == null) { Log.Error(string.Format("product sid:{0} has no inventory record for color_sid:{1}",product.PRODUCT_SID,product.PRO_COLOR_SID)); return false; } return ProductPropertySyncJob.SyncOne(exProduct.PRODUCT_SID, exProduct.PRO_STAN_SID ?? 0, exProduct.PRO_STAN_NAME, exProduct.PRO_COLOR_SID ?? 0, exProduct.PRO_COLOR); } } } return true; }
private static void EnsureProductContext(SUPPLY_MIN_PRICE product) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var exBrand = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == product.BRAND_SID).FirstOrDefault(); if (null == exBrand) { using (var erpDb = new ErpContext()) { var brand = erpDb.Set<BRAND>().Find(product.BRAND_SID); if (null != brand) BrandSyncJob.SyncOne(brand); } } var exCat = db.Set<CategoryEntity>().Where(c => c.ExCatId == product.PRO_CLASS_SID).FirstOrDefault(); if (null == exCat) { using (var erpDb = new ErpContext()) { var cat = erpDb.Set<PRO_CLASS_DICT>().Find(product.PRO_CLASS_SID); if (null != cat) CategorySyncJob.SyncOne(cat); } } var exStore = db.Set<StoreEntity>().Where(c => c.ExStoreId == product.SHOP_SID).FirstOrDefault(); if (null == exStore) { using (var erpDb = new ErpContext()) { var store = erpDb.Set<SHOP_INFO>().Find(product.SHOP_SID); if (null != store) StoreSyncJob.SyncOne(store); } } } }
private static bool EnsureProductContext(decimal pid) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var productEntity = db.Set<ProductMapEntity>().Where(b => b.ChannelPId == pid).FirstOrDefault(); if (null == productEntity) { using (var erpDb = new ErpContext()) { var exProduct = erpDb.Set<SUPPLY_MIN_PRICE>().Where(ep => ep.PRODUCT_SID == pid).FirstOrDefault(); if (null != exProduct) return ProductSyncJob.SyncOne(exProduct); } } return true; } }