public virtual IEnumerable <ISalesAttachment> SelectSalesAttachments(SalesLiteratureTypeCode type) { var serviceContext = Dependencies.GetServiceContext(); var salesAttachments = Enumerable.Empty <ISalesAttachment>(); var product = serviceContext.GetProduct(Product.Id); var salesLiterature = product.GetRelatedEntities(serviceContext, "productsalesliterature_association") .Where(e => e.GetAttributeValue <bool?>("iscustomerviewable").GetValueOrDefault() && e.GetAttributeValue <OptionSetValue>("literaturetypecode") != null && e.GetAttributeValue <OptionSetValue>("literaturetypecode").Value == (int)type) .ToList(); if (!salesLiterature.Any()) { return(salesAttachments); } return(salesLiterature.Select(literature => SelectSalesAttachments(literature.ToEntityReference())) .Aggregate(salesAttachments, (current, attachments) => current.Union(attachments)) .OrderBy(e => e.FileName)); }
private ISalesAttachment GetSalesAttachment(Entity product, SalesLiteratureTypeCode type, string keywords) { var attachment = SelectSalesAttachments(product, type).FirstOrDefault(e => e.Keywords != null && e.Keywords.Contains(keywords)); return(attachment); }
private IEnumerable <ISalesAttachment> SelectSalesAttachments(Entity product, SalesLiteratureTypeCode type) { var salesAttachments = Enumerable.Empty <ISalesAttachment>(); var salesLiterature = product.GetRelatedEntities(_serviceContext, "productsalesliterature_association") .Where(s => s.GetAttributeValue <bool?>("iscustomerviewable").GetValueOrDefault() && s.GetAttributeValue <OptionSetValue>("literaturetypecode") != null && s.GetAttributeValue <OptionSetValue>("literaturetypecode").Value == (int)type) .ToArray(); if (!salesLiterature.Any()) { return(salesAttachments); } var salesliteratureitems = salesLiterature .Select(literature => SelectSalesAttachments(literature.ToEntityReference())) .Aggregate(salesAttachments, (current, attachments) => current.Union(attachments)) .OrderBy(e => e.FileName); return(salesliteratureitems); }