Пример #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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #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);
            }
        }
Пример #5
0
        public Task<List<FlickrImage>> GetFlickrImagesCollectionAsync()
        {
            try
            {
                List<FlickrImage> images;

                using (var context = new FerrariDataContext())
                {
                    IQueryable<FlickrImage> itemsCollection = from itms
                        in context.GetTable<FlickrImage>()
                        select itms;

                    images = itemsCollection.ToList();
                }

                return Task.FromResult<List<FlickrImage>>(images);
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #6
0
        public Task<List<Item>> GetItemsCollectionByCategoryAsync(string itemCategory)
        {
            try
            {
                List<Item> items;

                using (var context = new FerrariDataContext())
                {
                    IQueryable<Item> itemsCollection = from itms
                        in context.GetTable<Item>()
                        select itms;

                    items = itemsCollection.Where(item => item.Category == itemCategory).ToList();
                }

                return Task.FromResult(items);
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #7
0
        public Task<List<Tweet>> GetTweetsCollectionAsync()
        {
            try
            {
                List<Tweet> tweets;

                using (var context = new FerrariDataContext())
                {
                    IQueryable<Tweet> itemsCollection = from itms
                        in context.GetTable<Tweet>()
                        select itms;

                    tweets = itemsCollection.ToList();
                }

                return Task.FromResult(tweets);
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #8
0
        public Task<List<YoutubeVideo>> GetVideosCollectionAsync()
        {
            try
            {
                List<YoutubeVideo> videos;

                using (var context = new FerrariDataContext())
                {
                    IQueryable<YoutubeVideo> vdeos = from itms
                                                       in context.GetTable<YoutubeVideo>()
                                                       select itms;

                    videos = vdeos.ToList();
                }

                return Task.FromResult<List<YoutubeVideo>>(videos);
            }
            catch (Exception)
            {
                return null;
            }
        }