Beispiel #1
0
        public Task<bool> SaveFlickrImagesCollectionAsync(List<FlickrImage> images)
        {
            if (images == null || images.Count == 0)
                return Task.FromResult<bool>(false);

            try
            {
                //Adding data to the local database
                using (var context = new FerrariDataContext())
                {
                    var oldImages = context.Images;
                    context.Images.DeleteAllOnSubmit(oldImages);
                    context.SubmitChanges();

                    foreach (FlickrImage item in images)
                    {
                        context.GetTable<FlickrImage>().InsertOnSubmit(item);
                    }
                    context.SubmitChanges();
                }

                return Task.FromResult<bool>(true);
            }
            catch (Exception exc)
            {
                return Task.FromResult<bool>(false);
            }
        }
Beispiel #2
0
        public Task<bool> SaveTweetsCollectionAsync(List<Tweet> tweets)
        {
            if (tweets == null || tweets.Count == 0)
                return Task.FromResult(false);

            try
            {
                //Adding data to the local database
                using (var context = new FerrariDataContext())
                {
                    Table<Tweet> oldTweets = context.GetTable<Tweet>();
                    context.GetTable<Tweet>().DeleteAllOnSubmit(oldTweets);
                    context.SubmitChanges();

                    foreach (Tweet tweet in tweets)
                    {
                        context.GetTable<Tweet>().InsertOnSubmit(tweet);
                    }
                    context.SubmitChanges();
                }

                return Task.FromResult(true);
            }
            catch (Exception exc)
            {
                return Task.FromResult(false);
            }
        }
Beispiel #3
0
        public Task<bool> SaveItemsCollectionAsync(List<Item> items)
        {
            if (items == null || items.Count == 0)
                return Task.FromResult<bool>(false);

            try
            {
                //Adding data to the local database
                using (var context = new FerrariDataContext())
                {
                    var oldItems = context.GetTable<Item>().Where(entity => entity.Category == items.FirstOrDefault().Category);
                    context.GetTable<Item>().DeleteAllOnSubmit(oldItems);
                    context.SubmitChanges();

                    foreach (Item item in items)
                    {
                        context.GetTable<Item>().InsertOnSubmit(item);
                    }
                    context.SubmitChanges();
                }

                return Task.FromResult<bool>(true);
            }
            catch (Exception exc)
            {
                return Task.FromResult<bool>(false);
            }
        }
Beispiel #4
0
        public Task<bool> SaveVideosCollectionAsync(List<YoutubeVideo> videos)
        {
            if (videos == null || videos.Count == 0)
                return Task.FromResult<bool>(false);

            try
            {
                //Adding data to the local database
                using (var context = new FerrariDataContext())
                {
                    var oldVideos = context.GetTable<YoutubeVideo>();
                    context.GetTable<YoutubeVideo>().DeleteAllOnSubmit(oldVideos);
                    context.SubmitChanges();

                    foreach (var video in videos)
                    {
                        context.GetTable<YoutubeVideo>().InsertOnSubmit(video);
                    }
                    context.SubmitChanges();
                }

                return Task.FromResult<bool>(true);
            }
            catch (Exception exc)
            {
                return Task.FromResult<bool>(false);
            }
        }