public async Task SaveManga(IList<JsonManga> mangas) { if (mangas == null) throw new ArgumentNullException("mangas"); _logger.Trace("Saving " + mangas.Count() + " mangas to database..."); using (MangaEdenContext context = new MangaEdenContext()) { List<JsonManga> existing = await context.Mangas.ToListAsync(); context.Mangas.AddRange(mangas.Except(existing, new JsonMangaComparer())); await context.SaveChangesAsync(); _logger.Trace("Saved."); } }
public async Task<IList<JsonManga>> LoadMangas() { using (MangaEdenContext context = new MangaEdenContext()) { _logger.Trace("Loading mangas from database..."); return await context.Mangas.OrderBy(x => x.Alias).ToListAsync(); } }
public async Task DeleteMangas(IList<JsonManga> mangas) { if (mangas == null) throw new ArgumentNullException("mangas"); _logger.Trace("Removing " + mangas.Count() + " mangas from database..."); using (MangaEdenContext context = new MangaEdenContext()) { foreach (JsonManga manga in mangas) { JsonManga m = await context.Mangas.FirstOrDefaultAsync(x => x.Alias == manga.Alias); if (m != null) context.Mangas.Remove(m); } await context.SaveChangesAsync(); _logger.Trace("Saved."); } }