Example #1
0
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            var result = base.Update(item);

            if (result.HasViolation)
            {
                return(result);
            }
            if (item.ProductTags != null)
            {
                _productTagService.Remove(m => m.ProductId == item.ID);
                _productTagService.BeginBulkSave();
                foreach (var tag in item.ProductTags.Where(m => m.Selected))
                {
                    _productTagService.Add(new ProductTag {
                        ProductId = item.ID, TagId = tag.ID
                    });
                }
                _productTagService.SaveChanges();
            }
            if (item.ProductImages != null)
            {
                _productImageService.BeginBulkSave();
                item.ProductImages.Each(m =>
                {
                    m.ProductId = item.ID;
                    SaveImages(m);
                });
                _productImageService.SaveChanges();
            }
            return(result);
        }
Example #2
0
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            ServiceResult <ProductEntity> result = new ServiceResult <ProductEntity>();

            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return(result);
                }
            }
            _eventManager.Trigger(Events.OnProductUpdating, item);
            BeginTransaction(() =>
            {
                result = base.Update(item);
                if (!result.HasViolation)
                {
                    if (item.ProductTags != null)
                    {
                        _productTagService.Remove(m => m.ProductId == item.ID);
                        _productTagService.BeginBulkSave();
                        foreach (var tag in item.ProductTags.Where(m => m.Selected))
                        {
                            _productTagService.Add(new ProductTag {
                                ProductId = item.ID, TagId = tag.ID
                            });
                        }
                        _productTagService.SaveChanges();
                    }
                    if (item.ProductImages != null)
                    {
                        _productImageService.BeginBulkSave();
                        item.ProductImages.Each(m =>
                        {
                            m.ProductId = item.ID;
                            SaveImages(m);
                        });
                        _productImageService.SaveChanges();
                    }
                }
            });
            _eventManager.Trigger(Events.OnProductUpdated, item);
            return(result);
        }
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    var re = new ServiceResult <ProductEntity>();
                    re.RuleViolations.Add(new RuleViolation("Url", "UrlÒÑ´æÔÚ"));
                    return(re);
                }
            }
            var result = base.Update(item);

            if (result.HasViolation)
            {
                return(result);
            }
            if (item.ProductTags != null)
            {
                _productTagService.Remove(m => m.ProductId == item.ID);
                _productTagService.BeginBulkSave();
                foreach (var tag in item.ProductTags.Where(m => m.Selected))
                {
                    _productTagService.Add(new ProductTag {
                        ProductId = item.ID, TagId = tag.ID
                    });
                }
                _productTagService.SaveChanges();
            }
            if (item.ProductImages != null)
            {
                _productImageService.BeginBulkSave();
                item.ProductImages.Each(m =>
                {
                    m.ProductId = item.ID;
                    SaveImages(m);
                });
                _productImageService.SaveChanges();
            }
            return(result);
        }