Ejemplo n.º 1
0
 public ProductInfo GetProductInfoByGtin(string gtin)
 {
     var productApplicationService = Container.Resolve<IProductApplicationService>();
     var product = productApplicationService.FindProductByGtin(gtin, true);
     if (product != null && product.Id != 0)
     {
         _statisticsDomainService.AddProductRequest(null, product.Id, _shopgunWebOperationContext.UserAgent, _shopgunWebOperationContext.IMEI, _shopgunWebOperationContext.Model, _shopgunWebOperationContext.OsVersion);
         var productInfo = new ProductInfo
                               {
                                   Id = product.Id,
                                   Name = product.ProductName,
                                   GTIN = product.GlobalTradeItemNumber,
                                   BrandId = product.Brand != null ? product.Brand.Id : 0,
                                   BrandName = product.Brand != null ? product.Brand.BrandName : "",
                                   CompanyId =
                                       product.Brand != null ? product.Brand.CompanyId.GetValueOrDefault() : 0,
                                   CompanyName =
                                       product.Brand != null && product.Brand.Owner != null
                                           ? product.Brand.Owner.CompanyName
                                           : "",
                                   AdviceInfos = product.ProductAdvices.Select(x => new AdviceInfo
                                                                                        {
                                                                                            AdviceId = x.Id.Value,
                                                                                            AdviceIntroduction = x.Introduction,
                                                                                            AdviceTag = x.Tag.Name,
                                                                                            AdviceType = "ProductAdvice",
                                                                                            AdviceableEntityId = x.ProductsId.Value,
                                                                                            AdviceableEntityName = x.ItemName,
                                                                                            AdvisorId = x.MentorId.Value,
                                                                                            AdvisorName = x.Mentor.MentorName,
                                                                                            Semaphore = x.Semaphore.ColorName
                                                                                        }).ToList()
                               };
         if (product.Brand != null)
         {
             productInfo.AdviceInfos.AddRange(product.Brand.BrandAdvices.Select(x => new AdviceInfo
                                                                                         {
                                                                                             AdviceId = x.Id.Value,
                                                                                             AdviceIntroduction =
                                                                                                 x.Introduction,
                                                                                             AdviceTag = x.Tag.Name,
                                                                                             AdviceType =
                                                                                                 "BrandAdvice",
                                                                                             AdviceableEntityId = x.BrandsId.Value,
                                                                                             AdviceableEntityName = x.ItemName,
                                                                                             AdvisorId = x.MentorId.Value,
                                                                                             AdvisorName = x.Mentor.MentorName,
                                                                                             Semaphore = x.Semaphore.ColorName
                                                                                         }));
             if (product.Brand.Owner != null)
             {
                 productInfo
                     .AdviceInfos
                     .AddRange(product.Brand.Owner.CompanyAdvices
                                   .Select(x => new AdviceInfo
                                                    {
                                                        AdviceId = x.Id.Value,
                                                        AdviceIntroduction =
                                                            x.Introduction,
                                                        AdviceTag = x.Tag.Name,
                                                        AdviceType =
                                                            "CompanyAdvice",
                                                        AdviceableEntityId =
                                                            x.CompanysId.Value,
                                                        AdviceableEntityName =
                                                            x.ItemName,
                                                        AdvisorId =
                                                            x.MentorId.Value,
                                                        AdvisorName =
                                                            x.Mentor.MentorName,
                                                        Semaphore =
                                                            x.Semaphore.ColorName
                                                    }));
             }
         }
         productInfo.AdviceInfos.AddRange(
             product.Ingredients.SelectMany(x => x.IngredientAdvices).Select(x => new AdviceInfo
                                                                                      {
                                                                                          AdviceId =
                                                                                              x.Id.Value,
                                                                                          AdviceIntroduction
                                                                                              =
                                                                                              x.
                                                                                              Introduction,
                                                                                          AdviceTag =
                                                                                              x.Tag.Name,
                                                                                          AdviceType =
                                                                                              "IngredientAdvice",
                                                                                          AdviceableEntityId = x.IngredientsId.Value,
                                                                                          AdviceableEntityName = x.ItemName,
                                                                                          AdvisorId = x.MentorId.Value,
                                                                                          AdvisorName = x.Mentor.MentorName,
                                                                                          Semaphore = x.Semaphore.ColorName
                                                                                      }));
         return productInfo;
     }
     return null;
 }
