Exemplo n.º 1
0
        public void HandleEvent(ModelBoundEvent eventMessage)
        {
            if (!eventMessage.BoundModel.CustomProperties.ContainsKey("GMC"))
            {
                return;
            }

            var model = eventMessage.BoundModel.CustomProperties["GMC"] as GoogleProductModel;

            if (model == null)
            {
                return;
            }

            var utcNow = DateTime.UtcNow;
            var entity = _googleService.GetGoogleProductRecord(model.ProductId);
            var insert = (entity == null);

            if (entity == null)
            {
                entity = new GoogleProductRecord
                {
                    ProductId    = model.ProductId,
                    CreatedOnUtc = utcNow
                };
            }

            // map objects
            entity.AgeGroup     = model.AgeGroup;
            entity.Color        = model.Color;
            entity.Gender       = model.Gender;
            entity.Size         = model.Size;
            entity.Taxonomy     = model.Taxonomy;
            entity.Material     = model.Material;
            entity.Pattern      = model.Pattern;
            entity.Export       = model.Exporting;
            entity.UpdatedOnUtc = utcNow;

            entity.IsTouched = entity.IsTouched();

            if (!insert && !entity.IsTouched)
            {
                _googleService.DeleteGoogleProductRecord(entity);
                return;
            }

            if (insert)
            {
                _googleService.InsertGoogleProductRecord(entity);
            }
            else
            {
                _googleService.UpdateGoogleProductRecord(entity);
            }
        }
Exemplo n.º 2
0
        public void HandleEvent(ModelBoundEvent eventMessage)
        {
            if (!eventMessage.BoundModel.CustomProperties.ContainsKey("GMC"))
            {
                return;
            }

            var model = eventMessage.BoundModel.CustomProperties["GMC"] as GoogleProductModel;

            if (model == null)
            {
                return;
            }

            var utcNow = DateTime.UtcNow;
            var entity = _googleService.GetGoogleProductRecord(model.ProductId);
            var insert = (entity == null);

            if (entity == null)
            {
                entity = new GoogleProductRecord
                {
                    ProductId    = model.ProductId,
                    CreatedOnUtc = utcNow
                };
            }

            entity.AgeGroup              = model.AgeGroup;
            entity.Color                 = model.Color;
            entity.Gender                = model.Gender;
            entity.Size                  = model.Size;
            entity.Taxonomy              = model.Taxonomy;
            entity.Material              = model.Material;
            entity.Pattern               = model.Pattern;
            entity.Export                = model.Export2;
            entity.UpdatedOnUtc          = utcNow;
            entity.Multipack             = model.Multipack2 ?? 0;
            entity.IsBundle              = model.IsBundle;
            entity.IsAdult               = model.IsAdult;
            entity.EnergyEfficiencyClass = model.EnergyEfficiencyClass;
            entity.CustomLabel0          = model.CustomLabel0;
            entity.CustomLabel1          = model.CustomLabel1;
            entity.CustomLabel2          = model.CustomLabel2;
            entity.CustomLabel3          = model.CustomLabel3;
            entity.CustomLabel4          = model.CustomLabel4;

            entity.IsTouched = entity.IsTouched();

            if (!insert && !entity.IsTouched)
            {
                _googleService.DeleteGoogleProductRecord(entity);
                return;
            }

            if (insert)
            {
                _googleService.InsertGoogleProductRecord(entity);
            }
            else
            {
                _googleService.UpdateGoogleProductRecord(entity);
            }
        }