public async Task <ActionResult> Edit(Guid readerId, InputModel model) { try { await _repository.Update(readerId, new Writer(model.EmailAddress, model.Username, model.Name)); return(StatusCode(StatusCodes.Status200OK)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
private void UpdateDatabaseWithWatchable(CompleteWatchable watchable, DatabaseBuilderType type, string path = "") { if (type == DatabaseBuilderType.Movies) { var files = Directory.GetFileSystemEntries(path).ToList(); var actors = new List <Actor>(watchable.Actors); var writers = new List <Writer>(watchable.Writers); var directors = new List <Director>(watchable.Directors); var genres = new List <Genre>(watchable.Genres); watchable.Actors.Clear(); watchable.Writers.Clear(); watchable.Directors.Clear(); watchable.Genres.Clear(); _moviesRepository.Create((Movie)watchable); foreach (var file in files) { if (file.EndsWith("srt")) { if (files.Count > 2) { BasicLogger.Log(watchable.Title + "'s subtitles not added due to more than 2 files being present in the directory.", Verbosity.Error); } else { var subs = new Subtitles { Language = SubtitleLanguage.English, Path = file, Watchable = watchable }; _subtitlesRepository.Create(subs); } } else if (file.EndsWith("mp4") || file.EndsWith("avi") || file.EndsWith("mkv") || file.EndsWith("wmv")) { watchable.Path = file; _moviesRepository.Update((Movie)watchable); } } foreach (var actor in actors) { var databaseActor = _actorsRepository.Query(x => x.Name == actor.Name).FirstOrDefault(); if (databaseActor == null) { actor.Watchables = new List <Watchable> { watchable }; _actorsRepository.Create(actor); } else { if (databaseActor.Watchables == null) { databaseActor.Watchables = new List <Watchable>(); } if (databaseActor.Watchables.Contains(watchable)) { continue; } databaseActor.Watchables.Add(watchable); _actorsRepository.Update(databaseActor); } } foreach (var writer in writers) { var databaseWriter = _writersRepository.Query(x => x.Name == writer.Name).FirstOrDefault(); if (databaseWriter == null) { writer.Watchables = new List <Watchable> { watchable }; _writersRepository.Create(writer); } else { if (databaseWriter.Watchables == null) { databaseWriter.Watchables = new List <Watchable>(); } if (databaseWriter.Watchables.Contains(watchable)) { continue; } databaseWriter.Watchables.Add(watchable); _writersRepository.Update(databaseWriter); } } foreach (var director in directors) { var databaseDirector = _directorsRepository.Query(x => x.Name == director.Name).FirstOrDefault(); if (databaseDirector == null) { director.Watchables = new List <Watchable> { watchable }; _directorsRepository.Create(director); } else { if (databaseDirector.Watchables == null) { databaseDirector.Watchables = new List <Watchable>(); } if (databaseDirector.Watchables.Contains(watchable)) { continue; } databaseDirector.Watchables.Add(watchable); _directorsRepository.Update(databaseDirector); } } foreach (var genre in genres) { var databaseGenre = _genresRepository.Query(x => x.Name == genre.Name).FirstOrDefault(); if (databaseGenre == null) { genre.Watchables = new List <Watchable> { watchable }; _genresRepository.Create(genre); } else { if (databaseGenre.Watchables == null) { databaseGenre.Watchables = new List <Watchable>(); } if (databaseGenre.Watchables.Contains(watchable)) { continue; } databaseGenre.Watchables.Add(watchable); _genresRepository.Update(databaseGenre); } } } }