public Comic Edit(Comic entity) { HtmlNode htmlBody = GetHtmlBody(entity.ComicUrl); if (htmlBody == null) return entity; HtmlNode comicDiv = htmlBody.ChildNodes.FirstOrDefault(c => c.Name.Equals("section")) .ChildNodes.FirstOrDefault(c => c.Name.Equals("div")) .ChildNodes.FirstOrDefault(c => c.InnerHtml.Contains("table")); HtmlNode comicTable = DigToFirstTable(comicDiv); HtmlNode chaptersTable = DigToLastTable(comicDiv); HtmlNode authorNode = comicTable == null ? null : comicTable.ChildNodes.FirstOrDefault(c => c.InnerText.ToUpper().Contains("AUTHOR")); string author = authorNode == null ? "" : authorNode.ChildNodes.LastOrDefault(c => c.Name.Equals("td")).InnerText; HtmlNode genreNode = comicTable == null ? null : comicTable.ChildNodes.FirstOrDefault(c => c.InnerHtml.ToUpper().Contains("GENRE")); string genre = genreNode == null ? "" : genreNode.ChildNodes.LastOrDefault(c => c.Name.Equals("td")).InnerText; HtmlNode publisherNode = comicTable == null ? null : comicTable.ChildNodes.FirstOrDefault(c => c.InnerHtml.ToUpper().Contains("PUBLISHER")); string publisher = publisherNode == null ? "" : publisherNode.ChildNodes.LastOrDefault(c => c.Name.Equals("td")).InnerText; //TODO: Arrumar isso aqui entity.DirtyStateAuthor = author; entity.DirtyStateGenre = genre; entity.DirtyStatePublisher = publisher; entity.Chapters = GetChapters(chaptersTable); return entity; }
private Comic GetNewComic(Comic c) { return new Comic { ComicId = c.ComicId, ComicName = c.ComicName, ComicUrl = c.ComicUrl, CoverUrl = c.CoverUrl, Description = c.Description, Authors = c.Authors == null ? null : c.Authors.Select(a => new Author { AuthorId = a.AuthorId, AuthorName = a.AuthorName }).ToList(), Genres = c.Genres == null ? null : c.Genres.Select(g => new Genre { GenreId = g.GenreId, GenreName = g.GenreName }).ToList(), Publishers = c.Publishers == null ? null : c.Publishers.Select(p => new Publisher { PublisherId = p.PublisherId, PublisherName = p.PublisherName }).ToList(), Chapters = c.Chapters == null ? null : c.Chapters.Select(ch => new Chapter { ChapterId = ch.ChapterId, ChapterName = ch.ChapterName, ChapterUrl = ch.ChapterUrl, ReleaseDate = ch.ReleaseDate }).ToList() }; }
public void Add(Comic entity) { throw new NotImplementedException(); }
public void Delete(Comic entity) { }
public ComicVM(Comic comic) { ComicId = comic.ComicId; ComicName = comic.ComicName; CoverUrl = comic.CoverUrl; }
private IList<Comic> CreateComics(HtmlNode comicNode) { IList<Comic> comics = new List<Comic>(); foreach (HtmlNode innerNode in comicNode.ChildNodes.Where(c => c.Name.Equals("li"))) { Comic comic = new Comic(); HtmlNode aNode = innerNode.ChildNodes.FirstOrDefault(c => c.Name.Equals("a")); comic.ComicName = aNode.InnerText; comic.ComicUrl = aNode.Attributes.FirstOrDefault(a => a.Name.Equals("href")).Value; comic.CoverUrl = aNode.Attributes.FirstOrDefault(a => a.Name.Equals("data-image")).Value; comic.Description = aNode.Attributes.FirstOrDefault(a => a.Name.Equals("data-desc")).Value; comics.Add(comic); } return comics; }
public static Comic ToComic(Comic comic) { return new Comic { Authors = comic.Authors, ComicId = comic.ComicId, ComicName = comic.ComicName, ComicUrl = comic.ComicUrl, CoverUrl = comic.CoverUrl, Description = comic.Description, Publishers = comic.Publishers, Chapters = comic.Chapters }; }
public static ComicVisitor FromComic(Comic comic) { return new ComicVisitor { Authors = comic.Authors, ComicId = comic.ComicId, ComicName = comic.ComicName, ComicState = ComicState.Empty, ComicUrl = comic.ComicUrl, CoverUrl = comic.CoverUrl, Description = comic.Description, Publishers = comic.Publishers, Chapters = comic.Chapters }; }
private void AddPublisher(Comic comic, IPublisherRepository publisherRepository, string publisherStr) { if (string.IsNullOrEmpty(publisherStr)) return; string[] publishers = publisherStr.Split(','); foreach (string publisher in publishers) { string publisherTrim = publisher.Trim(); Publisher publisherDb = publisherRepository.Find(g => g.PublisherName.Equals(publisherTrim)).FirstOrDefault(); if (publisherDb == null) { publisherDb = new Publisher { PublisherName = publisherTrim, Comics = new List<Comic>() }; publisherDb.Comics.Add(comic); publisherRepository.Add(publisherDb); } else { if (publisherDb.Comics == null) publisherDb.Comics = new List<Comic>(); if (publisherDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue; publisherDb.Comics.Add(comic); publisherRepository.Edit(publisherDb); } if (comic.Publishers == null) comic.Publishers = new List<Publisher>(); if (!comic.Publishers.Any(g => g.PublisherName.Equals(publisherTrim))) { comic.Publishers.Add(publisherDb); } publisherRepository.Save(); } }
private void AddGenre(Comic comic, IGenreRepository genreRepository, string genreStr) { if (string.IsNullOrEmpty(genreStr)) return; string[] genres = genreStr.Split(','); foreach (string genre in genres) { string genreTrim = genre.Trim(); Genre genreDb = genreRepository.Find(g => g.GenreName.Equals(genreTrim)).FirstOrDefault(); if (genreDb == null) { genreDb = new Genre { GenreName = genreTrim, Comics = new List<Comic>() }; genreDb.Comics.Add(comic); genreRepository.Add(genreDb); } else { if (genreDb.Comics == null) genreDb.Comics = new List<Comic>(); if (genreDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue; genreDb.Comics.Add(comic); genreRepository.Edit(genreDb); } if (comic.Genres == null) comic.Genres = new List<Genre>(); if (!comic.Genres.Any(g => g.GenreName.Equals(genreTrim))) { comic.Genres.Add(genreDb); } genreRepository.Save(); } }
private void AddAuthor(Comic comic, IAuthorRepository authorRepository, string authorStr) { if (string.IsNullOrEmpty(authorStr)) return; string[] authors = authorStr.Split(','); foreach (string author in authors) { string authorTrim = author.Trim(); Author authorDb = authorRepository.Find(a => a.AuthorName.Equals(authorTrim)).FirstOrDefault(); if (authorDb == null) { authorDb = new Author { AuthorName = authorTrim, Comics = new List<Comic>() }; authorDb.Comics.Add(comic); authorRepository.Add(authorDb); } else { if (authorDb.Comics == null) authorDb.Comics = new List<Comic>(); if (authorDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue; authorDb.Comics.Add(comic); authorRepository.Edit(authorDb); } if (comic.Authors == null) comic.Authors = new List<Author>(); if (!comic.Authors.Any(a => a.AuthorName.Equals(authorTrim))) { comic.Authors.Add(authorDb); } authorRepository.Save(); } }