public IActionResult Details(int id) { //var isSignedIn = this._signinManager.IsSignedIn(HttpContext.User); //var currentUserId = this._signinManager.UserManager.GetUserId(HttpContext.User); //if (isSignedIn) //{ // _currentMediaUser = _mediaService.GetAllMediaUseren().First(p => p.Id == currentUserId); //} Podcast selectedPodcast = _mediaService.GetAllPodcasts().FirstOrDefault(x => x.Id == id); var UserRatingList = _mediaService.GetAllRatings().Where(pod => pod.Media.Id == selectedPodcast.Id); Podcast podcast = _mediaService.GetAllPodcasts().First(x => x.Id == id); var media = _mediaService.GetAllMedia().First(med => med.Titel == podcast.Titel); PodcastDetailViewModel vm = new PodcastDetailViewModel() { MediaId = id, Name = podcast.Name, Photo = podcast.Photo, PodcastLink = podcast.ConversationMP3, IsRated = UserRatingList.Count() > 0? true :false, IsSignedIn = false//currentUserId == null ? false : true, }; vm.AveragePoints = selectedPodcast.Ratings.Count() > 0 ? selectedPodcast.Ratings.Average(r => r.Points) : 0; vm.PlayLists = new List <PlayList>(); if (_currentMediaUser != null) { vm.PlayLists = _currentMediaUser.Playlists.ToList(); } return(View(vm)); }
public IActionResult Details(int id) { var isSignedIn = this._signInManager.IsSignedIn(HttpContext.User); var currentUserId = this._signInManager.UserManager.GetUserId(HttpContext.User); if (isSignedIn) { _currentMediaUser = _mediaService.GetAllMediaUsers().First(p => p.Id == currentUserId); } var episode = _mediaService.GetAllEpisodes().FirstOrDefault(epi => epi.Id == id); var isRated = false; var playLists = new List <PlayList>(); var AveragePoints = 0.0; if (_currentMediaUser != null) { isRated = _mediaService.GetAllRatings().Where(epi => epi.Media.Id == epi.Id && epi.MediaUser.Id == _currentMediaUser.Id).Any(); playLists = _currentMediaUser.Playlists.ToList(); } var points = _mediaService.GetAllRatings().Where(epi => epi.Media.Id == epi.Id).Average(epi => epi.Points); AveragePoints = _mediaService.GetAllRatings().Where(epi => epi.Media.Id == epi.Id).Average(epi => epi.Points); EpisodeDetailViewModel model = new EpisodeDetailViewModel() { MediaId = episode.Id, SeasonNr = episode.Season.SeasonNr, Description = episode.Description, Duration = episode.Duration, Photo = episode.Photo, ReleaseDate = episode.ReleaseDate, IMDBLink = episode.IMDBLink, Titel = episode.Titel, IsRated = isRated, IsSignedIn = isSignedIn, PlayLists = playLists, AveragePoints = AveragePoints }; return(View(model)); }
public IActionResult Details(int id) { var currentUserId = this._signInManager.UserManager.GetUserId(HttpContext.User); _currentMediaUser = _mediaService.GetAllMediaUsers().First(p => p.Id == currentUserId); Music selectedMusic = _mediaService.GetAllMedia().OfType <Music>().Where(muz => muz.Id == id).FirstOrDefault(); List <Rating> UserRatingList = new List <Rating>(); bool isAlreadyRated = false; var playlists = new List <PlayList>(); if (_currentMediaUser != null) { isAlreadyRated = _mediaService.GetAllRatings().Where(movie => movie.Media.Titel == selectedMusic.Titel).Where(user => user.MediaUser.Id == _currentMediaUser.Id).Any(); playlists = _currentMediaUser.Playlists.ToList(); } UserRatingList = _mediaService.GetAllRatings().Where(music => music.Media.Id == selectedMusic.Id).ToList(); var detailViewModel = new MusicDetailViewModel() { MediaId = selectedMusic.Id, Lied = selectedMusic.Lied, Titel = selectedMusic.Titel, ZangersName = selectedMusic.ZangersName, Photo = selectedMusic.Photo, IsRated = isAlreadyRated, PlayLists = playlists, IsSignedIn = true }; if (selectedMusic.Ratings.Count() > 0) { detailViewModel.AveragePoints = selectedMusic.Ratings.Where(med => med.Media.Id == selectedMusic.Id) != null?selectedMusic.Ratings.Where(med => med.Media.Id == selectedMusic.Id).Average(r => r.Points) : 0; } if (_currentMediaUser != null) { detailViewModel.PlayLists = _currentMediaUser.Playlists.ToList(); } return(View(detailViewModel)); }
public IActionResult Details(int Id) { // var isSignedIn = this._signinManager.IsSignedIn(HttpContext.User); var currentUserId = this._signInManager.UserManager.GetUserId(HttpContext.User); _currentMediaUser = _mediaService.GetAllMediaUsers().First(p => p.Id == currentUserId); Movie selectedMovie = _mediaService.GetAllMedia().OfType <Movie>().FirstOrDefault(mov => mov.Id == Id); bool isAlreadyRatedByCurrentUser = false; var playlists = new List <PlayList>(); if (_currentMediaUser != null) { var allratings = _mediaService.GetAllRatings().Where(media => media.Id == selectedMovie.Id); isAlreadyRatedByCurrentUser = allratings.Where(media => media.MediaUser.Id == _currentMediaUser.Id).Any(); playlists = _currentMediaUser.Playlists.ToList(); } MovieDetailViewModel model = new MovieDetailViewModel() { MediaId = selectedMovie.Id, Titel = selectedMovie.Titel, Photo = selectedMovie.Photo, Duration = selectedMovie.Duration, IMDBLink = selectedMovie.IMDBLink, Status = selectedMovie.Status, PlayLists = playlists, AveragePoints = selectedMovie.Ratings.Count() > 0 ? selectedMovie.Ratings.Average(r => r.Points) : 0, IsRated = isAlreadyRatedByCurrentUser, AddedByUserName = selectedMovie.MediaUser.UserName, Ratings = selectedMovie.Ratings.ToList(), Reviews = selectedMovie.Ratings.Select(r => r.Review).ToList() }; return(View(model)); }