Exemple #1
0
        public async Task <IActionResult> CreatePlayList(PlaylistCreateViewModel createModel)
        {
            PlayList newPlayList = new PlayList()
            {
                Name      = StringEdits.FirstLettterToUpper(createModel.Name),
                IsPrivate = createModel.IsPrivate
            };

            //Add songs to playlist
            var playlistSongs = new List <PlaylistSong>();

            //Select from existing songs
            if (createModel.SelectedSongs != null)
            {
                foreach (var selectedSong in createModel.SelectedSongs)
                {
                    playlistSongs.Add(new PlaylistSong()
                    {
                        SongId = selectedSong
                    });
                }
            }

            newPlayList.PlaylistSongs = playlistSongs;

            var user = _userManager.GetUserAsync(HttpContext.User).Result;

            user.PlayLists.Add(newPlayList);

            _mediaWebDbContext.Update(newPlayList);
            await _mediaWebDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public async Task <IActionResult> CreateEpisode(EpisodeCreateViewModel createModel, int id)
        {
            TVshow tvshowFromDb = await _mediaWebDbContext.TVShows.FirstOrDefaultAsync(m => m.Id == id);

            Episode newEpisode = new Episode()
            {
                Name          = StringEdits.FirstLettterToUpper(createModel.Name),
                Summary       = createModel.Summary,
                Season        = createModel.Season,
                EpisodeNumber = createModel.EpisodeNumber
            };

            tvshowFromDb.Seasons = createModel.Season;
            tvshowFromDb.Episodes.Add(newEpisode);

            if (tvshowFromDb.Seasons != 0)
            {
                if (newEpisode.Season > tvshowFromDb.Seasons)
                {
                    tvshowFromDb.Seasons = newEpisode.Season;
                }
            }
            else
            {
                tvshowFromDb.Seasons = newEpisode.Season;
            }

            _mediaWebDbContext.Update(tvshowFromDb);
            _mediaWebDbContext.Update(newEpisode);

            await _mediaWebDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        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 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"));
        }
Exemple #5
0
        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"));
        }
Exemple #6
0
        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(PodcastCreateViewModel createModel)
        {
            List <string> podcastTitlesFromDb = await _mediaWebDbContext.PodCasts.Select(p => p.Title).ToListAsync();

            if (podcastTitlesFromDb.Contains(StringEdits.FirstLettterToUpper(createModel.Title)))
            {
                return(RedirectToAction("Index"));
            }

            PodCast newPodcast = new PodCast()
            {
                Title       = StringEdits.FirstLettterToUpper(createModel.Title),
                ReleaseDate = createModel.ReleaseDate,
                Description = createModel.Description,
                File        = createModel.PodcastLink
            };

            //add guests to podcast
            var podcastGuests = new List <PodcastGuest>();

            //create only if new guests
            if (createModel.createdGuests != null)
            {
                var createdGuests      = StringEdits.FirstLettterToUpper(createModel.createdGuests);
                var createdGuestsArray = createdGuests.Split(", ");

                var newGuests    = new List <Guest>();
                var guestsFromDb = await _mediaWebDbContext.Guests.ToListAsync();

                foreach (var createdGuest in createdGuestsArray)
                {
                    if (!guestsFromDb.Select(g => g.Name).Contains(createdGuest))
                    {
                        newGuests.Add(new Guest()
                        {
                            Name = createdGuest
                        });
                    }
                    else
                    {
                        podcastGuests.Add(new PodcastGuest()
                        {
                            Guest = guestsFromDb.Find(g => g.Name == createdGuest)
                        });
                    }
                }

                foreach (var newGuest in newGuests)
                {
                    podcastGuests.Add(new PodcastGuest()
                    {
                        Guest = newGuest
                    });
                }
            }

            newPodcast.PodCastGuests = podcastGuests;

            //add hosts to podcast
            var podcastHosts = new List <PodcastHost>();

            //create only if new hosts
            if (createModel.createdHosts != null)
            {
                var createdHosts      = StringEdits.FirstLettterToUpper(createModel.createdHosts);
                var createdHostsArray = createdHosts.Split(", ");

                var newHosts    = new List <Host>();
                var hostsFromDb = await _mediaWebDbContext.Hosts.ToListAsync();

                foreach (var createdHost in createdHostsArray)
                {
                    if (!hostsFromDb.Select(g => g.Name).Contains(createdHost))
                    {
                        newHosts.Add(new Host()
                        {
                            Name = createdHost
                        });
                    }
                    else
                    {
                        podcastHosts.Add(new PodcastHost()
                        {
                            Host = hostsFromDb.Find(g => g.Name == createdHost)
                        });
                    }
                }

                foreach (var newHost in newHosts)
                {
                    podcastHosts.Add(new PodcastHost()
                    {
                        Host = newHost
                    });
                }
            }

            newPodcast.PodCastHosts = podcastHosts;

            _mediaWebDbContext.Update(newPodcast);
            await _mediaWebDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #9
0
        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"));
        }