Ejemplo n.º 1
0
        public void UpdateNewsItem(NewsItem news)
        {
            var originHeart = _heartService.GetHeart(news.HeartId);

            if (news.RelativeUrl != originHeart.RelativeUrl)
            {
                bool relativeUrlExists = _heartService.CheckIfUrlExists(news.RelativeUrl);
                if (relativeUrlExists)
                {
                    throw new ArgumentException("Этот адрес уже занят");
                }
            }

            var dataRec          = Mapper.Map <Data.Models.NewsItem>(news);
            var tags             = !string.IsNullOrEmpty(news.Tags) ? news.Tags.Split(',').Select(x => x.Trim().ToLower()).ToList() : new List <string>();
            var originalTags     = _tagGateway.SelectByNews(news.HeartId);
            var existingTags     = _tagGateway.Select();
            var existingTagNames = existingTags.Select(x => x.Name).ToArray();

            var existingCatIds = _newsItemCategoryGateway.SelectCategoryIdsByNews(news.HeartId);
            var catIds         = news.Categories.Select(x => x.ID).ToArray();

            using (var ts = new TransactionScope())
            {
                _heartService.UpdateHeart(news);

                _newsItemGateway.Update(dataRec);

                foreach (var tag in tags.Except(existingTagNames))
                {
                    int tagId = _tagGateway.Insert(tag);
                    _newsItemTagGateway.Insert(news.HeartId, tagId);
                }
                foreach (var tag in existingTags.Where(x => tags.Contains(x.Name) && originalTags.All(y => y.TagId != x.TagId)))
                {
                    _newsItemTagGateway.Insert(news.HeartId, tag.TagId);
                }

                if (originalTags.Any(x => !tags.Contains(x.Name)))
                {
                    foreach (var tag in originalTags.Where(x => !tags.Contains(x.Name)))
                    {
                        _newsItemTagGateway.Delete(news.HeartId, tag.TagId);
                    }
                    _tagGateway.DeleteUnassociated();
                }

                foreach (var catId in catIds.Except(existingCatIds))
                {
                    _newsItemCategoryGateway.Insert(news.HeartId, catId);
                }
                foreach (var catId in existingCatIds.Except(catIds))
                {
                    _newsItemCategoryGateway.Delete(news.HeartId, catId);
                }
                _searchService.UpdateIndex(news);
                ts.Complete();
            }
        }
Ejemplo n.º 2
0
        public void UpdateManufacturer(Manufacturer manufacturer)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                _heartService.UpdateHeart(manufacturer);

                var dataRec = Mapper.Map <Data.Models.Manufacturer>(manufacturer);
                _manufacturerGateway.Update(dataRec);

                ts.Complete();
            }
        }
Ejemplo n.º 3
0
        public void UpdatePage(Page page)
        {
            var original = _heartService.GetHeart(page.HeartId);

            using (var ts = new TransactionScope())
            {
                _heartService.UpdateHeart(page);
                var dataPage = Mapper.Map <Data.Models.Page>(page);
                _pageGateway.Update(dataPage);
                page.CanonicalUrl = _heartService.GetCanonicalUrl(page.RelativeUrl);
                _searchService.UpdateIndex(page);
                ts.Complete();
            }
            RemoveObjectFromCache(GetPageCacheKey(original.RelativeUrl));
        }
