public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
 {
     try
     {
         using (var db = SyncDbContextFactory.Factory <EFDbContext>())
         {
             var result = db.Notices.Where(o => o.CompanyId == companyId && (("," + o.StoreId + ",").Contains("," + storeId + ",") || ("," + o.StoreId + ",").Contains(",-1,"))).Select(o => new SyncDataObject()
             {
                 SyncItemId = o.SyncItemId, SyncItemVersion = o.SyncItemVersion
             }).ToList();
             return(result);
         }
     }
     catch
     {
         return(new List <ISyncDataObject>());
     }
 }
 public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
 {
     try
     {
         using (var db = SyncDbContextFactory.Factory <EFDbContext>())
         {
             var result = db.ApiLibrarys.Where(o => o.CompanyId == companyId).Select(o => new SyncDataObject()
             {
                 SyncItemId = o.SyncItemId, SyncItemVersion = o.SyncItemVersion
             }).ToList();
             return(result);
         }
     }
     catch
     {
         return(new List <ISyncDataObject>());
     }
 }
Пример #3
0
 public ISyncDataObject GetItem(Guid guid, int companyId, string storeId)
 {
     using (var db = SyncDbContextFactory.Factory <EFDbContext>())
     {
         var commodits          = db.CommodityPromotions.Where(o => o.SyncItemId == guid).ToList();
         var commodit           = commodits.FirstOrDefault();
         var promotionBlend     = db.PromotionBlends.Where(o => o.CommodityId == commodit.Id).ToList();
         var promotionBlendList = db.PromotionBlendLists.Where(o => o.CommodityId == commodit.Id).ToList();
         var package            = new Package()
         {
             SyncItemId = guid, EntityType = "CommodityBlendPackage"
         };
         package.Init(commodits.Select(o => new CommodityPromotion().InitEntity(o)).ToList());
         package.Init(promotionBlend.Select(o => new PromotionBlend().InitEntity(o)).ToList());
         package.Init(promotionBlendList.Select(o => new PromotionBlendList().InitEntity(o)).ToList());
         return(package);
     }
 }
 public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
 {
     try
     {
         using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
         {
             var result = db.Notices.Select(o => new SyncDataObject()
             {
                 SyncItemId = o.SyncItemId, SyncItemVersion = o.SyncItemVersion
             }).ToList();
             return(result);
         }
     }
     catch
     {
         return(new List <ISyncDataObject>());
     }
 }
