예제 #1
0
        public static bool SyncOne(SUPPLY_MIN_PRICE product)
        {
            EnsureProductContext(product);
            if (!product.SHOP_SID.HasValue)
                return false;
            using (var ts = new TransactionScope())
            {
                using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
                {
                    var existProduct = db.Set<ProductMapEntity>().Where(b => b.ChannelPId == product.PRODUCT_SID).FirstOrDefault();
                    var tagEntity = db.Set<TagEntity>().Join(db.Set<CategoryMapEntity>().Where(cm => cm.ChannelCatId == product.PRO_CLASS_SID), o => o.Id, i => i.CatId, (o, i) => o)
                                    .FirstOrDefault();
            
                    var storeEntity = db.Set<StoreEntity>().Where(s => s.ExStoreId == product.SHOP_SID).FirstOrDefault();
                    if (storeEntity == null)
                    {
                        Log.Error(string.Format("product sid has no store:{0}", product.PRODUCT_SID));
                        return false;
                    }
                    var brandEntity = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == product.BRAND_SID).FirstOrDefault();
                    if (brandEntity == null)
                    {
                        Log.Error(string.Format("product sid has no brand:{0}", product.PRODUCT_SID));
                        return false;
                    }
                    if (existProduct == null)
                    {
                        var newProduct = new ProductEntity()
                        {
                            CreatedDate = DateTime.Now,
                            CreatedUser = DEFAULT_OWNER_ID,
                            SkuCode = product.PRO_SKU,
                            Brand_Id = brandEntity == null ? 0 : brandEntity.Id,
                            Description = product.PRO_DESC ?? string.Empty,
                            Is4Sale = false,
                            Name = string.IsNullOrEmpty(product.PRODUCT_NAME)? string.Format("{0}-{1}", brandEntity.Name, product.PRO_SKU):product.PRODUCT_NAME,
                            UnitPrice = product.ORIGINAL_PRICE ?? NULL_PRICE,
                            RecommendedReason = product.PRO_DESC ?? string.Empty,
                            RecommendUser = DEFAULT_OWNER_ID,
                            SortOrder = 0,
                            Status = (int)DataStatus.Default,
                            Store_Id = storeEntity == null ? 0 : storeEntity.Id,
                            Tag_Id = tagEntity == null ? int.Parse(DEFAULT_TAG_ID) : tagEntity.Id,
                            Price = product.PROMOTION_PRICE ?? NULL_PRICE,
                            UpdatedDate = product.OPT_UPDATE_TIME ?? DateTime.Now,
                            UpdatedUser = DEFAULT_OWNER_ID,
                            BarCode = product.BARCODE,
                            Favorable = "1"


                        };
                        db.Products.Add(newProduct);
                        db.SaveChanges();
                        db.ProductMaps.Add(new ProductMapEntity()
                        {
                            Channel = "ERP",
                            ChannelBrandId = (int)product.BRAND_SID,
                            ChannelPId = (int)product.PRODUCT_SID,
                            ChannelCatId = (int)(product.PRO_CLASS_SID??0m),
                            ProductId = newProduct.Id,
                            UpdateDate = product.OPT_UPDATE_TIME ?? DateTime.Now
                        });
                    }
                    else
                    {
                        var existProductEntity = db.Set<ProductEntity>().Find(existProduct.ProductId);
                        existProductEntity.BarCode = product.BARCODE;
                        existProductEntity.UpdatedDate = product.OPT_UPDATE_TIME ?? DateTime.Now;
                        existProductEntity.Store_Id = storeEntity == null ? 0 : storeEntity.Id;
                        existProductEntity.Brand_Id = brandEntity == null ? 0 : brandEntity.Id;
                        existProductEntity.Tag_Id = tagEntity == null ? int.Parse(DEFAULT_TAG_ID) : tagEntity.Id;
                        existProductEntity.SkuCode = product.PRO_SKU;
                        existProductEntity.Name = string.IsNullOrEmpty(product.PRODUCT_NAME) ? string.Format("{0}-{1}", brandEntity.Name, product.PRO_SKU) : product.PRODUCT_NAME;
                        existProductEntity.UnitPrice = product.ORIGINAL_PRICE ?? NULL_PRICE;
                        existProductEntity.Price = product.PROMOTION_PRICE ?? NULL_PRICE;
                        existProductEntity.Description = product.PRO_DESC ?? string.Empty;
                        existProductEntity.RecommendedReason = product.PRO_DESC ?? string.Empty;

                    }
                    db.SaveChanges();

                }
                ts.Complete();
            }
            return true;
        }
예제 #2
0
 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);
             }
         }
     }
 }
예제 #3
0
        private static void syncRelatedPics(SUPPLY_MIN_PRICE product)
        {
            IEnumerable<PRO_PICTURE> pics = null;
            using (var erp = new ErpContext())
            {
                pics = erp.PRO_PICTURE.Where(p => p.PRODUCT_SID == product.PRODUCT_SID).ToList();

            }
            foreach (var pic in pics)
            {
                ProductPicSyncJob.SyncOne(pic);
            }
        }