Ejemplo n.º 1
0
 public SlackMessage WithMessageText(string message)
 {
     Message = message;
     if (Attachments.Any())
     {
         Attachments.Last().Text = message;
     }
     return(this);
 }
        public static string GetAttachmentPath(LoginUser loginUser, int parentOrganizationID)
        {
            Attachments attachements = new Attachments(loginUser);

            attachements.LoadByReference(ReferenceType.CustomerHubLogo, parentOrganizationID);

            //Order by Descending so that we get the newest logo uploaded since more than one can exist.
            if (attachements.Any())
            {
                return(attachements.OrderByDescending(a => a.DateCreated).First().Path);
            }
            return(String.Empty);
        }
Ejemplo n.º 3
0
        private void UpdateContentTypeHeader()
        {
            string contentTypeString = Constants.ContentTypes.Soap;

            if (Attachments.Any())
            {
                ContentType contentType = new Multipart("related").ContentType;
                contentType.Parameters["type"] = contentTypeString;
                contentType.Charset            = Encoding.UTF8.HeaderName.ToLowerInvariant();
                contentTypeString = contentType.ToString();
            }

            ContentType = contentTypeString.Replace("Content-Type: ", string.Empty);
        }
Ejemplo n.º 4
0
        public override bool IsValid()
        {
            if (!base.IsValid())
            {
                return(false);
            }

            if (Attachments == null || !Attachments.Any())
            {
                ValidationFailureList.Add("No attachments found in report settings");
                return(false);
            }

            return(true);
        }
        public static AttachmentProxy LoadByReference(LoginUser loginUser, int refID, ReferenceType refType)
        {
            Attachments attachements = new Attachments(loginUser);

            attachements.LoadByReference(ReferenceType.CustomerHubLogo, refID);

            if (attachements.Any())
            {
                //Order by Descending so that we get the newest logo uploaded since more than one can exist.
                return(attachements.OrderByDescending(a => a.DateCreated).First().GetProxy());
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Delete all records from hard drive.
        /// </summary>
        internal void Delete()
        {
            Delete(DiagnosticDataPath);
            Delete(RecordPath);

            //remove database attachments
            if (Attachments != null && Attachments.Any())
            {
                foreach (var attachment in Attachments)
                {
                    if (IsInsideDatabaseDirectory(attachment))
                    {
                        Delete(attachment);
                    }
                }
            }
        }
        public static List <AttachmentProxy> GetAttachments(LoginUser loginUser, ReferenceType refType, int refID)
        {
            Attachments attachments = new Attachments(loginUser);

            attachments.LoadByReference(refType, refID);

            List <AttachmentProxy> results = new List <AttachmentProxy>();

            if (attachments.Any())
            {
                for (int a = 0; a < attachments.Count(); a++)
                {
                    results.Add(attachments[a].GetProxy());
                }
            }
            return(results);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Removes the given attachment from this message.
        /// </summary>
        /// <param name="tobeRemoved">The tobe removed.</param>
        public void RemoveAttachment(Attachment tobeRemoved)
        {
            if (tobeRemoved == null)
            {
                throw new ArgumentNullException(nameof(tobeRemoved));
            }

            Attachment foundAttachment = _attachmens.FirstOrDefault(a => a == tobeRemoved);

            if (foundAttachment != null)
            {
                _attachmens.Remove(foundAttachment);
                foundAttachment.Content?.Dispose();
            }

            if (!Attachments.Any())
            {
                ContentType = Constants.ContentTypes.Soap;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Save data to hard drive
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            try
            {
                _diagnosticDataJson = Record.ToJson();
                DiagnosticDataPath  = Save(_diagnosticDataJson, string.Format("{0}-attachment", Id));

                if (Attachments != null && Attachments.Any())
                {
                    foreach (var attachment in Attachments)
                    {
                        if (IsInsideDatabaseDirectory(attachment))
                        {
                            Size += new FileInfo(attachment).Length;
                        }
                    }
                }
                //save record
                RecordPath = Path.Combine(_path, string.Format("{0}-record.json", Id));
                //check current record size
                var    json = ToJson();
                byte[] file = Encoding.UTF8.GetBytes(json);
                //add record size
                Size += file.Length;
                RecordWriter.Write(json, string.Format("{0}-record", Id));
                return(true);
            }
            catch (IOException io)
            {
                Debug.Log(string.Format("Received {0} while saving data to database.",
                                        "IOException"));
                Debug.Log(string.Format("Message {0}", io.Message));
                return(false);
            }
            catch (Exception ex)
            {
                Debug.Log(string.Format("Received {0} while saving data to database.", ex.GetType().Name));
                Debug.Log(string.Format("Message {0}", ex.Message));
                return(false);
            }
        }
Ejemplo n.º 10
0
 public bool IsValid()
 {
     return(!string.IsNullOrEmpty(Name) &&
            !string.IsNullOrEmpty(Title) &&
            !string.IsNullOrEmpty(Description) &&
            Uri.IsWellFormedUriString(Url.ToString(), UriKind.RelativeOrAbsolute) &&
            Uri.IsWellFormedUriString(ParentStoryUrl.ToString(), UriKind.RelativeOrAbsolute) &&
            KeyIdentifiers != null &&
            KeyIdentifiers.Any() ? KeyIdentifiers.All(s => s.IsValid()) : true &&
            TestCases != null &&
            TestCases.Any() ? TestCases.All(s => s.IsValid()) : true &&
            Checkups != null &&
            Checkups.Any() ? Checkups.All(s => s.IsValid()) : true &&
            Attachments != null &&
            Attachments.Any() ? Attachments.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            Queries != null &&
            Queries.Any() ? Queries.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            Scripts != null &&
            Scripts.Any() ? Scripts.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            SubTasks.Any() ? SubTasks.All(s => s.IsValid()) : true);
 }
        /// <summary>
        /// Check if the message has content
        /// </summary>
        /// <returns>Returns true if this message has any content to send</returns>
        public bool HasContent()
        {
            if (!string.IsNullOrWhiteSpace(Text))
            {
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(Summary))
            {
                return(true);
            }

            if (Attachments != null && Attachments.Any())
            {
                return(true);
            }

            if (ChannelData != null)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 12
0
        public virtual void Save(System.IO.TextWriter txt)
        {
            txt.WriteLine("Date: {0}", (Date == DateTime.MinValue ? LocalTime.Now : Date).GetRFC2060Date());
            txt.WriteLine("To: {0}", string.Join("; ", To.Select(x => x.ToString())));
            txt.WriteLine("Cc: {0}", string.Join("; ", Cc.Select(x => x.ToString())));
            txt.WriteLine("Reply-To: {0}", string.Join("; ", ReplyTo.Select(x => x.ToString())));
            txt.WriteLine("Bcc: {0}", string.Join("; ", Bcc.Select(x => x.ToString())));
            if (Sender != null)
            {
                txt.WriteLine("Sender: {0}", Sender);
            }
            if (From != null)
            {
                txt.WriteLine("From: {0}", From);
            }
            if (!string.IsNullOrEmpty(MessageID))
            {
                txt.WriteLine("Message-ID: {0}", MessageID);
            }

            var otherHeaders = Headers.Where(x => !SpecialHeaders.Contains(x.Key, StringComparer.InvariantCultureIgnoreCase));

            foreach (var header in otherHeaders)
            {
                txt.WriteLine("{0}: {1}", header.Key, header.Value);
            }

            if (Importance != MailPriority.Normal)
            {
                txt.WriteLine("Importance: {0}", (int)Importance);
            }
            txt.WriteLine("Subject: {0}", Subject);

            string boundary = null;

            if (Attachments.Any() || AlternateViews.Any())
            {
                boundary = $"--boundary_{Guid.NewGuid()}";
                txt.WriteLine("Content-Type: multipart/mixed; boundary={0}", boundary);
            }

            // signal end of headers
            txt.WriteLine();

            if (boundary != null)
            {
                txt.WriteLine("--" + boundary);
                txt.WriteLine();
            }

            txt.WriteLine(Body);

            AlternateViews.Union(Attachments).ToList().ForEach(att =>
            {
                txt.WriteLine("--" + boundary);
                txt.WriteLine(string.Join("\n", att.Headers.Select(h => $"{h.Key}: {h.Value}")));
                txt.WriteLine();
                txt.WriteLine(att.Body);
            });

            if (boundary != null)
            {
                txt.WriteLine("--" + boundary + "--");
            }
        }
Ejemplo n.º 13
0
        public Message ToMimeMessage(int tenant, string user, bool load_attachments)
        {
            var mime_message = new Message
            {
                Date = DateTime.Now,
                From = new Address(From, string.IsNullOrEmpty(DisplayName) ? "" : Codec.RFC2047Encode(DisplayName))
            };

            if (Important)
            {
                mime_message.Priority = MessagePriority.High;
            }

            mime_message.To.AddRange(To.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Cc.AddRange(Cc.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Bcc.AddRange(Bcc.ConvertAll(address =>
            {
                var addr  = Parser.ParseAddress(address);
                addr.Name = string.IsNullOrEmpty(addr.Name) ? "" : Codec.RFC2047Encode(addr.Name);
                return(new Address(addr.Email, addr.Name));
            }));

            mime_message.Subject = Codec.RFC2047Encode(Subject);

            // Set correct body
            if (Attachments.Any() || AttachmentsEmbedded.Any())
            {
                foreach (var attachment in Attachments)
                {
                    attachment.user   = user;
                    attachment.tenant = tenant;
                    var attach = CreateAttachment(attachment, load_attachments);
                    if (attach != null)
                    {
                        mime_message.Attachments.Add(attach);
                    }
                }

                foreach (var embedded_attachment in AttachmentsEmbedded)
                {
                    embedded_attachment.user   = user;
                    embedded_attachment.tenant = tenant;
                    var attach = CreateAttachment(embedded_attachment, true);
                    if (attach != null)
                    {
                        mime_message.EmbeddedObjects.Add(attach);
                    }
                }
            }

            mime_message.BodyText.Charset = Encoding.UTF8.HeaderName;
            mime_message.BodyText.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mime_message.BodyText.Text = "";

            mime_message.BodyHtml.Charset = Encoding.UTF8.HeaderName;
            mime_message.BodyHtml.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
            mime_message.BodyHtml.Text = HtmlBody;

            return(mime_message);
        }
Ejemplo n.º 14
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            string boundary = Guid.NewGuid().ToString();
            var    date     = DateTime.Now.ToString("ddd, d MMM yyyy H:m:s zz00");

            var subject = !Equals(SubjectEncoding, Encoding.ASCII)
                ? EncodeQuotedPrintableHeader(Subject, SubjectEncoding)
                : Subject;

            AddHeader(sb, "From", FormatMailAddress(From, HeaderEncoding));
            if (To.Any())
            {
                AddHeader(sb, "To", String.Join(", ", To.Select(t => FormatMailAddress(t, HeaderEncoding))));
            }
            if (Cc.Any())
            {
                AddHeader(sb, "Cc", String.Join(", ", Cc.Select(t => FormatMailAddress(t, HeaderEncoding))));
            }
            AddHeader(sb, "Subject", subject);
            AddHeader(sb, "MIME-Version", "1.0");
            AddHeader(sb, "Date", date);
            AddHeader(sb, "Message-ID", MessageId);

            foreach (var additionalHeader in AdditionalHeaders)
            {
                AddHeader(additionalHeader.Name, additionalHeader.Value);
            }

            if (Attachments.Any())
            {
                AddHeader(sb, "Content-Type", "multipart/mixed; boundary=" + boundary);

                AddLine(sb, "");

                AddLine(sb, "--" + boundary);
            }

            string boundary2 = Guid.NewGuid().ToString();

            AddHeader(sb, "Content-Type", "multipart/alternative; boundary=" + boundary2);

            AddLine(sb, "");

            AddLine(sb, "--" + boundary2);

            AddHeader(sb, "Content-Type", "text/plain; charset=" + BodyEncoding.HeaderName);
            AddHeader(sb, "Content-Transfer-Encoding", "quoted-printable");
            AddHeader(sb, "Content-Disposition", "inline");

            AddLine(sb, "");

            AddLine(sb, encodeQuotedPrintable(Text, BodyEncoding));

            AddLine(sb, "--" + boundary2);

            AddHeader(sb, "Content-Type", "text/html; charset=" + BodyEncoding.HeaderName);
            AddHeader(sb, "Content-Transfer-Encoding", "quoted-printable");
            AddHeader(sb, "Content-Disposition", "inline");

            AddLine(sb, "");

            AddLine(sb, encodeQuotedPrintable(Html, BodyEncoding));

            AddLine(sb, "--" + boundary2 + "--");

            if (Attachments.Any())
            {
                AddLine(sb, "");

                foreach (var attachment in Attachments)
                {
                    AddLine(sb, "--" + boundary);

                    if (attachment.Encoding != null)
                    {
                        AddHeader(sb, "Content-Type", attachment.Type + "; charset=" + attachment.Encoding.HeaderName);
                    }
                    else
                    {
                        AddHeader(sb, "Content-Type", attachment.Type);
                    }
                    AddHeader(sb, "Content-Transfer-Encoding", "base64");
                    AddHeader(sb, "Content-Disposition", "attachment; filename=" + attachment.Name);

                    AddLine(sb, "");

                    AddLine(sb, Convert.ToBase64String(attachment.Data, Base64FormattingOptions.InsertLineBreaks));
                }

                AddLine(sb, "--" + boundary + "--");
            }

            return(sb.ToString());
        }
Ejemplo n.º 15
0
        private FlowDocument BuildDocument()
        {
            var doc = new FlowDocument();

            doc.LineStackingStrategy = System.Windows.LineStackingStrategy.BlockLineHeight;
            doc.LineHeight           = 12;
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Summary"))));
            doc.Blocks.Add(new Paragraph(new Run(" " + Title)));
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Description"))));
            doc.Blocks.Add(new Paragraph(new Run(" " + Description)));

            doc.Blocks.Add(new Paragraph(new Bold(new Run("Url"))));
            var url = new Hyperlink(new Run(Url.ToString()));

            doc.Blocks.Add(new Paragraph(url));
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Parent Story"))));
            var parentUrl = new Hyperlink(new Run(ParentStoryUrl.ToString()));

            parentUrl.NavigateUri = ParentStoryUrl;
            doc.Blocks.Add(new Paragraph(parentUrl));

            doc.Blocks.Add(new Paragraph(new Italic(new Run("Status: " + Status.ToString()))));

            doc.Blocks.Add(new Paragraph(new Italic(new Run("Date Started: " + DateStarted.Value.ToString("yyyy-MM-dd hh:mm:ss")))));
            if (DateEnded.HasValue && DateEnded.Value != DateTime.MinValue)
            {
                doc.Blocks.Add(new Paragraph(new Italic(new Run("Date Ended: " + DateEnded.Value.ToString("yyyy-MM-dd hh:mm:ss")))));
            }

            if (Attachments.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Attachments"))));
                foreach (var item in Attachments)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (AcceptanceCriteria.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Acceptance Criteria"))));
                foreach (var item in AcceptanceCriteria)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" + " + item.Value)));
                }
            }

            if (DeveloperCriteria.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Development Criteria"))));
                foreach (var item in DeveloperCriteria)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" + " + item.Value)));
                }
            }

            var i = 0;
            var j = 0;

            if (KeyIdentifiers.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Key Identifiers"))));
                foreach (var item in KeyIdentifiers)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));

                    if (item.Questions.Any())
                    {
                        j = 0;
                        doc.Blocks.Add(new Paragraph(new Italic(new Run(" Questions"))));
                        foreach (var q in item.Questions)
                        {
                            doc.Blocks.Add(new Paragraph(new Run("   " + (++j).ToString() + ".Q. " + q.Ask)));
                            doc.Blocks.Add(new Paragraph(new Run("     A. " + q.Answer)));
                        }
                    }
                }
            }

            if (Issues.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Issues"))));
                foreach (var item in Issues)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Is Open: " + item.IsOpen.ToString()))));
                }
            }

            if (Queries.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Queries"))));
                foreach (var item in Queries)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (Scripts.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Scripts"))));
                foreach (var item in Scripts)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (TestCases.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Test Cases"))));
                foreach (var item in TestCases)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Status: " + item.Status.ToString()))));

                    if (item.Steps.Any())
                    {
                        j = 0;
                        doc.Blocks.Add(new Paragraph(new Italic(new Run(" Steps"))));
                        foreach (var q in item.Steps)
                        {
                            doc.Blocks.Add(new Paragraph(new Run("   " + (++j).ToString() + ". " + q.Value)));
                        }
                    }
                }
            }

            if (Checkups.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Checkups"))));
                foreach (var item in Checkups)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Applied: " + item.Applied.ToString()))));
                }
            }

            if (SubTasks.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("SubTasks"))));
                foreach (var item in SubTasks)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Title)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Status: " + item.Status))));
                }
            }

            return(doc);
        }
