public async Task <bool> ToggleFavorite(Session session)
        {
            if (!Settings.Current.IsLoggedIn)
            {
                sessionQueued = session;
                return(false);
            }

            sessionQueued = null;

            session.IsFavorite = !session.IsFavorite;//switch first so UI updates :)
            if (!session.IsFavorite)
            {
                _logger.Log($"{DevopenspaceLoggerKeys.FavoriteRemoved}, Title, {session.Title}", Prism.Logging.Category.Info, Prism.Logging.Priority.None);

                var items = await _favoriteStore.GetItemsAsync();

                foreach (var item in items.Where(s => s.SessionId == session.Id))
                {
                    await _favoriteStore.RemoveAsync(item);
                }
            }
            else
            {
                _logger.Log($"{DevopenspaceLoggerKeys.FavoriteAdded}, Title, {session.Title}", Prism.Logging.Category.Info, Prism.Logging.Priority.None);
                await _favoriteStore.InsertAsync(new Favorite { SessionId = session.Id });
            }

            Settings.Current.LastFavoriteTime = DateTime.UtcNow;
            return(true);
        }
Esempio n. 2
0
        public override async Task <IEnumerable <Session> > GetItemsAsync(bool forceRefresh = false)
        {
            var sessions = await GetSessions(forceRefresh);

            if (!sessions.Any())
            {
                sessions = await GetSessions(true);
            }
            await _favoriteStore.GetItemsAsync(true).ConfigureAwait(false);//pull latest

            foreach (var session in sessions)
            {
                var isFav = await _favoriteStore.IsFavorite(session.Id).ConfigureAwait(false);

                session.IsFavorite = isFav;
            }

            return(sessions);
        }
        public override async Task <IEnumerable <Workshop> > GetItemsAsync(bool forceRefresh = false)
        {
            var workshops = await GetWorkshops(forceRefresh);

            if (!workshops.Any())
            {
                workshops = await GetWorkshops(true);
            }
            await _favoriteStore.GetItemsAsync(true).ConfigureAwait(false);//pull latest

            foreach (var workshop in workshops)
            {
                var isFav = await _favoriteStore.IsFavoriteWorkshop(workshop.Id).ConfigureAwait(false);

                workshop.IsFavorite = isFav;
            }

            return(workshops);
        }