public async Task <IActionResult> Delete(DeleteListViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var list = await _traktRepository.Get(model.Id); if (list == null) { return(RedirectToAction(nameof(My))); } if (list.Owner.UserName == User.Identity.Name) { try { await _traktService.Delete(list); } catch (TraktListNotFoundException) { } await _traktRepository.Delete(list); } return(RedirectToAction(nameof(My))); }
public async Task Execute(uint param) { try { var list = await traktService.Get(param, true); var found = await traktService.ShowSearch(list); var existing = await traktService.GetShows(list); var toRemove = new List <ITraktShow>(); foreach (var existingShow in existing) { if (!found.Contains(existingShow, new TraktShowComparer())) { toRemove.Add(existingShow); } } var toAdd = new List <ITraktShow>(); foreach (var foundShow in found) { if (!existing.Contains(foundShow, new TraktShowComparer())) { toAdd.Add(foundShow); } } if (toAdd.Any()) { //Chunking to 100 items per list cause trakt api does not like 10000s of items foreach (var toAddChunk in toAdd.ChunkBy(100)) { await traktService.AddShows(toAddChunk, list); } } if (toRemove.Any()) { //Chunking to 100 items per list cause trakt api does not like 10000s of items foreach (var toRemoveChunk in toRemove.ChunkBy(100)) { await traktService.RemoveShows(toRemoveChunk, list); } } list = await traktService.Get(list.Id, true); list.LastProcessed = DateTime.Now; await traktService.Update(list); } catch (TraktListNotFoundException) { await traktService.Delete(await traktService.Get(param)); } }
public async Task Execute(uint param) { try { var list = await traktService.Get(param, true); var foundMovies = await traktService.MovieSearch(list); var existingMovies = await traktService.GetMovies(list); var moviesToRemove = new List <ITraktMovie>(); foreach (var existingMovie in existingMovies) { if (!foundMovies.Contains(existingMovie, new TraktMovieComparer())) { moviesToRemove.Add(existingMovie); } } var moviesToAdd = new List <ITraktMovie>(); foreach (var foundMovie in foundMovies) { if (!existingMovies.Contains(foundMovie, new TraktMovieComparer())) { moviesToAdd.Add(foundMovie); } } if (moviesToAdd.Any()) { //Chunking to 100 items per list cause trakt api does not like 10000s of items foreach (var moviesToAddChunk in moviesToAdd.ChunkBy(100)) { await traktService.AddMovies(moviesToAddChunk, list); } } if (moviesToRemove.Any()) { //Chunking to 100 items per list cause trakt api does not like 10000s of items foreach (var moviesToRemoveChunk in moviesToRemove.ChunkBy(100)) { await traktService.RemoveMovies(moviesToRemoveChunk, list); } } list = await traktService.Get(list.Id, true); list.LastProcessed = DateTime.Now; await traktService.Update(list); } catch (TraktListNotFoundException) { await traktService.Delete(await traktService.Get(param)); } }
public async Task Execute(uint param) { try { traktList = await _traktService.Get(param, true); traktList.ScanState = ScanState.Updating; await _traktService.Update(traktList); var found = await _traktService.ShowSearch(traktList); var existing = await _traktService.GetShows(traktList); var remove = existing.Except(found, new TraktShowComparer()).ToList(); var add = found.Except(existing, new TraktShowComparer()).ToList(); if (add.Any()) { foreach (var toAddChunk in add.ChunkBy(500)) { await _traktService.AddShows(toAddChunk, traktList); } } if (remove.Any()) { foreach (var toRemoveChunk in remove.ChunkBy(500)) { await _traktService.RemoveShows(toRemoveChunk, traktList); } } traktList.LastProcessed = DateTime.Now; } catch (TraktListNotFoundException) { await _traktService.Delete(new TraktList { Id = param }); } finally { traktList.ScanState = ScanState.None; await _traktService.Update(traktList); } }
public async Task <IActionResult> Delete(DeleteListViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var list = await _traktService.Get(model.Id); if (list == null) { return(RedirectToAction(nameof(Lists))); } if (list.Owner.UserName == User.Identity.Name) { await _traktService.Delete(list, false); } return(RedirectToAction(nameof(Lists))); }