Ejemplo n.º 16
0
        public virtual void Save(TextWriter txt)
        {
            txt.WriteLine("Date: {0}", Date.GetRFC2060Date());
            txt.WriteLine("To: {0}", string.Join("; ", To.Select(x => x.ToString())));
            txt.WriteLine("Cc: {0}", string.Join("; ", Cc.Select(x => x.ToString())));
            txt.WriteLine("Reply-To: {0}", string.Join("; ", ReplyTo.Select(x => x.ToString())));
            txt.WriteLine("Bcc: {0}", string.Join("; ", Bcc.Select(x => x.ToString())));
            if (Sender != null)
            {
                txt.WriteLine("Sender: {0}", Sender);
            }
            if (From != null)
            {
                txt.WriteLine("From: {0}", From);
            }
            if (!string.IsNullOrEmpty(MessageID))
            {
                txt.WriteLine("Message-ID: {0}", MessageID);
            }

            var otherHeaders = Headers.Where(x => !SpecialHeaders.Contains(x.Key, StringComparer.InvariantCultureIgnoreCase));

            foreach (var header in otherHeaders)
            {
                txt.WriteLine("{0}: {1}", header.Key, header.Value);
            }
            if (Importance != MailPriority.Normal)
            {
                txt.WriteLine("Importance: {0}", (int)Importance);
            }
            txt.WriteLine("Subject: {0}", Subject);

            string boundary = null;

            if (Attachments.Any() || AlternateViews.Any())
            {
                boundary = string.Format("--boundary_{0}", Guid.NewGuid());
                txt.WriteLine("Content-Type: multipart/mixed; boundary={0}", boundary);
            }

            // signal end of headers
            txt.WriteLine();

            if (!string.IsNullOrWhiteSpace(Body))
            {
                if (boundary != null)
                {
                    txt.WriteLine("--" + boundary);
                    txt.WriteLine();
                }

                txt.Write(Body);
            }

            AlternateViews.ToList().ForEach(view =>
            {
                txt.WriteLine();
                txt.WriteLine("--" + boundary);
                txt.WriteLine(string.Join("\r\n", view.Headers.Select(h => string.Format("{0}: {1}", h.Key, h.Value))));
                txt.WriteLine();
                if (view.Scope >= Scope.HeadersAndBodySnyppit)
                {
                    txt.WriteLine(view.Body);
                }
            });


            this.Attachments.ToList().ForEach(att =>
            {
                txt.WriteLine();
                txt.WriteLine("--" + boundary);
                txt.WriteLine(string.Join("\r\n", att.Headers.Select(h => string.Format("{0}: {1}", h.Key, h.Value))));
                txt.WriteLine();
                if (att.Scope >= Scope.HeadersAndBodySnyppit)
                {
                    txt.WriteLine(att.Body);
                }
            });

            if (boundary != null)
            {
                txt.WriteLine("--" + boundary + "--");
            }
        }
