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")); }
public async Task<IActionResult> Create(PlaylistCreateViewModel playlistCreateViewModel, CancellationToken ct) { if (ModelState.IsValid) { playlistCreateViewModel.OwnerId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); var playlistCreateDto = _mapper.Map<PlaylistCreateDto>(playlistCreateViewModel); await _playlistService.CreatePlaylist(playlistCreateDto, ct); return RedirectToAction("Index", "Home"); } return View(); }
public async Task <IActionResult> CreatePlayList() { PlaylistCreateViewModel createModel = new PlaylistCreateViewModel(); var songs = await _mediaWebDbContext.Songs.Select(song => new SelectListItem() { Value = song.Id.ToString(), Text = song.Title }).ToListAsync(); createModel.Songs = songs; return(View(createModel)); }