Ejemplo n.º 4
0
        public void UpdateCategory(Category category)
        {
            var oldCategory = GetCategory(category.HeartId);

            var dataRec     = Mapper.Map <Data.Models.Category>(category);
            var oldSpecCats = _specCategoryGateway.SelectByCategory(category.HeartId);

            using (var ts = new TransactionScope())
            {
                _heartService.UpdateHeart(category);

                _categoryGateway.Update(dataRec);
                foreach (var spec in oldSpecCats.Where(x => category.OrderFormSpecs.All(y => x.SpecId != y.SpecId)).ToList())
                {
                    _specCategoryGateway.Delete(spec);
                }

                foreach (var spec in category.OrderFormSpecs.Where(x => oldSpecCats.All(y => x.SpecId != y.SpecId)))
                {
                    _specCategoryGateway.Insert(new SpecCategory()
                    {
                        CategoryId = category.HeartId,
                        SpecId     = spec.SpecId
                    });
                }
                ts.Complete();
            }


            RemoveObjectFromCache($"ChildCategoriesFor{oldCategory.ParentCategoryId}");
            RemoveObjectFromCache($"ChildCategoriesFor{category.ParentCategoryId}");


            RemoveObjectFromCache("Categories");
            RemoveObjectFromCache("AllCategories");
            RemoveObjectFromCache(GetCategoryCanonicalUrlCacheKey(category.RelativeUrl));
            RemoveObjectFromCache(GetCategoryCanonicalUrlCacheKey(oldCategory.RelativeUrl));

            RemoveObjectFromCache(GetCategoryIDCanonicalUrlCacheKey(category.HeartId));
        }
Ejemplo n.º 5
0
        public void UpdateAction(Action action)
        {
            var dataAction = Mapper.Map <Data.Models.Action>(action);

            using (var ts = new TransactionScope())
            {
                int actionId = action.HeartId;

                _heartService.UpdateHeart(action);

                _actionGateway.Update(dataAction);

                var oldCats = _actionCategoryGateway.SelectByAction(actionId);
                var newCats = action.Categories;
                foreach (var oldCat in oldCats)
                {
                    if (newCats.All(x => x.ID != oldCat.CategoryId))
                    {
                        _actionCategoryGateway.Delete(oldCat);
                    }
                }
                foreach (var newCat in newCats)
                {
                    if (oldCats.All(x => x.CategoryId != newCat.ID))
                    {
                        _actionCategoryGateway.Insert(new ActionCategory()
                        {
                            ActionId   = actionId,
                            CategoryId = newCat.ID
                        });
                    }
                }

                var oldGoods = _actionGoodsGateway.SelectByAction(actionId);
                var newGoods = action.Goods;
                foreach (var old in oldGoods)
                {
                    if (newGoods.All(x => x.ID != old.HeartId))
                    {
                        _actionGoodsGateway.Delete(old);
                    }
                }
                foreach (var @new in newGoods)
                {
                    if (oldGoods.All(x => x.HeartId != @new.ID))
                    {
                        _actionGoodsGateway.Insert(new ActionGoods()
                        {
                            ActionId = actionId,
                            HeartId  = @new.ID
                        });
                    }
                }

                var oldMans = _actionManufacturerGateway.SelectByAction(actionId);
                var newMans = action.Manufacturers;

                foreach (var oldMan in oldMans)
                {
                    if (newMans.All(x => x.ID != oldMan.ManufacturerId))
                    {
                        _actionManufacturerGateway.Delete(oldMan);
                    }
                }

                foreach (var newMan in newMans)
                {
                    if (oldMans.All(x => x.ManufacturerId != newMan.ID))
                    {
                        _actionManufacturerGateway.Insert(new ActionManufacturer()
                        {
                            ActionId       = actionId,
                            ManufacturerId = newMan.ID
                        });
                    }
                }
                ts.Complete();
            }
        }
