Пример #1
0
		private Genre GetGenreInCollectionById(XCollection<Genre> genres, int genreId)
		{
			Genre found = null;

			if (genres != null)
			{
				found = genres.FirstOrDefault(x => x.Id == genreId);

				if (found == null)
				{
					foreach (var genre in genres)
					{
						found = GetGenreInCollectionById(genre.Children, genreId);

						if (found != null)
						{
							break;
						}
					}
				}
			}
			return found;
		}
Пример #2
0
		private async Task LoadBookmarks( Session session )
		{
			XCollection<Bookmark> bookmarks = null;
			try
			{
				bookmarks = await _bookmarksProvider.GetBookmarks( session.Token );
			}
			catch (CatalitNoCredentialException)
			{
				//ToDo: Do something? Message?
			}

			XCollection<Book> books = new XCollection<Book>();

			foreach (var bookmark in bookmarks)
			{
				if( bookmark.Group != "0" )
				{
					var exits = books.FirstOrDefault( x => x.Description.Hidden.DocumentInfo.Id == bookmark.ArtId );

					if( exits != null )
					{
						exits.BookmarksCount++;
					}
					else
					{
						var book = await _catalogProvider.GetBookByDocumentId( bookmark.ArtId, session.Token );
						if( book != null )
						{
							book.BookmarksCount = 1;
							books.Add( book );
						}
					}
				}
			}

			//sort books by last opened
			int top = 0;
			var myBooksHistory = await _catalogProvider.GetBooksIdsFromHistory( session.Token );

			foreach( var mybook in myBooksHistory )
			{
				var inbookmarked = books.FirstOrDefault(x => x.Id == mybook );

				if( inbookmarked != null )
				{
					books.Remove( inbookmarked );
					books.Insert( top, inbookmarked );
					top++;
				}
			}

			BookmarkedBooks.Update( books );

			BookmarkedBooksEmpty = BookmarkedBooks.Count == 0;

			if (bookmarks != null)
			{
				Bookmarks.Update(bookmarks);
			}
		}
Пример #3
0
		private XCollection<Genre> GetGenresInCollectionByTokens(XCollection<Genre> genres, List<string> tokens)
		{
			XCollection<Genre> res = new XCollection<Genre>();
			if (genres != null)
			{
				foreach (var genre in genres)
				{
					if(tokens.Contains( genre.Token ) && res.FirstOrDefault( x => x.Id == genre.Id ) == null)
					{
						res.Add( genre );
					}
					var subcollection = GetGenresInCollectionByTokens(genre.Children, tokens);
					foreach (var subgenre in subcollection)
					{
						if(res.FirstOrDefault( x => x.Id == subgenre.Id ) == null)
						{
							res.Add(subgenre);
						}
					}
				}
			}
			return res;
		}