Esempio n. 1
0
        private void FillPacks(GoodsItem goodsItem)
        {
            try
            {
                var dataVals = _goodsPackGateway.SelectByGoods(goodsItem.HeartId);
                if (dataVals.Any())
                {
                    var vals = Mapper.Map <IList <GoodsPack> >(dataVals);
                    foreach (var goodsPack in vals)
                    {
                        goodsPack.PackInfo = _shopPackService.GetPack(goodsPack.PackId);
                    }
                    goodsItem.Packs = vals;
                }

                if (goodsItem.BasePackId.HasValue)
                {
                    var  basePack = goodsItem.Packs.FirstOrDefault(x => x.PackId == goodsItem.BasePackId);
                    Pack basePackInfo;
                    if (basePack != null)
                    {
                        basePackInfo = basePack.PackInfo;
                    }
                    else
                    {
                        basePackInfo = _shopPackService.GetPack(goodsItem.BasePackId.Value);
                    }
                    goodsItem.BasePack = basePackInfo;
                }
            }
            catch (Exception e)
            {
                _logService.LogError(new Exception($"Ошибка при заполнении упаковок товара {goodsItem.HeartId}", e));
            }
        }
Esempio n. 2
0
        private void FillCompatibles(GoodsItem goodsItem)
        {
            var compIds = _compatibleSetGoodsGateway.SelectByGoods(goodsItem.HeartId).Select(x => x.CompatibleSetId);
            var comps   = compIds.Select(x => _shopCompatiblesService.GetCompatibleSet(x)).ToList();

            goodsItem.CompatibleGoods = comps;
        }
Esempio n. 3
0
        private void FillCats(GoodsItem goodsItem)
        {
            var catsIds = _goodsCategoryGateway.SelectByGoods(goodsItem.HeartId).Select(x => x.CategoryId);
            var cats    = catsIds.Select(x => _categoryGateway.SelectOne(x));
            var idNames = Mapper.Map <IList <IdNamePair <int> > >(cats);

            goodsItem.Categories = idNames;
        }
Esempio n. 4
0
 private void FillActions(GoodsItem goodsItem, bool activeActionsOnly)
 {
     if (activeActionsOnly)
     {
         goodsItem.Actions = _shopActionService.GetActiveActionsForGoodsItem(goodsItem.HeartId);
     }
     else
     {
         goodsItem.Actions = _shopActionService.GetActionsForGoodsItem(goodsItem.HeartId);
     }
 }
Esempio n. 5
0
        private void FillSpecs(GoodsItem goodsItem)
        {
            var dataVals = _goodsSpecGateway.SelectByGoods(goodsItem.HeartId);
            var vals     = Mapper.Map <IList <SpecValue> >(dataVals);

            foreach (var specValue in vals)
            {
                specValue.Spec = _shopSpecService.GetSpec(specValue.SpecId);
            }
            goodsItem.GoodsSpecs = vals;
        }
Esempio n. 6
0
 private void FillManufacturers(GoodsItem goodsItem)
 {
     if (goodsItem.ManufacturerId.HasValue)
     {
         goodsItem.Manufacturer = _shopManufacturerService.GetManufacturer(goodsItem.ManufacturerId.Value);
     }
     if (goodsItem.SupplierId.HasValue)
     {
         goodsItem.Supplier = _shopManufacturerService.GetManufacturer(goodsItem.SupplierId.Value);
     }
 }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        private void FillData(GoodsItem goodsItem, bool activeActionsOnly = true)
        {
            var heart = _heartService.GetHeart(goodsItem.HeartId);

            goodsItem.FillHeart(heart);

            goodsItem.CanonicalUrl = _heartService.GetCanonicalUrl(heart.HeartId);

            FillImages(goodsItem);
            FillCompatibles(goodsItem);
            FillCats(goodsItem);
            FillActions(goodsItem, activeActionsOnly);
            FillPacks(goodsItem);
            FillSpecs(goodsItem);
            FillManufacturers(goodsItem);

            goodsItem.Rating = _goodsReviewService.GetGoodsRating(goodsItem.HeartId);

            if (activeActionsOnly)
            {
                goodsItem.Actions.Clear();
                goodsItem.Actions = _shopActionService.GetActiveActionsForGoodsItem(goodsItem.HeartId);
            }
        }
Esempio n. 9
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();
            }
        }
Esempio n. 10
0
        private void FillImages(GoodsItem goodsItem)
        {
            var imageIds = _goodsImageGateway.SelectByGoods(goodsItem.HeartId).OrderBy(x => x.SortOrder).Select(x => x.ImageId);

            goodsItem.Images = imageIds.ToList();
        }