1. Place the
2. Use
This will return the albums for specified user or group with certain privacy levels (Public, Private, etc.) and the result will be pages so no need to worry about the optimization.
If you need to search for album with specific name you can use the code below to do so
...
/// <summary>
/// Retrieves a collection of album entities for the paging scenarios.
/// </summary>
/// <param name="searchPhrase">User ID.</param>
/// <param name="userId">User ID.</param>
/// <param name="groupId">Group ID.</param>
/// <param name="privacyLevelIds">Privacy level ids</param>
/// <param name="fullPrefetchPath">Include full prefetch path</param>
/// <param name="pageIndex">Page index.</param>
/// <param name="pageSize">Page size.</param>
/// <param name="recordCount">Record count.</param>
/// <returns>Collection of album entities that satisfy the criteria from the parameter list.</returns>
public virtual EntityCollection<SnAlbumEntity> GetAlbums(string searchPhrase, Guid? userId, Guid? groupId, List<Guid> privacyLevelIds, bool fullPrefetchPath, int pageIndex, int pageSize, out int recordCount)
{
EntityCollection<SnAlbumEntity> albums = new EntityCollection<SnAlbumEntity>();
RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(SnAlbumFields.ApplicationId == MembershipRepository.GetInstance().GetApplicationId());
filter.PredicateExpression.Add(SnAlbumFields.LanguageId == LocalizationUtility.GetCurrentLanguageId());
if (groupId.HasValue)
{
filter.PredicateExpression.Add(SnAlbumFields.SnGroupId == groupId.GetValueOrDefault());
if (userId.HasValue && !Guid.Empty.Equals(userId.GetValueOrDefault()))
filter.PredicateExpression.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
}
else
{
PredicateExpression peRoot = new PredicateExpression();
//Filter in user photo albums but exclude the group photo albums
PredicateExpression pe = new PredicateExpression();
pe.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
pe.Add(SnAlbumFields.SnGroupId == DBNull.Value);
peRoot.Add(pe);
if (privacyLevelIds.Count > 0)
{
filter.Relations.Add(SnAlbumEntity.Relations.AspnetUsersEntityUsingUserId);
PredicateExpression pePrivacy = new PredicateExpression();
PredicateExpression peGroup = new PredicateExpression();
peGroup.Add(SnAlbumFields.SnGroupId == DBNull.Value);
if (!(SecurityUtility.IsAdmin() || SecurityUtility.IsPhotoGalleryAdmin()))
{
PredicateExpression privacyFilter = new PredicateExpression();
PredicateExpression friendFilter = new PredicateExpression();
friendFilter.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
friendFilter.AddWithOr(FriendRepository.GetInstance().GetFriendshipFilter(userId.GetValueOrDefault()));
PredicateExpression friendPrivacyFilter = GetFriendPrivacyFilter();
friendFilter.Add(friendPrivacyFilter);
privacyFilter.AddWithOr(friendFilter);
pePrivacy.Add(privacyFilter);
}
pePrivacy.Add(peGroup);
peRoot.AddWithOr(pePrivacy);
}
filter.PredicateExpression.Add(peRoot);
}
AddPartialPhraseSearch(filter, SnAlbumFields.Name, searchPhrase);
AddWithOrPartialPhraseSearch(filter, SnAlbumFields.Description, searchPhrase);
ISortExpression sorter = new SortExpression(SnAlbumFields.DateCreated | SortOperator.Descending);
FetchEntityCollection(albums, filter, 0, sorter, GetPrefetchPath(fullPrefetchPath), pageIndex, pageSize);
InitAlbumCovers(albums);
recordCount = GetDbCount(albums, filter);
return albums;
}
...
3. After you fetch the albums choose the album you want and set the
BTW can you please open a separate topics for things like this - we are not talking about the Photo gallery and topic is related to File Gallery :)