public async Task <IActionResult> AddNewSong() { try { var albums = await unitOfWork.Albums.GetAllAsync(); var genres = await unitOfWork.Genres.GetAllAsync(); var vm = new CreateSongViewModel { Genres = genres.Select( g => new CheckBoxItem { Id = g.Id, Name = g.Name }).ToList() }; return(View(vm)); } catch (Exception ex) { logger.LogError(ex, "An error occurred while getting data."); } // ToDo: Implement error getting data return(View("ErrorGettingData")); }
public async Task <IActionResult> Edit(int id, CreateSongViewModel viewModel, int albumID) { viewModel.Song.AlbumID = albumID; if (id != viewModel.Song.SongID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(viewModel.Song); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SongExists(viewModel.Song.SongID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details), "Album", new { id = viewModel.Song.AlbumID })); } return(View(viewModel)); }
public async Task <IActionResult> AddNewSong(CreateSongViewModel vm) { try { if (!ModelState.IsValid) { return(View(vm)); } var selectedGenres = vm.Genres.Where(s => s.IsSelected); vm.Dto.GenresIds = await GetValidGenresIdsAsync(selectedGenres); var currentUserId = userManager.GetUserId(User); vm.Dto.OwenerId = currentUserId; await unitOfWork.Songs.AddAsync(vm.Dto); if (!await this.unitOfWork.SaveAsync()) { // ToDo: Implement error page return(View("ErrorSaving")); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { logger.LogError(ex, "An error occurred while deleting song."); } // ToDo: Implement error page return(View("ErrorSaving")); }
public ActionResult CreateSong() { var artistNames = this.artistService .GetArtists() .Select(x => x.Name) .OrderBy(x => x) .ToList(); var albumNames = this.albumService .GetAlbums() .Select(x => x.Title) .OrderBy(x => x) .ToList(); var genreNames = this.genreService .GetGenres() .Select(x => x.Name) .OrderBy(x => x) .ToList(); var model = new CreateSongViewModel() { AllArtists = artistNames, AllAlbums = albumNames, AllGenres = genreNames }; return(View(model)); }
// GET: Song/Create public IActionResult Create(int id) { CreateSongViewModel viewModel = new CreateSongViewModel(); viewModel.Song = new Song(); viewModel.AlbumID = id; return(View(viewModel)); }
public IActionResult Create(int artistID) { CreateSongViewModel model = new CreateSongViewModel(); model.song = new SongModel(); model.song.songArtistID = artistID; model.genreList = _mapper.Map <List <GenreModel> >(_genreService.GetAllGenres()); return(View(model)); }
public IActionResult Create(CreateSongViewModel model) { MusicCore.Song songCore = _mapper.Map <MusicCore.Song>(model.song); songCore.songArtistID = model.song.songArtistID; songCore.songGenreID = model.song.songGenreID; Boolean success = _songService.AddSong(songCore); return(RedirectToAction("Songs")); }
public ActionResult Create() { var albums = _db.Albums.ToList(); var vm = new CreateSongViewModel { Albums = albums }; return(View(vm)); }
public ActionResult CreateSong(CreateSongViewModel song) { if (song.VideoUrl.Contains(Watch)) { song.VideoUrl = song.VideoUrl.Replace(Watch, Embed); } this.createService.CreateSong(song.Title, song.Artist, song.Album, song.Duration, song.Genres, song.Lyrics, song.VideoUrl); return(RedirectToAction(CreationChoiceAction)); }
public async Task <IActionResult> Create(CreateSongViewModel model) { if (ModelState.IsValid) { var songCreate = await _songService.GetSongCreateByIdAsync(model.SongCreateId); if (songCreate.CreatedById != GetUserId() || songCreate.SongCreated) { return(RedirectToAction("InsufficientPermission", "Home")); } if (songCreate != null) { if (songCreate.SongCreated) { return(RedirectToAction("Library", "Index")); } songCreate.IsPublic = model.IsPublic.ToLower() == "yes" ? true : false; var songId = await _songService.CreateSongAsync(songCreate, GetUserId(), GetChurchId()); //Add related data to the newly created song, in this case, the composers and lyricists. var contributors = songCreate.Contributors.Select(c => new SongContributor { ContributorId = c.ContributorId, SongId = songId, Role = c.Role, CreatedById = GetUserId(), LastModifiedById = GetUserId(), DateCreated = DateTime.Now, DateLastModified = DateTime.Now }).ToList(); await _songService.AddSongContributorsAsync(contributors); await _libaryService.AddChurchSongAsync(GetChurchId(), songId, GetUserId()); await _songService.UpdateSongCreate_CreateSongTrueAsync(model.SongCreateId); //await _songEditionService.CreateSongEditionAsync(new SongEdition { // SongId = songId, // CreatedById = GetUserId(), // LastModifiedById = GetUserId(), // DateLastModified = DateTime.Now, // DateCreated = DateTime.Now, // IsDefault = true, // CreatedByChurchId = GetChurchId() //}); return(RedirectToAction("CreateSuccess", new { id = songId })); } } return(RedirectToAction("Error", "Home")); }
public void CallCreateServiceMethodCreateSong_WhenInvoked() { // Arrange var createService = new Mock <ICreationService>(); var artistService = new Mock <IArtistService>(); var albumService = new Mock <IAlbumService>(); var genreService = new Mock <IGenreService>(); createService.Setup(x => x.CreateSong( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <ICollection <string> >(), It.IsAny <string>(), It.IsAny <string>())); var sut = new CreateController( createService.Object, artistService.Object, albumService.Object, genreService.Object); var model = new CreateSongViewModel() { Title = "Title", Artist = "Artist", Album = "Album", Duration = 5, Genres = new List <string>() { "Genre" }, Lyrics = "Lyrics", VideoUrl = "VideoUrl", }; // Act sut.CreateSong(model); // Assert createService.Verify(x => x.CreateSong( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <ICollection <string> >(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public async Task <IActionResult> Create(CreateSongViewModel viewModel, int id) { viewModel.Song.Album = _context.Albums.FirstOrDefault(x => x.AlbumID == id); Album album = viewModel.Song.Album; if (ModelState.IsValid) { _context.Add(viewModel.Song); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), "Album", new { id })); } viewModel.Albums = new SelectList(_context.Albums, "AlbumID", "Title", viewModel.Song.AlbumID); return(View(viewModel)); }
public async Task <IActionResult> Edit(int id, CreateSongViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var success = await this.songService.EditAsync(id, model.Song); if (!success) { return(this.BadRequest()); } return(this.RedirectToAction(nameof(this.Index))); }
public ActionResult Create(Song song) { if (!ModelState.IsValid) { var vm = new CreateSongViewModel { Song = song, Albums = _db.Albums.ToList() }; //return the same page with error messages return(View(vm)); } //save to database _db.Songs.Add(song); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } CreateSongViewModel viewModel = new CreateSongViewModel(); viewModel.Song = await _context.Songs.FindAsync(id); viewModel.AlbumID = viewModel.Song.AlbumID; if (viewModel.Song == null) { return(NotFound()); } return(View(viewModel)); }
public async Task <IActionResult> Create(CreateSongViewModel songModel) { if (!this.ModelState.IsValid) { return(this.View(songModel)); } if (songModel == null) { return(this.BadRequest()); } var success = await this.songService.CreateAsync(songModel.Song); if (!success) { return(this.BadRequest()); } return(this.RedirectToAction(nameof(this.Index))); }