Ejemplo n.º 17
0
        public async Task <CipherView> DecryptAsync()
        {
            var model = new CipherView(this);

            await DecryptObjAsync(model, this, new HashSet <string>
            {
                "Name",
                "Notes"
            }, OrganizationId);

            switch (Type)
            {
            case Enums.CipherType.Login:
                model.Login = await Login.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.SecureNote:
                model.SecureNote = await SecureNote.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.Card:
                model.Card = await Card.DecryptAsync(OrganizationId);

                break;

            case Enums.CipherType.Identity:
                model.Identity = await Identity.DecryptAsync(OrganizationId);

                break;

            default:
                break;
            }

            if (Attachments?.Any() ?? false)
            {
                model.Attachments = new List <AttachmentView>();
                var tasks = new List <Task>();
                async Task decryptAndAddAttachmentAsync(Attachment attachment)
                {
                    var decAttachment = await attachment.DecryptAsync(OrganizationId);

                    model.Attachments.Add(decAttachment);
                }

                foreach (var attachment in Attachments)
                {
                    tasks.Add(decryptAndAddAttachmentAsync(attachment));
                }
                await Task.WhenAll(tasks);
            }
            if (Fields?.Any() ?? false)
            {
                model.Fields = new List <FieldView>();
                var tasks = new List <Task>();
                async Task decryptAndAddFieldAsync(Field field)
                {
                    var decField = await field.DecryptAsync(OrganizationId);

                    model.Fields.Add(decField);
                }

                foreach (var field in Fields)
                {
                    tasks.Add(decryptAndAddFieldAsync(field));
                }
                await Task.WhenAll(tasks);
            }
            if (PasswordHistory?.Any() ?? false)
            {
                model.PasswordHistory = new List <PasswordHistoryView>();
                var tasks = new List <Task>();
                async Task decryptAndAddHistoryAsync(PasswordHistory ph)
                {
                    var decPh = await ph.DecryptAsync(OrganizationId);

                    model.PasswordHistory.Add(decPh);
                }

                foreach (var ph in PasswordHistory)
                {
                    tasks.Add(decryptAndAddHistoryAsync(ph));
                }
                await Task.WhenAll(tasks);
            }
            return(model);
        }