Пример #1
0
 public string GetProductXml(int id)
 {
     using (DpcModelDataContext context = _customer.DatabaseType == DatabaseType.Postgres
                     ? GetNpgSqlDpcModelDataContext(_customer.ConnectionString)
                     : GetSqlServerDpcModelDataContext(_customer.ConnectionString))
     {
         var product = context.Products.FirstOrDefault(p => p.DpcId == id && p.IsLive == _state &&
                                                       p.Language == _language &&
                                                       p.Format == (_isJson ? "json" : "xml") &&
                                                       p.Version == 1 && string.IsNullOrEmpty(p.Slug));
         return(product?.Data);
     }
 }
Пример #2
0
        public ProductInfo[] GetByIds(int[] productIDs)
        {
            Throws.IfArrayArgumentNullOrEmpty(productIDs, _ => productIDs);

            using (DpcModelDataContext context = _customer.DatabaseType == DatabaseType.Postgres
                    ? GetNpgSqlDpcModelDataContext(_customer.ConnectionString)
                    : GetSqlServerDpcModelDataContext(_customer.ConnectionString))
            {
                var products = context.GetProducts(new ProductLocator
                {
                    Language    = _language,
                    IsLive      = _state,
                    Version     = 1,
                    QueryFormat = _isJson ? "json" : "xml"
                }).Where(p =>
                         productIDs.Contains(p.DpcId)
                         ).ToArray();

                var list = new List <ProductInfo>();
                // производим запрос - без этого не будет работать dependency
                foreach (var product in products)
                {
                    var item = new ProductInfo
                    {
                        Id                    = product.DpcId,
                        Updated               = product.Updated,
                        Alias                 = product.Alias,
                        Hash                  = product.Hash,
                        Title                 = product.Title,
                        LastPublishedUserId   = product.UserUpdatedId,
                        LastPublishedUserName = product.UserUpdated
                    };

                    list.Add(item);
                }

                return(list.ToArray());
            }
        }
Пример #3
0
 public DpcProductService(ILogger logger, DpcModelDataContext context)
 {
     Logger   = logger;
     _context = context;
 }