Пример #1
0
        public async Task <GoodsDTO> GetOnlineGoods(string id)
        {
            var obj = _onlineGoodsRepository.Get(id);

            if (obj != null)
            {
                var goodsImages = _onlineGoodsImageRepository.GetFiltered(o => o.GoodsId == id).Select(item => new GoodsImageDTO {
                    GoodsId = item.GoodsId, Id = item.Id, ImageId = item.ImageId
                }).ToList();

                var imageIds = goodsImages.Select(o => o.ImageId).ToList();
                var images   = await _imageServiceProxy.GetImagesByIds(imageIds);

                foreach (var img in goodsImages)
                {
                    var pic = images.FirstOrDefault(o => o.Id == img.ImageId);

                    img.HttpPath    = pic?.HttpPath;
                    img.Title       = pic?.Title;
                    img.Description = pic?.Description;
                }

                var grouponCondition = _onlineGrouponConditionRepository.GetFiltered(o => o.GoodsId == id).Select(item => new GrouponConditionDTO {
                    Id = item.Id, GoodsId = item.GoodsId, MoreThanNumber = item.MoreThanNumber, Price = item.Price
                });

                return(new GoodsDTO
                {
                    Category = obj.Category,
                    Description = obj.Description,
                    Detail = obj.Detail,
                    Id = obj.Id,
                    ItemNumber = obj.ItemNumber,
                    MarketPrice = obj.MarketPrice,
                    OptionalPropertyJsonObject = obj.OptionalPropertyJsonObject,
                    Status = obj.Status,
                    Stock = obj.Stock,
                    StoreId = obj.StoreId,
                    SubCategory = obj.SubCategory,
                    Title = obj.Title,
                    Unit = obj.Unit,
                    UnitPrice = obj.UnitPrice,
                    GoodsImages = goodsImages,
                    GrouponConditions = grouponCondition,
                    DistributionScope = obj.DistributionScope,
                    VideoPath = obj.VideoPath,
                    GoodsCategoryName = obj.GoodsCategoryName
                });
            }
            return(null);
        }
Пример #2
0
        public void Handle(GoodsShelvedEvent evnt)
        {
            var eventSource = evnt.Source as Goods;

            var goods = _onlineGoodsRepository.Get(eventSource.Id);

            if (goods == null)
            {
                var obj = new OnlineGoods
                {
                    CreatedBy   = eventSource.CreatedBy,
                    CreatedOn   = eventSource.CreatedOn,
                    Description = eventSource.Description,
                    Detail      = eventSource.Detail,
                    ItemNumber  = eventSource.ItemNumber,
                    LastUpdBy   = eventSource.LastUpdBy,
                    LastUpdOn   = eventSource.LastUpdOn,
                    MarketPrice = eventSource.MarketPrice,
                    OptionalPropertyJsonObject = eventSource.OptionalPropertyJsonObject,
                    Stock             = eventSource.Stock,
                    StoreId           = eventSource.StoreId,
                    Title             = eventSource.Title,
                    Unit              = eventSource.Unit,
                    UnitPrice         = eventSource.UnitPrice,
                    Category          = eventSource.Category,
                    SubCategory       = eventSource.SubCategory,
                    DistributionScope = eventSource.DistributionScope,
                    Address           = eventSource.Address
                };

                obj.InitAddress();
                obj.SetId(eventSource.Id);
                obj.InitStatus();

                _onlineGoodsRepository.Add(obj);

                foreach (var item in eventSource.GoodsImages)
                {
                    _onlineGoodsImageRepository.Add(new OnlineGoodsImage {
                        CreatedOn = item.CreatedOn, GoodsId = item.GoodsId, ImageId = item.ImageId
                    });
                }

                foreach (var item in eventSource.GrouponConditions)
                {
                    _onlineGrouponConditionRepository.Add(new OnlineGrouponCondition {
                        GoodsId = item.GoodsId, MoreThanNumber = item.MoreThanNumber, Price = item.Price
                    });
                }
                _dbUnitOfWork.Commit();
            }
            else
            {
                goods.Description = eventSource.Description;
                goods.Detail      = eventSource.Detail;
                goods.ItemNumber  = eventSource.ItemNumber;
                goods.LastUpdBy   = eventSource.LastUpdBy;
                goods.LastUpdOn   = eventSource.LastUpdOn;
                goods.MarketPrice = eventSource.MarketPrice;
                goods.OptionalPropertyJsonObject = eventSource.OptionalPropertyJsonObject;
                goods.Stock = eventSource.Stock;
                //goods.StoreId = eventSource.StoreId;
                goods.Title       = eventSource.Title;
                goods.Unit        = eventSource.Unit;
                goods.UnitPrice   = eventSource.UnitPrice;
                goods.Category    = eventSource.Category;
                goods.SubCategory = eventSource.SubCategory;
                goods.Address     = eventSource.Address;
                goods.InitAddress();

                goods.InitStatus();

                _onlineGoodsRepository.Update(goods);

                var imgs = _onlineGoodsImageRepository.GetFiltered(o => o.GoodsId == eventSource.Id).ToList();
                imgs.ForEach(img => { _onlineGoodsImageRepository.Remove(img); });

                var conditions = _onlineGrouponConditionRepository.GetFiltered(o => o.GoodsId == eventSource.Id).ToList();
                conditions.ForEach(condition => { _onlineGrouponConditionRepository.Remove(condition); });

                foreach (var item in eventSource.GoodsImages)
                {
                    _onlineGoodsImageRepository.Add(new OnlineGoodsImage {
                        CreatedOn = item.CreatedOn, GoodsId = item.GoodsId, ImageId = item.ImageId
                    });
                }

                foreach (var item in eventSource.GrouponConditions)
                {
                    _onlineGrouponConditionRepository.Add(new OnlineGrouponCondition {
                        GoodsId = item.GoodsId, MoreThanNumber = item.MoreThanNumber, Price = item.Price
                    });
                }

                _dbUnitOfWork.Commit();
            }

            _bus.Publish(evnt);
        }