private IEnumerable <Product> MapProductsForBrand(IEnumerable <ProductBrand> products) { var collection = new List <Product>(); foreach (var product in products) { var result = new Product { Id = product.ProductId, Name = product.Product.ProductsMultilingual.FirstOrDefault().Name, VirtualName = product.Product.ProductsMultilingual.FirstOrDefault().Name.RemoveDiacritics(), Modified = product.Product.Modified, Risk = new Risk { Description = product.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Description, Id = product.Product.Risk.Id, Modified = product.Product.Risk.Modified, Name = product.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Name }, Description = product.Product.ProductsMultilingual.FirstOrDefault().Description }; collection.Add(result); } return(collection.Count == 0 ? null : collection); }
/// <summary> /// Get Product information by AliasId /// </summary> /// <param name="aliasId"></param> /// <returns></returns> public Product GetProductByAlias(int aliasId) { _logger.LogInformation($"BEGIN GetProductByAlias"); try { var product = _productRepository.GetProductByAlias(aliasId); if (product == null) { return(null); } var result = new Product { Id = product.ProductId, Name = product.Name, VirtualName = product.Name.RemoveDiacritics(), Modified = product.Product.Modified, Risk = new Risk { Description = product.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Description, Id = product.Product.Risk.Id, Modified = product.Product.Risk.Modified, Name = product.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Name }, Description = product.Description }; return(result); } catch (Exception ex) { _logger.LogError($"Exception on GetProductByAlias with message: {ex.Message}"); return(null); } }
private IEnumerable <Product> MapProducts(IEnumerable <ProductMultilingual> products) { var collection = new List <Product>(); foreach (var product in products) { Product result = MapProduct(product); collection.Add(result); } return(collection.Count == 0 ? null : collection); }