public Feed ToFeed() { var feed = Feed.Create(Link); feed.Id = Id; feed.Title = Title; feed.CategoryId = CategoryId; feed.CountryId = CountryId; return(feed); }
public async Task <Result> Handle(CreateFeedCommand command) { var feedResult = Feed.Create(command.Id, command.Name); if (feedResult.IsFailure) { return(Result.Fail(feedResult.Error)); } await _feedRepository.Add(feedResult.Value); await _feedRepository.UnitOfWork.SaveChangesAsync(); return(Result.Ok()); }
private void AddFeed() { var feed = Feed.Create(Database); var category = (Category)CategoryListBox.SelectedItem; feed.Category = category; var feedWindow = new FeedWindow(); var result = feedWindow.Display(Database, feed, Window.GetWindow(this)); if (result.HasValue && result.Value) { Database.Feeds.Add(feed); FeedListBox.SelectedItem = feed; SetFeedButtonStates(); } }
private void ImportFeeds() { // Setup the open file dialog var openFileDialog = new OpenFileDialog { Filter = Properties.Resources.ImportExportFilter, FilterIndex = 0 }; var result = openFileDialog.ShowDialog(); if (!result.GetValueOrDefault(false)) { return; } // Setup the reader settings var xmlReaderSettings = new XmlReaderSettings { IgnoreWhitespace = true }; // Create an XML reader for the file chosen var xmlReader = XmlReader.Create(openFileDialog.FileName, xmlReaderSettings); try { // Read the first node xmlReader.Read(); // Read the OPML node xmlReader.ReadStartElement("opml"); // Read the body node xmlReader.ReadStartElement("body"); // Read all outline nodes while (xmlReader.NodeType != XmlNodeType.EndElement) { // Create a new feed var feed = Feed.Create(Database); feed.Category = Database.Categories.First(c => c.IsDefault); // Loop over all attributes while (xmlReader.MoveToNextAttribute()) { // Handle the attibute switch (xmlReader.Name.ToLower()) { case "title": feed.Title = xmlReader.Value; break; case "htmlurl": feed.Link = xmlReader.Value; break; case "xmlurl": feed.Source = xmlReader.Value; break; case "text": feed.Name = xmlReader.Value; break; } } // Fill in defaults for optional fields if (string.IsNullOrEmpty(feed.Name)) { feed.Name = feed.Title; } // Add the feed to the main list Database.Feeds.Add(feed); // Move back to the element node xmlReader.MoveToElement(); // Skip to the next node xmlReader.Skip(); } // End the body node xmlReader.ReadEndElement(); // End the OPML node xmlReader.ReadEndElement(); } finally { xmlReader.Close(); } }