Ejemplo n.º 1
0
        /// <summary>
        /// Sends the email message
        /// </summary>
        public static void SendMessage(Email email)
        {
            JoinableList jList = new JoinableList();

            foreach (string recipient in email.Recipients)
            {
                jList.Add(recipient + " (TO)");
            }

            foreach (string recipient in email.CC)
            {
                jList.Add(recipient + " (CC)");
            }

            foreach (string recipient in email.BCC)
            {
                jList.Add(recipient + " (BCC)");
            }

            try
            {
                email.Send();
                m_Logger.DebugFormat("Sent email message with subject '{0}' to '{1}', using template: {2}", email.Subject, jList, email.TemplateFilename);
            }
            catch (Exception ex)
            {
                m_Logger.Error(string.Format("Error sending email message with subject '{0}' to '{1}', using template: {2}", email.Subject, jList, email.TemplateFilename), ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        protected void MimeTypesDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
            case (ListItemType.Item):
            case (ListItemType.AlternatingItem):

                MimeTypeManager.MimeType mimeType = (MimeTypeManager.MimeType)e.Item.DataItem;

                Label MimeTypeNameLabel   = (Label)e.Item.FindControl("MimeTypeNameLabel");
                Label FileExtensionsLabel = (Label)e.Item.FindControl("FileExtensionsLabel");

                MimeTypeNameLabel.Text = mimeType.ContentType;

                JoinableList jList = new JoinableList(", ");

                foreach (string fileExt in mimeType.FileExtensions)
                {
                    jList.Add(fileExt);
                }

                FileExtensionsLabel.Text = jList.ToString();

                break;
            }
        }
Ejemplo n.º 3
0
        public static Company Update(Company company)
        {
            if (company.BrandListLoaded)
            {
                JoinableList jList = new JoinableList();
                company.BrandList.ForEach(b => jList.Add(b.Name));
                company.Brands = jList.ToString();
            }

            CompanyMapper.Instance.Update(company);

            if (company.BrandListLoaded)
            {
                CompanyBrandMapper.Instance.DeleteBrands(company.CompanyId);

                foreach (Brand brand in company.BrandList)
                {
                    CompanyBrand cb = CompanyBrand.New();
                    cb.CompanyId = company.CompanyId.GetValueOrDefault();
                    cb.BrandId   = brand.BrandId.GetValueOrDefault();
                    CompanyBrand.Update(cb);
                }
            }

            return(company);
        }
Ejemplo n.º 4
0
        private JoinableList GetStandardSectorSearchSql()
        {
            JoinableList jList = new JoinableList(" OR ");

            string[] keywords = GeneralKeyword.ToLower().Split(' ');

            foreach (string field in m_StandardFields)
            {
                JoinableList jList2 = new JoinableList(" AND ");

                foreach (string keyword in keywords)
                {
                    if (!UserQueryParser.NoiseWords.Contains(keyword))
                    {
                        string text = keyword.Replace("'", "''");

                        if (text.StartsWith("*"))
                        {
                            text = text.Substring(1);
                        }

                        if (text.EndsWith("*"))
                        {
                            text = text.Substring(0, text.Length - 1);
                        }

                        jList2.Add(string.Format("({0} LIKE '%{1}%')", field, text));
                    }
                }

                jList.Add(jList2);
            }

            return(jList);
        }
Ejemplo n.º 5
0
        protected void SetCustomSearchCriteria(ref SearchBuilder sb)
        {
            if (ContainingAssetsFromBrandId != 0)
            {
                string criteria = string.Format("{0}.OrderId IN (SELECT OrderId FROM [v_OrderItem] OI WHERE OI.AssetBrandId={1})", sb.TableAlias, ContainingAssetsFromBrandId);
                sb.Criteria.Add(criteria);
            }

            if (ContainingAssetsUploadedByUserId != 0)
            {
                string criteria = string.Format("{0}.OrderId IN (SELECT OrderId FROM [v_OrderItem] OI WHERE OI.AssetUploadUserId={1})", sb.TableAlias, ContainingAssetsUploadedByUserId);
                sb.Criteria.Add(criteria);
            }

            if (PendingOrdersOnly.HasValue)
            {
                sb.Criteria.Add(PendingOrdersOnly.Value ? "CompletionDate IS NULL" : "CompletionDate IS NOT NULL");
            }

            if (!StringUtils.IsBlank(GeneralKeyword))
            {
                JoinableList jList = new JoinableList(" OR ");

                if (NumericUtils.IsInt32(GeneralKeyword))
                {
                    jList.Add(string.Format("{0}={1}", Order.Columns.OrderId, GeneralKeyword));
                }
                else
                {
                    foreach (string column in new[] { "UserName", "UserEmail", "UserPrimaryBrandName" })
                    {
                        jList.Add(string.Format("{0} LIKE '%{1}%'", column, SqlUtils.SafeValue(GeneralKeyword)));
                    }
                }

                sb.Criteria.Add(jList);
            }
        }
        protected void SetCustomSearchCriteria(ref SearchBuilder sb)
        {
            if (OnlyDistinctAssetIds)
            {
                sb.TableAlias = "AAH";
                sb.Fields.Add("DISTINCT AssetId");
            }

            if (IncludeActionsList.Count > 0)
            {
                JoinableList jList = new JoinableList(" OR ");

                foreach (AuditAssetAction auditAssetAction in IncludeActionsList)
                {
                    string criteria = string.Format("{0}={1}", AuditAssetHistory.Columns.AuditAssetActionId, Convert.ToInt32(auditAssetAction));
                    jList.Add(criteria);
                }

                sb.Criteria.Add(jList.ToString());
            }

            if (!StringUtils.IsBlank(UserEmail))
            {
                sb.Criteria.Add("[UserEmail] = @userEmail");
                sb.AddDataParameter("@userEmail", UserEmail);
            }

            if (BrandId != 0)
            {
                sb.Criteria.Add(string.Format("AssetBrandId={0}", BrandId));
            }

            if (StartDate.HasValue)
            {
                string criteria = string.Format("[Date] >= '{0}'", StartDate.Value.ToString("yyyy-MM-dd"));
                sb.Criteria.Add(criteria);
            }

            if (EndDate.HasValue)
            {
                string criteria = string.Format("[Date] <= '{0}'", EndDate.Value.ToString("yyyy-MM-dd"));
                sb.Criteria.Add(criteria);
            }
        }
Ejemplo n.º 7
0
        protected void SetCustomSearchCriteria(ref SearchBuilder sb)
        {
            if (UserIdFinder != null)
            {
                sb.Criteria.Add("UserId IN (" + UserIdFinder.FindQuery + ")");
            }

            if (!StringUtils.IsBlank(Keyword))
            {
                JoinableList jList = new JoinableList(" OR ");

                if (NumericUtils.IsInt32(Keyword))
                {
                    jList.Add(string.Format("({0}={1})", AuditUserHistory.Columns.UserId, Keyword));
                }

                string safeSector = SqlUtils.SafeValue(Keyword);

                jList.Add(string.Format("({0} LIKE '%{1}%')", AuditUserHistory.Columns.SessionId, safeSector));
                jList.Add(string.Format("({0} LIKE '%{1}%')", AuditUserHistory.Columns.IpAddress, safeSector));
                jList.Add(string.Format("({0} LIKE '%{1}%')", AuditUserHistory.Columns.Notes, safeSector));
                jList.Add(string.Format("(Description LIKE '%{0}%')", safeSector));
                jList.Add(string.Format("(UserName LIKE '%{0}%')", safeSector));
                jList.Add(string.Format("(UserEmail LIKE '%{0}%')", safeSector));

                sb.Criteria.Add(jList.ToString());
            }

            if (StartDate.HasValue)
            {
                string criteria = string.Format("[Date] >= '{0}'", StartDate.Value.ToString("yyyy-MM-dd"));
                sb.Criteria.Add(criteria);
            }

            if (EndDate.HasValue)
            {
                string criteria = string.Format("[Date] <= '{0}'", EndDate.Value.ToString("yyyy-MM-dd"));
                sb.Criteria.Add(criteria);
            }

            if (SuccessfulLogins)
            {
                // TODO: Doing a LIKE query is not very efficient.  Need to change this... seperate login events perhaps
                // and add an AuditUserAction for Successful Login and Login Errors

                string criteria = string.Format("(([{0}]={1}) AND ([Notes] LIKE 'Login Successful.%'))", AuditUserHistory.Columns.AuditUserActionId, Convert.ToInt32(AuditUserAction.UserLogin));
                sb.Criteria.Add(criteria);
            }

            if (AuditUserActionList.Count > 0)
            {
                JoinableList jList = new JoinableList();

                foreach (AuditUserAction action in AuditUserActionList)
                {
                    jList.Add(Convert.ToInt32(action));
                }

                sb.Criteria.Add("AuditUserActionId IN (" + jList + ")");
            }

            Debug.WriteLine(sb.GetCountQuery());
        }
Ejemplo n.º 8
0
        protected void SetCustomSearchCriteria(ref SearchBuilder sb)
        {
            sb.Table = "[v_User]";

            if (CompanyName.ToLower() == "all")
            {
                sb.Criteria.Remove(string.Format("{0}=@companyName", User.Columns.CompanyName));
            }

            if (MinimumUserRoleId > 0)
            {
                string sql = string.Format("{0} >= {1}", User.Columns.UserRoleId, MinimumUserRoleId);
                sb.Criteria.Add(sql);
            }

            if (MaximumUserRoleId > 0)
            {
                string sql = string.Format("{0} <= {1}", User.Columns.UserRoleId, MaximumUserRoleId);
                sb.Criteria.Add(sql);
            }

            if (FuzzyEmail != string.Empty)
            {
                string sql = string.Format("{0} LIKE '%{1}%'", User.Columns.Email, FuzzyEmail.Replace("'", "''"));
                sb.Criteria.Add(sql);
            }

            if (ExpiredAndSuspendedAccountsOnly)
            {
                sb.Criteria.Add("((IsAccountExpired = 1) OR (IsSuspended = 1))");
            }

            if (PrimaryBrandId == Int32.MinValue)
            {
                // -------------------------------------------------------------
                // Criteria checks
                // -------------------------------------------------------------
                // null				= ignore	(automatic)
                // int				= int		(automatic)
                // Int32.MinValue	= IS NULL	(handled below)
                // -------------------------------------------------------------

                sb.Criteria.Remove(string.Format("{0}=@primaryBrandId", User.Columns.PrimaryBrandId));
                sb.Criteria.Add(string.Format("{0} IS NULL", User.Columns.PrimaryBrandId));
            }

            if (!RegisterDateRange.IsNull)
            {
                if (RegisterDateRange.StartDate.HasValue)
                {
                    string criteria = string.Format("{0} >= @RegisterDateRangeStartDate", User.Columns.RegisterDate);
                    sb.Criteria.Add(criteria);
                    sb.AddDataParameter("@RegisterDateRangeStartDate", RegisterDateRange.StartDate);
                }

                if (RegisterDateRange.EndDate.HasValue)
                {
                    string criteria = string.Format("{0} <= @RegisterDateRangeEndDate", User.Columns.RegisterDate);
                    sb.Criteria.Add(criteria);
                    sb.AddDataParameter("@RegisterDateRangeEndDate", RegisterDateRange.EndDate);
                }
            }

            //--------------------------------------------------------------------
            // Brand Admins are restricted to seeing users in their own BU
            // or from companies they have created, so we modify the where clause
            // accordingly to reflect this.
            //--------------------------------------------------------------------
            if (BrandAdministratorId != 0)
            {
                // Ensure that the primary brand ID is specified
                if (!sb.Criteria.Contains(string.Format("{0}=@primaryBrandId", User.Columns.PrimaryBrandId)))
                {
                    throw new SystemException("PrimaryBrandId must be specified when BrandAdministratorId is specified");
                }

                // Create list to hold criteria
                JoinableList jList = new JoinableList(" AND ");

                // Remove primary brand ID from SQL
                sb.Criteria.Remove(string.Format("{0}=@primaryBrandId", User.Columns.PrimaryBrandId));

                // Update with correct syntax
                jList.Add(PrimaryBrandId == 0 ? string.Format("{0} IS NULL", User.Columns.PrimaryBrandId) : string.Format("{0}={1}", User.Columns.PrimaryBrandId, PrimaryBrandId));

                // Add the criteria
                sb.Criteria.Add(jList.ToString());
            }
        }
        public override object GetDataSource()
        {
            Dictionary <Int32, String> ht = new Dictionary <int, string>();

            foreach (Lightbox lb in ContextInfo.LightboxManager.UserLightboxes)
            {
                // Filter out linked lightboxes if required

                if (!lb.IsLinked || !HideLinkedLightboxes)
                {
                    StringBuilder sb = new StringBuilder(lb.Name);

                    JoinableList jList = new JoinableList(", ");

                    if (lb.IsDefault)
                    {
                        jList.Add("default");
                    }

                    if (lb.IsPublic)
                    {
                        jList.Add("public");
                    }

                    if (lb.IsLinked)
                    {
                        jList.Add("linked");
                    }

                    if (jList.Count > 0)
                    {
                        sb.AppendFormat(" ({0})", jList);
                    }

                    ht[lb.LightboxId.GetValueOrDefault()] = sb.ToString();
                }
            }

            if (ShowPublicLightboxes)
            {
                // Initialise finder to get public lightboxes
                LightboxFinder finder = new LightboxFinder {
                    IsPublic = true
                };

                // Non-superadmins should only see public lightboxes which are assigned
                // to a brand to which they are also assigned (so a user cannot see lightboxes
                // assigned to brands to which they do not have access).
                if (SessionInfo.Current.User.UserRole != UserRole.SuperAdministrator && BrandManager.IsMultipleBrandMode)
                {
                    finder.BrandIdList.Add(0);
                    finder.BrandIdList.AddRange(SessionInfo.Current.User.Brands.Select(b => b.BrandId.GetValueOrDefault()));
                }

                // Get the lightboxes
                List <Lightbox> lightboxList = Lightbox.FindMany(finder);

                foreach (Lightbox lb in lightboxList)
                {
                    int lightboxId = lb.LightboxId.GetValueOrDefault();

                    // Check that the lightbox isn't already in the list
                    // (In case the current user has public lightboxes)
                    if (!ht.ContainsKey(lightboxId))
                    {
                        string lightboxName = string.Format("{0} (public)", lb.Name);
                        ht.Add(lightboxId, lightboxName);
                    }
                }
            }

            return(ht);
        }
Ejemplo n.º 10
0
        private void SetFullTextSearchCriteria(SearchBuilder sb, string parsedQuery)
        {
            //---------------------------------------------------------------------
            // Fields to included in select statement
            //---------------------------------------------------------------------
            sb.Fields.Add("DISTINCT [BASE].*");
            sb.Fields.Add("(ISNULL([AMD].[Rank], 0)*100) AS AssetMetadataRank");

            if (FileContentSearchingEnabled)
            {
                //---------------------------------------------------------------------
                // Fields
                //---------------------------------------------------------------------
                sb.Fields.Add("ISNULL([AFC].[Rank], 0) AS FileContentRank");
                sb.Fields.Add("ISNULL([AFC].[Rank], 0) + (ISNULL([AMD].[Rank], 0)*100) AS CombinedRank");

                //---------------------------------------------------------------------
                // Asset File Join
                //---------------------------------------------------------------------
                sb.Joins.Add("LEFT OUTER JOIN [AssetFile] AF ON AF.AssetId = BASE.AssetId");

                //---------------------------------------------------------------------
                // File Rank Join
                //---------------------------------------------------------------------
                StringBuilder sb1 = new StringBuilder();
                sb1.Append(" LEFT OUTER JOIN CONTAINSTABLE");
                sb1.Append("(");
                sb1.Append(" [AssetFile],");
                sb1.Append(" ([FileName], [FileContent]),");
                sb1.AppendFormat("'{0}'", parsedQuery);
                sb1.Append(")");
                sb1.Append(" AFC ON [AFC].[Key] = [AF].[AssetFileId]");
                sb.Joins.Add(sb1.ToString());
            }
            else
            {
                // We're not using file indexing, so the file content rank
                // will always be 0, and the combined rank should only
                // take the metadata into account.

                sb.Fields.Add("0 AS FileContentRank");
                sb.Fields.Add("(ISNULL([AMD].[Rank], 0)*100) AS CombinedRank");
            }

            // Set up the list to hold the fields to be searched
            JoinableList jFieldList = new JoinableList(new TextExtractor("[", "]"));

            // This is a hack!  We don't want to add all the fields into the query
            // if our search terms contain a negative term.  This is because SQL Server
            // will still return all rows unless *every single row* doesn't contain the
            // term to be excluded, which isn't the behaviour we want, so we'll just
            // search the SearchableData field instead.
            // http://stackoverflow.com/questions/1296181/using-not-keyword-with-full-text-search-and-multiple-columns
            if (!parsedQuery.Contains("AND NOT"))
            {
                jFieldList.AddRange(m_StandardFields);
            }

            // Always search the SearchableData field, as this is our concatenated
            // field and includes all of the keywords that would be relevant.
            if (!jFieldList.Contains("SearchableData"))
            {
                jFieldList.Add("SearchableData");
            }

            //---------------------------------------------------------------------
            // Metadata Rank
            //---------------------------------------------------------------------
            StringBuilder sb2 = new StringBuilder();

            sb2.Append(" LEFT OUTER JOIN CONTAINSTABLE");
            sb2.Append("(");
            sb2.AppendFormat("  {0} ,", sb.Table);
            sb2.AppendFormat(" ({0}),", jFieldList);
            sb2.AppendFormat(" '{0}' ", parsedQuery);
            sb2.Append(")");
            sb2.AppendFormat(" AMD ON [AMD].[Key] = [{0}].[{1}]", sb.TableAlias, Asset.Columns.AssetId);
            sb.Joins.Add(sb2.ToString());

            //---------------------------------------------------------------------
            // Filters
            //---------------------------------------------------------------------
            JoinableList jList = new JoinableList(" OR ");

            if (FileContentSearchingEnabled)
            {
                // File indexing is enabled, so we can use the rank from searching
                // the file contents to determine what is returned.  Restrict our
                // result set to assets where there is a match somewhere, either
                // in the metadata or the asset file.  We do this by adding both
                // ranks, and filtering the results to assets where this value
                // is greater than 0.

                jList.Add("(ISNULL(AFC.[Rank], 0) + ISNULL(AMD.[Rank], 0) > 0)");
            }
            else
            {
                // Otherwise, file content is not returned, so we can't use any
                // content ranking from there.  Instead, we'll just use the rank
                // from the full-text search on the metadata.

                jList.Add("(ISNULL(AMD.[Rank], 0) > 0)");
            }

            // Include the asset matching the asset id, if a number was entered
            if (NumericUtils.IsInt32(GeneralKeyword))
            {
                jList.Add(string.Format("{0}.{1} = {2}", sb.TableAlias, Asset.Columns.AssetId, GeneralKeyword));
            }

            sb.Criteria.Add("(" + jList + ")");

            //---------------------------------------------------------------------
            // Sort Expressions
            // Here, we're forcing the rank column to be the first sort column
            // so that the most relevant assets appear first in the list
            //---------------------------------------------------------------------
            if (OrderBy == OrderBy.Relevance)
            {
                IList <ISortExpression> sorts = new List <ISortExpression>();

                foreach (ISortExpression sortExpression in sb.SortExpressions)
                {
                    sorts.Add(sortExpression);
                }

                sb.SortExpressions.Clear();
                sb.SortExpressions.Add(new DescendingSort("CombinedRank"));

                foreach (ISortExpression sortExpression in sorts)
                {
                    sb.SortExpressions.Add(sortExpression);
                }
            }
        }
Ejemplo n.º 11
0
        static AssetFinder()
        {
            // Default text search options
            FullTextSearchedEnabled     = true;
            FileIndexingEnabled         = false;
            FileContentSearchingEnabled = false;

            // Table columns
            m_StandardFields.Add(Asset.Columns.CopyrightOwner);
            m_StandardFields.Add(Asset.Columns.Description);
            m_StandardFields.Add(Asset.Columns.Keywords);
            m_StandardFields.Add(Asset.Columns.Filename);
            m_StandardFields.Add(Asset.Columns.Originator);
            m_StandardFields.Add(Asset.Columns.ProjectCode);
            m_StandardFields.Add(Asset.Columns.Title);
            m_StandardFields.Add(Asset.Columns.FileHash);
            m_StandardFields.Add(Asset.Columns.AssetCategories);
            m_StandardFields.Add(Asset.Columns.AssetMetadataVals);
            m_StandardFields.Add(Asset.Columns.MetadataSearchVals);

            // View Columns
            m_StandardFields.Add("AssetTypeName");
            m_StandardFields.Add("UploadedByUserName");
            m_StandardFields.Add("BrandName");
        }
Ejemplo n.º 12
0
        private void SetCustomSearchCriteria(ref SearchBuilder sb)
        {
            sb.Table = "[v_Asset]";

            if (AuditAssetHistoryFinder != null)
            {
                AuditAssetHistoryFinder.OnlyDistinctAssetIds = true;
                sb.Criteria.Add(sb.TableAlias + ".AssetId IN (" + AuditAssetHistoryFinder.FindQuery + ")");
            }

            if (Orientation != Orientation.All)
            {
                string sql = string.Empty;

                switch (Orientation)
                {
                case (Orientation.Portrait):
                    sql = string.Format("[Height] > [Width]");
                    break;

                case (Orientation.Landscape):
                    sql = string.Format("[Height] < [Width]");
                    break;

                case (Orientation.Square):
                    sql = string.Format("[Height] = [Width]");
                    break;
                }

                if (sql != string.Empty)
                {
                    sb.Criteria.Add(string.Format("({0})", sql));
                }
            }

            if (GeneralKeyword != string.Empty)
            {
                if (FullTextSearchedEnabled)
                {
                    UserQueryParser uq      = new UserQueryParser();
                    bool            isValid = uq.ParseTokens(GeneralKeyword);

                    if (isValid)
                    {
                        string query = uq.GetSqlQuery();
                        SetFullTextSearchCriteria(sb, query);
                    }
                    else
                    {
                        string error = string.Format("Error parsing user query: \"{0}\" - {1}", GeneralKeyword, uq.Error);
                        Debug.WriteLine(error);
                    }
                }
                else
                {
                    JoinableList jList = GetStandardSectorSearchSql();
                    sb.Criteria.Add(string.Format("({0})", jList));
                }
            }

            if (IsBeforePublicationDate)
            {
                sb.Criteria.Add(string.Format("({0} > getdate())", Asset.Columns.PublishDate));
            }

            if (IsExpired.HasValue)
            {
                sb.Criteria.Add("dbo.IsExpired(" + sb.TableAlias + ".ExpiryDate) = @isExpired");
                sb.AddDataParameter("@isExpired", SqlUtils.BitValue(IsExpired.GetValueOrDefault()));
            }

            if (!ExpiryDateRange.IsNull)
            {
                const string dateFormat = "dd MMMM yyyy HH:mm:ss";

                if (ExpiryDateRange.StartDate.HasValue && ExpiryDateRange.EndDate.HasValue)
                {
                    sb.Criteria.Add(string.Format("({0} BETWEEN '{1}' AND '{2}')", Asset.Columns.ExpiryDate, ExpiryDateRange.StartDate.Value.ToString(dateFormat), ExpiryDateRange.EndDate.Value.ToString(dateFormat)));
                }
                else
                {
                    if (ExpiryDateRange.StartDate.HasValue)
                    {
                        sb.Criteria.Add(string.Format("({0} >= '{1}')", Asset.Columns.ExpiryDate, ExpiryDateRange.StartDate.Value.ToString(dateFormat)));
                    }

                    if (ExpiryDateRange.EndDate.HasValue)
                    {
                        sb.Criteria.Add(string.Format("({0} <= '{1}')", Asset.Columns.ExpiryDate, ExpiryDateRange.EndDate.Value.ToString(dateFormat)));
                    }
                }
            }

            foreach (ComplexCriteria cc in m_ComplexCriteria)
            {
                string operand;

                switch (cc.CompareType)
                {
                case (CompareType.LessThan):
                    operand = "<";
                    break;

                case (CompareType.MoreThan):
                    operand = ">";
                    break;

                default:
                    operand = "=";
                    break;
                }

                sb.Criteria.Add(string.Format("({0} {1} {2})", cc.Field, operand, cc.Value));
            }

            if (IsCompletelyPublished)
            {
                // Entire clause
                JoinableList jList1 = new JoinableList(" OR ");

                // Currently published
                JoinableList jList2 = new JoinableList(" AND ");
                jList2.Add(string.Format("{0} = {1}", Asset.Columns.AssetPublishStatusId, Convert.ToInt32(AssetPublishStatus.Published)));
                jList2.Add(string.Format("{0} < getdate()", Asset.Columns.PublishDate));
                jList2.Add(string.Format("{0} > getdate()", Asset.Columns.ExpiryDate));

                // Add to entire clause
                jList1.Add(jList2);

                // If unpublished and expired assets need to be displayed too, we need to expand this criteria as follows:
                // 1. All admin users should see their own assets
                // 2. Brand admins should see assets in their primary brand
                // 3. Super admins should see all assets
                if (IncludeUnpublishedExpiredAssets)
                {
                    JoinableList jList3 = new JoinableList(" OR ");

                    if (IncludeUnpublishedExpiredAssets_UserId > 0)
                    {
                        jList3.Add(string.Format("({0}={1})", Asset.Columns.UploadedByUserId, IncludeUnpublishedExpiredAssets_UserId));
                    }

                    if (IncludeUnpublishedExpiredAssets_BrandId > 0)
                    {
                        jList3.Add(string.Format("({0}={1})", Asset.Columns.BrandId, IncludeUnpublishedExpiredAssets_BrandId));
                    }

                    if (jList3.Count > 0)
                    {
                        jList1.Add(jList3);
                    }
                }

                string criteria = jList1.ToString();

                if (!StringUtils.IsBlank(criteria))
                {
                    sb.Criteria.Add(string.Format("({0})", criteria));
                }
            }

            if (IsPublished.HasValue)
            {
                string op = (IsPublished.Value) ? " = " : " <> ";
                sb.Criteria.Add(string.Concat(Asset.Columns.AssetPublishStatusId, op, Convert.ToInt32(AssetPublishStatus.Published)));
            }

            if (BrandIdList.Count > 0)
            {
                JoinableList jList = new JoinableList(BrandIdList);
                sb.Criteria.Add(string.Format("BrandId IN ({0})", jList));
            }

            // Production date filter
            SetProductionMonthDayCriteria(sb);

            // Metadata filters
            AddMetadataCriteria(sb);

            // Category filters
            AddManyToManyCriteria(sb, "AssetCategory", "CategoryId", CategoryIdList);

            // Setup results ordering
            AddOrderByClause();

            Debug.WriteLine(string.Format("AssetFinder: {0}", sb.GetFullQuery()));
        }