Example #1
0
        /// <summary>
        /// Takes a fee url, verifies it, and adds it to the database
        /// </summary>
        /// <param name="url">An RSS feed</param>
        /// <returns>True if the feed was successfully added, false otherwise</returns>
        public Boolean AddFeed(String url)
        {
            Boolean returnValue = false;

            //verify the url isn't already in our list
            if (feedList.Where(f => f.Url.ToLower().Contains(url.ToLower())).Any())
                return true;

            //get the feed info
            Feed internalFeed;
            SyndicationFeed feed;
            try
            {
                feed = SyndicationFeed.Load(XmlReader.Create(url));
                internalFeed = new Feed();
                internalFeed.Title = feed.Title.Text;
                internalFeed.Url = url;

                //add the Feed to the db
                if (internalFeed != null)
                {
                    using (var ctx = new RssReaderDbContext())
                    {
                        ctx.Feeds.Add(internalFeed);
                        ctx.SaveChanges();
                        returnValue = true;
                    }
                }
            }
            catch (Exception)
            {
                returnValue = false;
            }

            PopulateFeedList();

            return returnValue;
        }
Example #2
0
        /// <summary>
        /// Deletes the specified feed from the database and re-populates the local feedlist
        /// </summary>
        /// <param name="feedToRemove">A Feed object</param>
        /// <returns>True if the feed was removed.</returns>
        public Boolean RemoveFeed(Feed feedToRemove)
        {
            Boolean returnValue = false;

            using (var ctx = new RssReaderDbContext())
            {
                ctx.Feeds.Remove(feedToRemove);
                returnValue = true;
            }

            PopulateFeedList();
            return returnValue;
        }