Пример #5
0
 public ISyncDataObject GetItem(Guid guid, int companyId, string storeId)
 {
     using (var db = SyncDbContextFactory.Factory <EFDbContext>())
     {
         var commodits = db.CommodityPromotions.Where(o => o.SyncItemId == guid).ToList();
         var commodit  = commodits.FirstOrDefault();
         var promotionFreeGiftPurchase = db.FreeGiftPurchases.Where(o => o.CommodityId == commodit.Id).ToList();
         var giftIds = promotionFreeGiftPurchase.Select(o => o.GiftId);
         var promotionFreeGiftPurchaseList = db.FreeGiftPurchaseLists.Where(o => giftIds.Contains(o.GiftId)).ToList();
         var package = new Package()
         {
             SyncItemId = guid, EntityType = "CommodityFreeGiftPackage"
         };
         package.Init(commodits.Select(o => new CommodityPromotion().InitEntity(o)).ToList());
         package.Init(promotionFreeGiftPurchase.Select(o => new FreeGiftPurchase().InitEntity(o)).ToList());
         package.Init(promotionFreeGiftPurchaseList.Select(o => new FreeGiftPurchaseList().InitEntity(o)).ToList());
         return(package);
     }
 }
        public byte[] UpdateItem(Guid guid, ISyncDataObject mergedData, int companyId, string storeId)
        {
            var temp = mergedData as Package;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                var integralSets            = temp.GetEntities <MemberIntegralSet>();
                var integralSetsSyncIds     = integralSets.Select(o => o.SyncItemId).ToList();
                var integralSetLists        = temp.GetEntities <MemberIntegralSetList>();
                var integralSetListsSyncIds = integralSetLists.Select(o => o.SyncItemId).ToList();

                db.MemberIntegralSets.Where(o => integralSetsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(integralSets.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.MemberIntegralSetLists.Where(o => integralSetListsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(integralSetLists.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.SaveChanges();

                var version = GetVersion(guid, companyId, storeId, db);
                return(version.SyncItemVersion);
            }
        }
        public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
        {
            try
            {
                using (var db = SyncDbContextFactory.Factory <EFDbContext>())
                {
                    var result = db.Database.SqlQuery <SyncDataObject>(@"  select 'MemberIntegralSetPackage' as  EntityType, SyncItemId,max(SyncItemVersion) SyncItemVersion from (
select  s.syncitemid,s.SyncItemVersion from [MemberIntegralSet] s  where s.CompanyId=@p0
union all
select  s.syncitemid,d.SyncItemVersion from [MemberIntegralSet] s,[MemberIntegralSetList] d where s.Id = d.IntegralId  and s.CompanyId=@p0
) as t group by SyncItemId", companyId).ToList();
                    return(result);
                }
            }
            catch
            {
                return(new List <ISyncDataObject>());
            }
        }
Пример #8
0
 public IDictionary <Microsoft.Synchronization.SyncId, ISyncDataObject> GetItems(IEnumerable <Microsoft.Synchronization.SyncId> ids, int companyId, string StoreId)
 {
     using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
     {
         var syncidsdict = ids.ToDictionary(o => o.GetGuidId(), o => o);
         var syncids     = syncidsdict.Keys;
         var query       = db.CommodityPromotions.Where(o => syncids.Contains(o.SyncItemId)).Include(o => o.CommodityDiscounts).ToList();
         return(query.ToDictionary(o => syncidsdict[o.SyncItemId], o =>
         {
             var package = new Package()
             {
                 SyncItemId = o.SyncItemId, EntityType = "CommodityDiscountPackage"
             };
             package.Init(new CommodityPromotion[] { new CommodityPromotion().InitEntity(o) });
             package.Init(o.CommodityDiscounts.Select(p => new CommodityDiscount().InitEntity(p)).ToList());
             return package as ISyncDataObject;
         }));
     }
 }
 public ISyncDataObject GetItem(Guid guid, int companyId, string storeId)
 {
     using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
     {
         var promotions = db.CommodityPromotions.FirstOrDefault(o => o.SyncItemId == guid);
         var package    = new Package()
         {
             SyncItemId = guid, EntityType = "CommodityFreeGiftPackage"
         };
         var promotionList = new List <CommodityPromotion>();
         promotionList.Add(new CommodityPromotion().InitEntity(promotions));
         package.Init(promotionList);
         var gifts   = db.FreeGiftPurchases.Where(o => o.CommodityId == promotions.Id).ToList().Select(o => new FreeGiftPurchase().InitEntity(o, true));
         var giftIds = gifts.Select(o => o.GiftId).ToList();
         package.Init(gifts);
         package.Init(db.FreeGiftPurchaseLists.Where(o => giftIds.Exists(p => o.GiftId == p)).ToList().Select(o => new FreeGiftPurchaseList().InitEntity(o, true)));
         return(package);
     }
 }
 public ISyncDataObject GetItem(Guid guid, int companyId, string storeId)
 {
     using (var db = SyncDbContextFactory.Factory <EFDbContext>())
     {
         var orders              = db.SaleOrders.Where(o => o.SyncItemId == guid).ToList();
         var order               = orders.FirstOrDefault();
         var saleDetails         = db.SaleDetails.Where(o => o.PaySN == order.PaySN && o.CompanyId == companyId).ToList();
         var consumptionPayments = db.ConsumptionPayments.Where(o => o.PaySN == order.PaySN && o.CompanyId == companyId).ToList();
         var wipeZeros           = db.WipeZeros.Where(o => o.PaySN == order.PaySN && o.CompanyId == companyId).ToList();
         var package             = new Package()
         {
             SyncItemId = guid, EntityType = "SalePackage"
         };
         package.Init(orders.Select(o => new SaleOrders().InitEntity(o)).ToList());
         package.Init(saleDetails.Select(o => new SaleDetail().InitEntity(o)).ToList());
         package.Init(consumptionPayments.Select(o => new ConsumptionPayment().InitEntity(o)).ToList());
         package.Init(wipeZeros.Select(o => new WipeZero().InitEntity(o)).ToList());
         return(package);
     }
 }
Пример #11
0
        public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
        {
            try
            {
                using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
                {//PromotionType 1:单品折扣、 2:捆绑促销、 3:组合促销、4:买赠促销、 5:满元促销
                    var result = db.Database.SqlQuery <SyncDataObject>(@" select 'CommodityDiscountPackage' as  EntityType, SyncItemId,max (SyncItemVersion)  as SyncItemVersion from (
select  s.syncitemid,s.SyncItemVersion from [CommodityPromotion] s 
union all
select  s.syncitemid,d.SyncItemVersion from [CommodityPromotion] s,[CommodityDiscount] d where s.Id = d.CommodityId  
) as t group by SyncItemId").ToList();

                    return(result);
                }
            }
            catch
            {
                return(new List <ISyncDataObject>());
            }
        }
Пример #12
0
        public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
        {
            try
            {
                using (var db = SyncDbContextFactory.Factory <EFDbContext>())
                {
                    var result = db.Database.SqlQuery <SyncDataObject>(@" select 'CommodityDiscountPackage' as  EntityType, SyncItemId,max (SyncItemVersion) SyncItemVersion from (
select  s.syncitemid,s.SyncItemVersion from [CommodityPromotion] s  where s.PromotionType=1 and s.companyid =@p0 and ((','+s.storeid+',') like ('%,'+@p1+',%') or (','+s.storeid+',') like ('%,-1,%')) and State!=2
union all
select  s.syncitemid,d.SyncItemVersion from [CommodityPromotion] s,[CommodityDiscount] d where s.Id = d.CommodityId  and  s.PromotionType=1 and s.companyid =@p0 and ((','+s.storeid+',') like ('%,'+@p1+',%') or (','+s.storeid+',') like ('%,-1,%')) and State!=2
) as t group by SyncItemId", companyId, storeId).ToList();

                    return(result);
                }
            }
            catch
            {
                return(new List <ISyncDataObject>());
            }
        }
Пример #13
0
        public byte[] UpdateItem(Guid guid, ISyncDataObject mergedData, int companyId, string storeId)
        {
            var temp = mergedData as Package;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                var _promotions               = temp.GetEntities <CommodityPromotion>();
                var _promotionsSyncIds        = _promotions.Select(o => o.SyncItemId).ToList();
                var commodityDiscounts        = temp.GetEntities <CommodityDiscount>();
                var commodityDiscountsSyncIds = commodityDiscounts.Select(o => o.SyncItemId).ToList();

                db.CommodityPromotions.Where(o => _promotionsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(_promotions.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.CommodityDiscounts.Where(o => commodityDiscountsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(commodityDiscounts.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.SaveChanges();

                StoreManager.PubEvent("MarketingRefresh", new { StoreId = storeId, CompanyId = companyId });

                var version = GetVersion(guid, companyId, storeId, db);
                return(version.SyncItemVersion);
            }
        }
Пример #14
0
        public byte[] CreateItem(ISyncDataObject data, Guid guid, int companyId, string storeId)
        {
            var temp = data as Pharos.SyncService.SyncEntities.SalesRecord;

            using (var db = SyncDbContextFactory.Factory <EFDbContext>())
            {
                Pharos.Logic.Entity.SalesRecord entity;
                if (!db.SalesRecords.Any(o => o.SyncItemId == guid))
                {
                    entity = new Pharos.Logic.Entity.SalesRecord();
                    entity.InitEntity(temp);
                    db.SalesRecords.Add(entity);
                    db.SaveChanges();
                }
                else
                {
                    entity = db.SalesRecords.FirstOrDefault(o => o.SyncItemId == guid);
                }
                return(entity.SyncItemVersion);
            }
        }
        public byte[] CreateItem(ISyncDataObject data, Guid guid, int companyId, string storeId)
        {
            var temp = data as Package;

            using (var db = SyncDbContextFactory.Factory <EFDbContext>())
            {
                if (!db.SaleOrders.Any(o => o.SyncItemId == guid))
                {
                    var orders              = temp.GetEntities <SaleOrders>();
                    var saleDetails         = temp.GetEntities <SaleDetail>();
                    var consumptionPayments = temp.GetEntities <ConsumptionPayment>();
                    var wipeZeros           = temp.GetEntities <WipeZero>();
                    db.SaleOrders.AddRange(orders.Select(o => new Pharos.Logic.Entity.SaleOrders().InitEntity(o, false)));
                    db.SaleDetails.AddRange(saleDetails.Select(o => new Pharos.Logic.Entity.SaleDetail().InitEntity(o, false)));
                    db.ConsumptionPayments.AddRange(consumptionPayments.Select(o => new Pharos.Logic.Entity.ConsumptionPayment().InitEntity(o, false)));
                    db.WipeZeros.AddRange(wipeZeros.Select(o => new Pharos.Logic.Entity.WipeZero().InitEntity(o, false)));
                    db.SaveChanges();
                }
                var version = GetVersion(guid, companyId, storeId, db);
                return(version.SyncItemVersion);
            }
        }
        public byte[] CreateItem(ISyncDataObject data, Guid guid, int companyId, string storeId)
        {
            var temp = data as Package;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                try
                {
                    var memberImterSet     = temp.GetEntities <MemberIntegralSet>();
                    var memberImterSetList = temp.GetEntities <MemberIntegralSetList>();
                    db.MemberIntegralSets.AddRange(memberImterSet.Select(o => new Pharos.Logic.ApiData.Pos.Entity.LocalCeEntity.MemberIntegralSet().InitEntity(o)));
                    db.MemberIntegralSetLists.AddRange(memberImterSetList.Select(o => new Pharos.Logic.ApiData.Pos.Entity.LocalCeEntity.MemberIntegralSetList().InitEntity(o)));
                    db.SaveChanges();
                    var version = GetVersion(guid, companyId, storeId, db);
                    return(version.SyncItemVersion);
                }
                catch (DbEntityValidationException dbEx)
                {
                    throw dbEx;
                }
            }
        }
        public IDictionary <Microsoft.Synchronization.SyncId, ISyncDataObject> GetItems(IEnumerable <Microsoft.Synchronization.SyncId> ids, int companyId, string StoreId)
        {
            using (var db = SyncDbContextFactory.Factory <EFDbContext>())
            {
                var syncidsdict = ids.ToDictionary(o => o.GetGuidId(), o => o);
                var syncids     = syncidsdict.Keys;
                var query       = db.SaleOrders.Where(o => syncids.Contains(o.SyncItemId)).Include(o => o.SaleDetails).Include(o => o.WipeZeros).Include(o => o.ConsumptionPayments).ToList();

                return(query.ToDictionary(o => syncidsdict[o.SyncItemId], o =>
                {
                    var package = new Package()
                    {
                        SyncItemId = o.SyncItemId, EntityType = "SalePackage"
                    };
                    package.Init(new SaleOrders[] { new SaleOrders().InitEntity(o) });
                    package.Init(o.SaleDetails.Select(p => new SaleDetail().InitEntity(p)).ToList());
                    package.Init(o.ConsumptionPayments.Select(p => new ConsumptionPayment().InitEntity(p)).ToList());
                    package.Init(o.WipeZeros.Select(p => new WipeZero().InitEntity(p)).ToList());
                    return package as ISyncDataObject;
                }));
            }
        }
        public byte[] UpdateItem(Guid guid, ISyncDataObject mergedData, int companyId, string storeId)
        {
            var temp = mergedData as Package;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                var _promotions                   = temp.GetEntities <CommodityPromotion>();
                var _promotionsSyncIds            = _promotions.Select(o => o.SyncItemId).ToList();
                var commodityBundlings            = temp.GetEntities <Bundling>();
                var commodityBundlingsSyncIds     = commodityBundlings.Select(o => o.SyncItemId).ToList();
                var commodityBundlingLists        = temp.GetEntities <BundlingList>();
                var commodityBundlingListsSyncIds = commodityBundlingLists.Select(o => o.SyncItemId).ToList();

                db.CommodityPromotions.Where(o => _promotionsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(_promotions.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.Bundlings.Where(o => commodityBundlingsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(commodityBundlings.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.BundlingLists.Where(o => commodityBundlingListsSyncIds.Contains(o.SyncItemId)).ToList().ForEach(o => o.InitEntity(commodityBundlingLists.FirstOrDefault(p => o.SyncItemId == p.SyncItemId)));
                db.SaveChanges();

                StoreManager.PubEvent("MarketingRefresh", new { StoreId = storeId, CompanyId = companyId });
                try
                {
                    var bunding = commodityBundlings.FirstOrDefault();
                    if (bunding != null)
                    {
                        var qRefresh = new List <Pharos.ObjectModels.DTOs.MemoryCacheRefreshQuery>();
                        var item     = new ObjectModels.DTOs.MemoryCacheRefreshQuery()
                        {
                            CompanyId = companyId, StoreId = storeId, Barcode = bunding.NewBarcode, ProductType = ObjectModels.ProductType.Bundling, ProductCode = ""
                        };
                        qRefresh.Add(item);
                        Pharos.Logic.ApiData.Pos.Cache.ProductCache.RefreshProduct(qRefresh);
                    }
                }
                catch { }

                var version = GetVersion(guid, companyId, storeId, db);
                return(version.SyncItemVersion);
            }
        }
        public byte[] CreateItem(ISyncDataObject data, Guid guid, int companyId, string storeId)
        {
            var temp = data as DeviceRegInfo;

            using (var db = SyncDbContextFactory.Factory <EFDbContext>())
            {
                Pharos.Logic.Entity.DeviceRegInfo entity;
                if (!db.DeviceRegInfos.Any(o => o.SyncItemId == guid))
                {
                    entity = new Pharos.Logic.Entity.DeviceRegInfo();
                    entity.InitEntity(temp, false);
                    db.DeviceRegInfos.Add(entity);
                    db.SaveChanges();
                }
                else
                {
                    entity = db.DeviceRegInfos.FirstOrDefault(o => o.SyncItemId == guid);
                }
                return(entity.SyncItemVersion);
            }
            //  throw new Exception("创建DeviceRegInfo");
        }
Пример #20
0
        public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
        {
            try
            {
                using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
                {
                    var result = db.Database.SqlQuery <SyncDataObject>(@"select 'SalePackage' as  EntityType, SyncItemId,max (SyncItemVersion)  as SyncItemVersion from (
select  s.syncitemid,s.SyncItemVersion from saleorders s 
union all
select  s.syncitemid,d.SyncItemVersion from saleorders s,SaleDetail d where s.paysn = d.paysn
union all
select  s.syncitemid,b.SyncItemVersion from saleorders s,ConsumptionPayment b where s.paysn = b.paysn
union all
select  s.syncitemid,w.SyncItemVersion from saleorders s,WipeZero w where s.paysn =w.paysn ) as t group by SyncItemId ").ToList();
                    return(result);
                }
            }
            catch
            {
                return(new List <ISyncDataObject>());
            }
        }
 public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
 {
     try
     {
         using (var db = SyncDbContextFactory.Factory <EFDbContext>())
         {
             var result = db.Database.SqlQuery <SyncDataObject>(@"select  'SalePackage' EntityType, s.SyncItemId,(select max(t.SyncItemVersion) from ( 
             select s.SyncItemVersion
             union all
             select a.SyncItemVersion from SaleDetail a where s.PaySN= a.PaySN
             union all
             select b.SyncItemVersion from ConsumptionPayment b where s.PaySN= b.PaySN
             union all
             select c.SyncItemVersion from WipeZero c where s.PaySN= c.PaySN
             ) as t) SyncItemVersion  from SaleOrders s where s.storeid =@p0 and s.companyId= @p1", storeId, companyId).ToList();
             return(result);
         }
     }
     catch
     {
         return(new List <ISyncDataObject>());
     }
 }
        public ISyncDataObject GetItem(Guid guid, int companyId, string storeId)
        {
            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                var promitions = db.CommodityPromotions.FirstOrDefault(o => o.SyncItemId == guid);
                var bundling   = db.Bundlings.FirstOrDefault(o => o.CommodityId == promitions.Id);
                var package    = new Package()
                {
                    SyncItemId = guid, EntityType = "CommodityBundlingPackage"
                };
                var promitionItem = new List <CommodityPromotion>();
                var bundlingItem  = new List <Bundling>();

                promitionItem.Add(new CommodityPromotion().InitEntity(promitions));
                package.Init(promitionItem);

                bundlingItem.Add(new Bundling().InitEntity(bundling));
                package.Init(bundlingItem);

                package.Init(db.CommodityDiscounts.Where(o => o.CommodityId == promitions.Id).ToList().Select(o => new CommodityDiscount().InitEntity(o, true)));
                return(package);
            }
        }
Пример #23
0
        public byte[] CreateItem(ISyncDataObject data, Guid guid, int companyId, string storeId)
        {
            var temp = data as Package;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                try
                {
                    var commodityPromotion = temp.GetEntities <CommodityPromotion>();
                    var commodityDiscount  = temp.GetEntities <CommodityDiscount>();
                    db.CommodityPromotions.AddRange(commodityPromotion.Select(o => new Pharos.Logic.ApiData.Pos.Entity.LocalCeEntity.CommodityPromotion().InitEntity(o)));
                    db.CommodityDiscounts.AddRange(commodityDiscount.Select(o => new Pharos.Logic.ApiData.Pos.Entity.LocalCeEntity.CommodityDiscount().InitEntity(o)));
                    db.SaveChanges();
                    StoreManager.PubEvent("MarketingRefresh", new { StoreId = storeId, CompanyId = companyId });
                    var version = GetVersion(guid, companyId, storeId, db);
                    return(version.SyncItemVersion);
                }
                catch (DbEntityValidationException dbEx)
                {
                    throw dbEx;
                }
            }
        }
Пример #24
0
        public IEnumerable <ISyncDataObject> GetSyncObjects(int companyId, string storeId)
        {
            try
            {
                using (var db = SyncDbContextFactory.Factory <EFDbContext>())
                {
                    //PromotionType 1:单品折扣、 2:捆绑促销、 3:组合促销、4:买赠促销、 5:满元促销
                    var result = db.Database.SqlQuery <SyncDataObject>(@" select 'CommodityFreeGiftPackage' as  EntityType, SyncItemId,max (SyncItemVersion) SyncItemVersion from (
select  s.syncitemid,s.SyncItemVersion from [CommodityPromotion] s where s.PromotionType=4 and s.companyid =@p0 and ((','+s.storeid+',') like ('%,'+@p1+',%') or (','+s.storeid+',') like ('%,-1,%')) and State!=2
union all
select  s.syncitemid,d.SyncItemVersion from [CommodityPromotion] s,[FreeGiftPurchase] d where s.Id = d.CommodityId and s.PromotionType=4 and s.companyid =@p0 and ((','+s.storeid+',') like ('%,'+@p1+',%') or (','+s.storeid+',') like ('%,-1,%')) and State!=2
union all
select  s.syncitemid,b.SyncItemVersion from [CommodityPromotion] s,[FreeGiftPurchase] d,[FreeGiftPurchaseList] b where s.Id =d.CommodityId  AND d.GiftId= b.GiftId and s.PromotionType=4 and s.companyid =@p0 and ((','+s.storeid+',') like ('%,'+@p1+',%') or (','+s.storeid+',') like ('%,-1,%')) and State!=2
) as t group by SyncItemId", companyId, storeId).ToList();

                    return(result);
                }
            }
            catch
            {
                return(new List <ISyncDataObject>());
            }
        }
        public byte[] UpdateItem(Guid guid, ISyncDataObject mergedData, int companyId, string storeId)
        {
            var temp = mergedData as Pharos.SyncService.SyncEntities.ProductRecord;

            using (var db = SyncDbContextFactory.Factory <LocalCeDbContext>())
            {
                var dbEntity = db.ProductRecords.FirstOrDefault(o => o.SyncItemId == guid && o.CompanyId == companyId);
                dbEntity.InitEntity(temp);
                db.SaveChanges();
                try
                {
                    var qRefresh = new List <Pharos.ObjectModels.DTOs.MemoryCacheRefreshQuery>();
                    var item     = new ObjectModels.DTOs.MemoryCacheRefreshQuery()
                    {
                        CompanyId = companyId, StoreId = storeId, Barcode = temp.Barcode, ProductCode = temp.ProductCode
                    };
                    switch (temp.Nature)
                    {
                    case 0:
                        item.ProductType = ObjectModels.ProductType.Normal;
                        break;

                    case 1:
                        item.ProductType = ObjectModels.ProductType.Combination;
                        break;

                    case 2:
                        item.ProductType = ObjectModels.ProductType.Split;
                        break;
                    }
                    qRefresh.Add(item);
                    Pharos.Logic.ApiData.Pos.Cache.ProductCache.RefreshProduct(qRefresh);
                }
                catch { }
                return(temp.SyncItemVersion);
            }
        }