Ejemplo n.º 6
0
        public void UpdateGoods(GoodsItem goods)
        {
            int heartId   = goods.HeartId;
            var dataGoods = Mapper.Map <Data.Models.GoodsItem>(goods);

            //dataGoods.SearchDescription = SearchHelper.ToSearchIndexText(dataGoods.HtmlDescription);

            using (var ts = new TransactionScope())
            {
                _heartService.UpdateHeart(goods);

                _goodsItemGateway.Update(dataGoods);

                var oldCats = _goodsCategoryGateway.SelectByGoods(heartId);
                var newCats = goods.Categories;
                foreach (var oldCat in oldCats)
                {
                    if (newCats.All(x => x.ID != oldCat.CategoryId))
                    {
                        _goodsCategoryGateway.Delete(oldCat);
                    }
                }
                foreach (var newCat in newCats)
                {
                    if (oldCats.All(x => x.CategoryId != newCat.ID))
                    {
                        _goodsCategoryGateway.Insert(new GoodsCategory()
                        {
                            GoodsId    = heartId,
                            CategoryId = newCat.ID
                        });
                    }
                }

                var oldSpecs = _goodsSpecGateway.SelectByGoods(heartId);
                var newSpecs = goods.GoodsSpecs;
                foreach (var oldSpec in oldSpecs)
                {
                    if (newSpecs.All(x => x.SpecId != oldSpec.SpecId))
                    {
                        _goodsSpecGateway.Delete(oldSpec);
                    }
                }
                foreach (var newSpec in newSpecs)
                {
                    var dataSpecVal = Mapper.Map <GoodsSpec>(newSpec);
                    if (oldSpecs.All(x => x.SpecId != newSpec.SpecId))
                    {
                        _goodsSpecGateway.Insert(dataSpecVal);
                    }
                    else
                    {
                        _goodsSpecGateway.Update(dataSpecVal);
                    }
                }

                var oldImages = _goodsImageGateway.SelectByGoods(heartId);
                var newImages = goods.Images;
                foreach (var oldImage in oldImages)
                {
                    if (newImages.All(x => !Equals(x, oldImage.ImageId)))
                    {
                        _goodsImageGateway.Delete(oldImage);
                    }
                }
                foreach (var newImage in newImages)
                {
                    if (oldImages.All(x => !Equals(x.ImageId, newImage)))
                    {
                        _goodsImageGateway.Insert(new GoodsImage()
                        {
                            HeartId = heartId,
                            ImageId = newImage
                        });
                    }
                }

                int k = 0;
                foreach (var image in goods.Images)
                {
                    _goodsImageGateway.Update(new GoodsImage()
                    {
                        HeartId   = heartId,
                        ImageId   = image,
                        SortOrder = k
                    });
                    k++;
                }

                var oldPacks = _goodsPackGateway.SelectByGoods(heartId);
                var newPacks = goods.Packs;
                foreach (var oldPack in oldPacks)
                {
                    if (newPacks.All(x => x.PackId != oldPack.PackId))
                    {
                        _goodsPackGateway.Delete(oldPack);
                    }
                }
                foreach (var newPack in newPacks)
                {
                    var dataPackVal = Mapper.Map <Data.Models.GoodsPack>(newPack);
                    dataPackVal.HeartId = heartId;
                    if (oldPacks.All(x => x.PackId != newPack.PackId))
                    {
                        _goodsPackGateway.Insert(dataPackVal);
                    }
                    else
                    {
                        _goodsPackGateway.Update(dataPackVal);
                    }
                }

                var oldActions = _actionGoodsGateway.SelectByGoods(heartId);
                var newActions = goods.Actions;
                foreach (var oldAction in oldActions)
                {
                    if (newActions.All(x => x.ID != oldAction.ActionId))
                    {
                        _actionGoodsGateway.Delete(oldAction);
                    }
                }
                foreach (var newAction in newActions)
                {
                    if (oldActions.All(x => x.ActionId != newAction.ID))
                    {
                        _actionGoodsGateway.Insert(new ActionGoods()
                        {
                            ActionId = newAction.ID, HeartId = heartId
                        });
                    }
                }

                var oldComps = _compatibleSetGoodsGateway.SelectByGoods(heartId);
                var newComps = goods.CompatibleGoods;
                foreach (var oldComp in oldComps)
                {
                    if (newComps.All(x => x.CompatibleSetId != oldComp.CompatibleSetId))
                    {
                        _compatibleSetGoodsGateway.Delete(oldComp);
                    }
                }
                foreach (var newComp in newComps)
                {
                    if (oldComps.All(x => x.CompatibleSetId != newComp.CompatibleSetId))
                    {
                        _compatibleSetGoodsGateway.Insert(new CompatibleSetGoods()
                        {
                            HeartId         = heartId,
                            CompatibleSetId = newComp.CompatibleSetId
                        });
                    }
                }
                _searchService.UpdateIndex(goods);
                ts.Complete();
            }
        }