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); }
internal static void SaveUploadedAssetListToCurrentUser() { // Create new list to hold asset ID's List <Int32> list = new List <Int32>(); // Strip out duplicates foreach (int i in SessionInfo.Current.AdminSessionInfo.UploadedAssetsList) { if (!list.Contains(i)) { list.Add(i); } } // Convert into comma-delimited string JoinableList jList = new JoinableList(list, ","); // Update session SessionInfo.Current.User.CatalogueAssetIdList = jList.ToString(); SessionInfo.Current.AdminSessionInfo.UploadedAssetsList.Clear(); SessionInfo.Current.AdminSessionInfo.UploadedAssetsList.AddRange(list); // Save the user User.Update(SessionInfo.Current.User); }
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; } }
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); } }
private void EndHandler(IAsyncResult ar) { if (m_ServiceStatus != null && m_ServiceException == null) { const string dateFormat = Global.DateTimeFormat + ":ss"; TimeSpan uptime = DateTime.Now - m_ServiceStatus.StartDate; VersionLabel.Text = string.Format("{0}.{1}.{2}.{3}", m_VersionInfo.Major, m_VersionInfo.Minor, m_VersionInfo.Revision, m_VersionInfo.Build); BuildDateLabel.Text = m_VersionInfo.LastModifiedDate.ToString(Global.DateTimeFormat); StartDateLabel.Text = m_ServiceStatus.StartDate.ToString(dateFormat); ServiceUptimeLabel.Text = string.Format("{0} days, {1} hours, {2} minutes, {3} seconds", uptime.Days, uptime.Hours, uptime.Minutes, uptime.Seconds); LastCheckDate.Text = (m_ServiceStatus.QueueLastChecked == DateTime.MinValue) ? "Never" : m_ServiceStatus.QueueLastChecked.ToString(dateFormat); NumberOfJobsInProgressCountLabel.Text = m_ServiceStatus.NumberOfJobsInProgress.ToString(); NumberOfJobsPendingCountLabel.Text = m_ServiceStatus.NumberOfJobsInQueue.ToString(); NumberOfJobsProcessedCountLabel.Text = m_ServiceStatus.NumberOfJobsProcessed.ToString(); if (m_ServiceStatus.QueueLastChecked > DateTime.MinValue) { TimeSpan lastCheckedTimeSpan = DateTime.Now - m_ServiceStatus.QueueLastChecked; LastCheckDate.Text += string.Format(" ({0} minutes, {1} seconds ago)", lastCheckedTimeSpan.Minutes, lastCheckedTimeSpan.Seconds); } StatusWrapper.Visible = true; // Get the list of supported extensions and sort it List <string> supportExtensions = APSGateway.Instance.ProcesssableExtensions; supportExtensions.Sort(); // Update the UI JoinableList jList = new JoinableList(supportExtensions); SupportedFileExtensionsLiteral.Text = (jList.Count == 0) ? "(Unknown)" : jList.ToString(); // Display message indicating server is up APSFeedbackLabel.SetSuccessMessage("Asset processing server is running"); return; } string error = (m_ServiceException == null) ? string.Empty : m_ServiceException.Message; StatusWrapper.Visible = false; APSFeedbackLabel.SetErrorMessage("Asset processing server is not running or inaccessible", error); }
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()); }
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()); } }
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())); }