public async Task <IActionResult> Edit(int id, TVShowEditViewModel editModel) { TVshow tvshowFromDB = await _mediaWebDbContext.TVShows.FirstOrDefaultAsync(m => m.Id == id); List <string> tvshowTitlesFromDb = await _mediaWebDbContext.TVShows.Where(tv => tv != tvshowFromDB).Select(tvs => tvs.Name).ToListAsync(); if (tvshowTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(editModel.Name))) { return(RedirectToAction("Index")); } tvshowFromDB.Name = editModel.Name; tvshowFromDB.ReleaseDate = editModel.ReleaseDate; tvshowFromDB.Summary = editModel.Summary; if (editModel.Picture != null) { tvshowFromDB.Picture = UploadUtility.UploadFile(editModel.Picture, "tvshows", _hostingEnvironment); } else { tvshowFromDB.Picture = editModel.PictureFile; } await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public static void TestUpload() { var filePath = SavePath + "/35/sticker_prefab_ppbbbmhmf_10_common.png"; UploadUtility.UploadFile(filePath, (res, msg) => { Debug.Log(UploadUtility.GetDownloadFileUrl(res)); }); }
private IEnumerator UploadFiles() { RenderThumbMgr.ReportSegTime(5, "ToUpload"); if (thumbFiles.Count == 0) { onFinish.InvokeGracefully(null, "待渲染零件个数为0"); yield break; } uploadCounter = 0; mUploadFiles = new UploadFiles(); uploadMsg = string.Empty; foreach (var file in thumbFiles.Keys) { UploadUtility.UploadFile(file, OnUploadItemFinish); yield return(null); } }
public async Task <IActionResult> Edit(int id, PodcastEditViewModel editModel) { PodCast podcastFromDb = await _mediaWebDbContext.PodCasts.FirstOrDefaultAsync(m => m.Id == id); List <string> podcastTitlesFromDb = await _mediaWebDbContext.PodCasts.Where(podcast => podcast != podcastFromDb).Select(p => p.Title).ToListAsync(); if (podcastTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(editModel.Title))) { return(RedirectToAction("index")); } podcastFromDb.Title = editModel.Title; podcastFromDb.ReleaseDate = editModel.ReleaseDate; podcastFromDb.Description = editModel.Description; podcastFromDb.File = UploadUtility.UploadFile(editModel.Podcast, "podcasts", _hostingEnvironment); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id, MovieEditViewModel editModel) { Movie movieFromDb = await _mediaWebDbContext.Movies.FirstOrDefaultAsync(m => m.Id == id); movieFromDb.Title = editModel.Title; movieFromDb.ReleaseDate = editModel.ReleaseDate; movieFromDb.Summary = editModel.Summary; if (editModel.Photo != null) { movieFromDb.Photo = UploadUtility.UploadFile(editModel.Photo, "pics", _hostingEnvironment); } else { movieFromDb.Photo = editModel.PhotoUrl; } await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(MusicCreateViewModel createModel) { List <string> songsFromDb = await _mediaWebDbContext.Songs.Select(s => s.Title).ToListAsync(); List <string> artistFromDb = await _mediaWebDbContext.Artists.Select(a => a.Name).ToListAsync(); //check for duplicates if (songsFromDb.Contains(StringEdits.FirstLettterToUpper(createModel.Title))) { return(RedirectToAction("Index")); } Song newSong = new Song() { Title = StringEdits.FirstLettterToUpper(createModel.Title), ReleaseDate = createModel.ReleaseDate, SongFile = UploadUtility.UploadFile(createModel.Song, "songs", _hostingEnvironment) }; //add artists to song var songArtists = new List <SongArtist>(); //create only if new artists if (createModel.createdArtists != null) { var createdArtists = StringEdits.FirstLettterToUpper(createModel.createdArtists); var createdArtistsArray = createdArtists.Split(", "); var newArtists = new List <Artist>(); var artistsFromDb = await _mediaWebDbContext.Artists.ToListAsync(); foreach (var createdArtist in createdArtistsArray) { if (!artistsFromDb.Select(g => g.Name).Contains(createdArtist)) { newArtists.Add(new Artist() { Name = createdArtist }); } else { songArtists.Add(new SongArtist() { Artist = artistsFromDb.Find(g => g.Name == createdArtist) }); } } foreach (var newArtist in newArtists) { songArtists.Add(new SongArtist() { ArtistId = newArtist.Id, Artist = newArtist }); } } newSong.SongArtists = songArtists; _mediaWebDbContext.Update(newSong); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id, MusicEditViewModel editModel) { Song songFromDb = await _mediaWebDbContext.Songs.FirstOrDefaultAsync(s => s.Id == id); var tempFile = songFromDb.SongFile; List <string> songTitlesFromDb = await _mediaWebDbContext.Songs.Where(song => song != songFromDb).Select(s => s.Title).ToListAsync(); //check for duplicates if (songTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(editModel.Title))) { return(RedirectToAction("Index")); } songFromDb.Title = editModel.Title; songFromDb.ReleaseDate = editModel.ReleaseDate; var songArtists = new List <SongArtist>(); if (editModel.createdArtists != null) { var createdArtists = StringEdits.FirstLettterToUpper(editModel.createdArtists); var createdArtistsArray = createdArtists.Split(", "); var newArtists = new List <Artist>(); var artistsFromDb = await _mediaWebDbContext.Artists.ToListAsync(); foreach (var createdArtist in createdArtistsArray) { if (!artistsFromDb.Select(g => g.Name).Contains(createdArtist)) { newArtists.Add(new Artist() { Name = createdArtist }); } else { songArtists.Add(new SongArtist() { Artist = artistsFromDb.Find(g => g.Name == createdArtist) }); } } foreach (var newArtist in newArtists) { songArtists.Add(new SongArtist() { ArtistId = newArtist.Id, Artist = newArtist }); } } songFromDb.SongArtists = songArtists; if (editModel.Song != null) { songFromDb.SongFile = UploadUtility.UploadFile(editModel.Song, "songs", _hostingEnvironment); } else { songFromDb.SongFile = tempFile; } await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(MovieCreateViewModel createModel) { //check for duplicate List <string> movieTitlesFromDb = await _mediaWebDbContext.Movies.Select(m => m.Title).ToListAsync(); if (movieTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(createModel.Title))) { return(RedirectToAction("Index")); } //create if no duplicate Movie newMovie = new Movie() { Title = StringEdits.FirstLettterToUpper(createModel.Title), ReleaseDate = createModel.ReleaseDate, Summary = createModel.Summary, Photo = UploadUtility.UploadFile(createModel.Photo, "pics", _hostingEnvironment), IsHidden = false }; //Add genres to movie var movieGenres = new List <MovieGenre>(); //Select from existing genres if (createModel.SelectedGenres != null) { foreach (var selectedGenre in createModel.SelectedGenres) { movieGenres.Add(new MovieGenre() { GenreId = selectedGenre }); } } //create only if new genres if (createModel.createdGenres != null) { var createdGenres = StringEdits.FirstLettterToUpper(createModel.createdGenres); var createdGenresArray = createdGenres.Split(", "); var newGenres = new List <Genre>(); var genresFromDb = await _mediaWebDbContext.Genres.ToListAsync(); foreach (var createdGenre in createdGenresArray) { if (!genresFromDb.Select(g => g.Name).Contains(createdGenre)) { newGenres.Add(new Genre() { Name = createdGenre }); } else { movieGenres.Add(new MovieGenre() { Genre = genresFromDb.Find(g => g.Name == createdGenre) }); } } foreach (var newGenre in newGenres) { movieGenres.Add(new MovieGenre() { Genre = newGenre }); } } newMovie.MovieGenres = movieGenres; //add actors to movie var movieActors = new List <MovieActor>(); //create only if new actors if (createModel.createdActors != null) { var createdActors = StringEdits.FirstLettterToUpper(createModel.createdActors); var createdActorsArray = createdActors.Split(", "); var newActors = new List <Actor>(); var actorsFromDb = await _mediaWebDbContext.Actors.ToListAsync(); foreach (var createdActor in createdActorsArray) { //check for duplicates if (!actorsFromDb.Select(g => g.Name).Contains(createdActor)) { newActors.Add(new Actor() { Name = createdActor }); } else { movieActors.Add(new MovieActor() { Actor = actorsFromDb.Find(g => g.Name == createdActor) }); } } foreach (var newActor in newActors) { movieActors.Add(new MovieActor() { Actor = newActor }); } } newMovie.MovieActors = movieActors; //add directors to movie var movieDirectors = new List <MovieDirector>(); //create only if new directors if (createModel.createdDirectors != null) { var createdDirectors = StringEdits.FirstLettterToUpper(createModel.createdDirectors); var createdDirectorsArray = createdDirectors.Split(", "); var newDirectors = new List <Director>(); var directorsFromDb = await _mediaWebDbContext.Directors.ToListAsync(); foreach (var createdDirector in createdDirectorsArray) { if (!directorsFromDb.Select(g => g.Name).Contains(createdDirector)) { newDirectors.Add(new Director() { Name = createdDirector }); } else { movieDirectors.Add(new MovieDirector() { Director = directorsFromDb.Find(g => g.Name == createdDirector) }); } } foreach (var newDirector in newDirectors) { movieDirectors.Add(new MovieDirector() { Director = newDirector }); } } newMovie.MovieDirectors = movieDirectors; _mediaWebDbContext.Update(newMovie); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(TVShowCreateViewModel createModel) { List <string> tvshowTitlesFromDb = await _mediaWebDbContext.TVShows.Select(tvs => tvs.Name).ToListAsync(); if (tvshowTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(createModel.Name))) { return(RedirectToAction("Index")); } TVshow newTvshow = new TVshow() { Name = StringEdits.FirstLettterToUpper(createModel.Name), ReleaseDate = createModel.ReleaseDate, Summary = createModel.Summary, Picture = UploadUtility.UploadFile(createModel.Picture, "tvshows", _hostingEnvironment) }; //Add genres to tvshow var tvshowGenres = new List <TVShowGenre>(); //Select from existing genres if (createModel.SelectedGenres != null) { foreach (var selectedGenre in createModel.SelectedGenres) { tvshowGenres.Add(new TVShowGenre() { GenreId = selectedGenre }); } } //create only if new genres if (createModel.createdGenres != null) { var createdGenres = StringEdits.FirstLettterToUpper(createModel.createdGenres); var createdGenresArray = createdGenres.Split(", "); var newGenres = new List <Genre>(); var genresFromDb = await _mediaWebDbContext.Genres.ToListAsync(); foreach (var createdGenre in createdGenresArray) { if (!genresFromDb.Select(g => g.Name).Contains(createdGenre)) { newGenres.Add(new Genre() { Name = createdGenre }); } else { tvshowGenres.Add(new TVShowGenre() { Genre = genresFromDb.Find(g => g.Name == createdGenre) }); } } foreach (var newGenre in newGenres) { tvshowGenres.Add(new TVShowGenre() { Genre = newGenre }); } } newTvshow.TVShowGenres = tvshowGenres; //add actors to tvshow var tvshowActors = new List <TVShowActor>(); //create only if new actors if (createModel.createdActors != null) { var createdActors = StringEdits.FirstLettterToUpper(createModel.createdActors); var createdActorsArray = createdActors.Split(", "); var newActors = new List <Actor>(); var actorsFromDb = await _mediaWebDbContext.Actors.ToListAsync(); foreach (var createdActor in createdActorsArray) { if (!actorsFromDb.Select(g => g.Name).Contains(createdActor)) { newActors.Add(new Actor() { Name = createdActor }); } else { tvshowActors.Add(new TVShowActor() { Actor = actorsFromDb.Find(g => g.Name == createdActor) }); } } foreach (var newActor in newActors) { tvshowActors.Add(new TVShowActor() { Actor = newActor }); } } newTvshow.TVShowActors = tvshowActors; //add directors to tvshow var tvshowDirectors = new List <TVShowDirector>(); //create only if new directors if (createModel.createdDirectors != null) { var createdDirectors = StringEdits.FirstLettterToUpper(createModel.createdDirectors); var createdDirectorsArray = createdDirectors.Split(", "); var newDirectors = new List <Director>(); var directorsFromDb = await _mediaWebDbContext.Directors.ToListAsync(); foreach (var createdDirector in createdDirectorsArray) { if (!directorsFromDb.Select(g => g.Name).Contains(createdDirector)) { newDirectors.Add(new Director() { Name = createdDirector }); } else { tvshowDirectors.Add(new TVShowDirector() { Director = directorsFromDb.Find(g => g.Name == createdDirector) }); } } foreach (var newDirector in newDirectors) { tvshowDirectors.Add(new TVShowDirector() { Director = newDirector }); } } newTvshow.TVShowDirectors = tvshowDirectors; _mediaWebDbContext.Update(newTvshow); await _mediaWebDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }