public byte[] GetImageFile(AttachedFile[] attachedFiles, bool isPep) { int dicDocTypeImageDeclarantId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentType), DicDocumentTypeCodes._001_001_1A); if (isPep) { return(attachedFiles .Where(x => x.Type.UID == dicDocTypeImageDeclarantId) .Select(x => ShepFileDownload(x.File.ShepFile)) .FirstOrDefault() ?? attachedFiles .Where(x => FileTypeHelper.GetFileExtension(x.File.ShepFile?.Name) .Equals(FileTypes.Png, StringComparison.CurrentCultureIgnoreCase) || FileTypeHelper.GetFileExtension(x.File.ShepFile?.Name).Equals(FileTypes.Jpeg, StringComparison.CurrentCultureIgnoreCase)) .Select(x => ShepFileDownload(x.File.ShepFile)) .FirstOrDefault()); } return(attachedFiles .Where(x => x.Type.UID == dicDocTypeImageDeclarantId) .Select(x => x.File.Content) .FirstOrDefault() ?? attachedFiles .Where(x => FileTypeHelper.GetFileExtension(x.File.Name) .Equals(FileTypes.Png, StringComparison.CurrentCultureIgnoreCase) || FileTypeHelper.GetFileExtension(x.File.Name) .Equals(FileTypes.Jpeg, StringComparison.CurrentCultureIgnoreCase)) .Select(x => x.File.Content) .FirstOrDefault()); }