Ejemplo n.º 2
0
        public ProductInfo GetProductInfoByGtin(string gtin)
        {
            var productApplicationService = Container.Resolve <IProductApplicationService>();
            var product = productApplicationService.FindProductByGtin(gtin, true);

            if (product != null && product.Id != 0)
            {
                _statisticsDomainService.AddProductRequest(null, product.Id, _shopgunWebOperationContext.UserAgent, _shopgunWebOperationContext.IMEI, _shopgunWebOperationContext.Model, _shopgunWebOperationContext.OsVersion);
                var productInfo = new ProductInfo
                {
                    Id        = product.Id,
                    Name      = product.ProductName,
                    GTIN      = product.GlobalTradeItemNumber,
                    BrandId   = product.Brand != null ? product.Brand.Id : 0,
                    BrandName = product.Brand != null ? product.Brand.BrandName : "",
                    CompanyId =
                        product.Brand != null?product.Brand.CompanyId.GetValueOrDefault() : 0,
                            CompanyName =
                                product.Brand != null && product.Brand.Owner != null
                                                  ? product.Brand.Owner.CompanyName
                                                  : "",
                            AdviceInfos = product.ProductAdvices.Select(x => new AdviceInfo
                    {
                        AdviceId             = x.Id.Value,
                        AdviceIntroduction   = x.Introduction,
                        AdviceTag            = x.Tag.Name,
                        AdviceType           = "ProductAdvice",
                        AdviceableEntityId   = x.ProductsId.Value,
                        AdviceableEntityName = x.ItemName,
                        AdvisorId            = x.MentorId.Value,
                        AdvisorName          = x.Mentor.MentorName,
                        Semaphore            = x.Semaphore.ColorName
                    }).ToList()
                };
                if (product.Brand != null)
                {
                    productInfo.AdviceInfos.AddRange(product.Brand.BrandAdvices.Select(x => new AdviceInfo
                    {
                        AdviceId           = x.Id.Value,
                        AdviceIntroduction =
                            x.Introduction,
                        AdviceTag  = x.Tag.Name,
                        AdviceType =
                            "BrandAdvice",
                        AdviceableEntityId   = x.BrandsId.Value,
                        AdviceableEntityName = x.ItemName,
                        AdvisorId            = x.MentorId.Value,
                        AdvisorName          = x.Mentor.MentorName,
                        Semaphore            = x.Semaphore.ColorName
                    }));
                    if (product.Brand.Owner != null)
                    {
                        productInfo
                        .AdviceInfos
                        .AddRange(product.Brand.Owner.CompanyAdvices
                                  .Select(x => new AdviceInfo
                        {
                            AdviceId           = x.Id.Value,
                            AdviceIntroduction =
                                x.Introduction,
                            AdviceTag  = x.Tag.Name,
                            AdviceType =
                                "CompanyAdvice",
                            AdviceableEntityId =
                                x.CompanysId.Value,
                            AdviceableEntityName =
                                x.ItemName,
                            AdvisorId =
                                x.MentorId.Value,
                            AdvisorName =
                                x.Mentor.MentorName,
                            Semaphore =
                                x.Semaphore.ColorName
                        }));
                    }
                }
                productInfo.AdviceInfos.AddRange(
                    product.Ingredients.SelectMany(x => x.IngredientAdvices).Select(x => new AdviceInfo
                {
                    AdviceId =
                        x.Id.Value,
                    AdviceIntroduction
                        =
                            x.
                            Introduction,
                    AdviceTag =
                        x.Tag.Name,
                    AdviceType =
                        "IngredientAdvice",
                    AdviceableEntityId   = x.IngredientsId.Value,
                    AdviceableEntityName = x.ItemName,
                    AdvisorId            = x.MentorId.Value,
                    AdvisorName          = x.Mentor.MentorName,
                    Semaphore            = x.Semaphore.ColorName
                }));
                return(productInfo);
            }
            return(null);
        }