public Communication CreateCommunication(CopyItem copyItem) { var communication = new Communication { Id = Id, Definition = Definition, AffiliateId = AffiliateId, From = From, To = To, Copy = Copy == null ? null : Copy.Cast <ICommunicationRecipient>().ToList(), BlindCopy = BlindCopy == null ? null : BlindCopy.Cast <ICommunicationRecipient>().ToList(), Return = Return, Subject = copyItem.Text, Views = new List <CommunicationView>() }; foreach (var viewItem in copyItem.ViewItems) { if (viewItem.ResourceItems.Count == 0) { communication.Views.Add(new CommunicationView(viewItem.Text, viewItem.MimeType)); } else { communication.Views.Add(new CommunicationView(viewItem.Text, viewItem.MimeType, GetCommunicationResources(viewItem.ResourceItems))); } } // Look for temporary files. var tempFiles = GetTempFileAttachments(); if (tempFiles != null) { communication.AddAttachments(tempFiles); } // Look for permanent files. var attachments = GetAttachments(); if (attachments != null) { communication.AddAttachments(attachments); } return(communication); }