Beispiel #1
0
        public int CreateGoods(GoodsItem goods)
        {
            goods.Type = goods.GetType().FullName;
            using (var ts = new TransactionScope())
            {
                var dataGoods = Mapper.Map <Data.Models.GoodsItem>(goods);

                int id = goods.HeartId = dataGoods.HeartId = _heartService.CreateHeart(goods);

                dataGoods.SearchDescription = SearchHelper.ToSearchIndexText(dataGoods.HtmlDescription);
                _goodsItemGateway.Insert(dataGoods);

                foreach (var goodsCategory in goods.Categories)
                {
                    _goodsCategoryGateway.Insert(new GoodsCategory()
                    {
                        CategoryId = goodsCategory.ID, GoodsId = id
                    });
                }
                int k = 0;
                foreach (var goodsImageId in goods.Images)
                {
                    _goodsImageGateway.Insert(new GoodsImage()
                    {
                        ImageId = goodsImageId, HeartId = id, SortOrder = k
                    });
                    k++;
                }
                foreach (var goodsPack in goods.Packs)
                {
                    var dataGoodsPack = Mapper.Map <Data.Models.GoodsPack>(goodsPack);
                    dataGoodsPack.HeartId = id;
                    _goodsPackGateway.Insert(dataGoodsPack);
                }
                foreach (var compatibleGoods in goods.CompatibleGoods)
                {
                    _compatibleSetGoodsGateway.Insert(new CompatibleSetGoods()
                    {
                        CompatibleSetId = compatibleGoods.CompatibleSetId, HeartId = id
                    });
                }
                foreach (var specVal in goods.GoodsSpecs)
                {
                    specVal.HeartId = id;
                    var dataGoodsSpec = Mapper.Map <GoodsSpec>(specVal);
                    _goodsSpecGateway.Insert(dataGoodsSpec);
                }
                _searchService.UpdateIndex(goods);
                ts.Complete();
                return(id);
            }
        }
        public int CreateManufacturer(Manufacturer manufacturer)
        {
            manufacturer.Type = manufacturer.GetType().FullName;

            using (TransactionScope ts = new TransactionScope())
            {
                var dataRec = Mapper.Map <Data.Models.Manufacturer>(manufacturer);

                int id = manufacturer.HeartId = dataRec.HeartId = _heartService.CreateHeart(manufacturer);

                _manufacturerGateway.Insert(dataRec);

                ts.Complete();
                return(id);
            }
        }
Beispiel #3
0
        public int CreateCategory(Category category)
        {
            category.Type = category.GetType().FullName;

            var dataCategory = Mapper.Map <Data.Models.Category>(category);

            using (var ts = new TransactionScope())
            {
                int id = category.HeartId = dataCategory.HeartId = _heartService.CreateHeart(category);
                _categoryGateway.Insert(dataCategory);
                RemoveObjectFromCache("Categories");
                RemoveObjectFromCache("AllCategories");
                RemoveObjectFromCache($"ChildCategoriesFor{category.ParentCategoryId}");
                ts.Complete();
                return(id);
            }
        }
Beispiel #4
0
        public int CreatePage(Page page)
        {
            page.Type = page.GetType().FullName;
            int heartId;

            using (var ts = new TransactionScope())
            {
                heartId      = _heartService.CreateHeart(page);
                page.HeartId = heartId;
                var newPage = Mapper.Map <Data.Models.Page>(page);
                _pageGateway.Insert(newPage);
                page.CanonicalUrl = _heartService.GetCanonicalUrl(page.RelativeUrl);
                _searchService.UpdateIndex(page);
                ts.Complete();
            }
            AddOrUpdateCacheObject(GetPageCacheKey(page.RelativeUrl), page);
            return(heartId);
        }
Beispiel #5
0
        public int CreateAction(Action action)
        {
            action.Type = action.GetType().FullName;

            var dataRec = Mapper.Map <Data.Models.Action>(action);

            using (var ts = new TransactionScope())
            {
                int id = action.HeartId = dataRec.HeartId = _heartService.CreateHeart(action);

                _actionGateway.Insert(dataRec);


                foreach (var catId in action.Categories.Select(x => x.ID))
                {
                    _actionCategoryGateway.Insert(new ActionCategory()
                    {
                        ActionId = id, CategoryId = catId
                    });
                }
                foreach (var goodsId in action.Goods.Select(x => x.ID))
                {
                    _actionGoodsGateway.Insert(new ActionGoods()
                    {
                        ActionId = id, HeartId = goodsId
                    });
                }
                foreach (var manId in action.Manufacturers.Select(x => x.ID))
                {
                    _actionManufacturerGateway.Insert(new ActionManufacturer()
                    {
                        ActionId = id, ManufacturerId = manId
                    });
                }
                ts.Complete();
                return(id);
            }
        }
Beispiel #6
0
        public int CreateNewsItem(NewsItem news)
        {
            news.Type = news.GetType().FullName;
            var dataRec = Mapper.Map <Data.Models.NewsItem>(news);

            lock (_createNewsItemLockObj)
            {
                using (var ts = new TransactionScope())
                {
                    news.RelativeUrl = _heartService.GetNextAvailableRelativeUrl(news.RelativeUrl);
                    news.HeartId     = dataRec.HeartId = _heartService.CreateHeart(news);
                    _newsItemGateway.Insert(dataRec);
                    var tags = news.Tags?.Split(',').Select(x => x.Trim().ToLower()).ToArray() ?? new string[0];

                    var existingTags     = _tagGateway.Select();
                    var existingTagNames = existingTags.Select(x => x.Name).ToArray();
                    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)))
                    {
                        _newsItemTagGateway.Insert(news.HeartId, tag.TagId);
                    }

                    var catIds = news.Categories.Select(x => x.ID);
                    foreach (var catId in catIds)
                    {
                        _newsItemCategoryGateway.Insert(news.HeartId, catId);
                    }
                    _searchService.UpdateIndex(news);
                    ts.Complete();
                    return(news.HeartId);
                }
            }
        }