public void EditPostTest() { SongEditViewModel model = new SongEditViewModel { Id = 1, ExistingPhotoPath = "TestPath", Artist = "TestArtist", SongName = "TestSongName", License = Dept.MasterLicense, Photo = null }; Song song = new Song { Id = 1, Artist = "TestArtist", SongName = "TestSong", License = Dept.MasterLicense, PhotoPath = "TestPhotoPath" }; var callToHosting = A.CallTo(() => hostingEnvironment.WebRootPath); callToHosting.Returns("FakePath"); var callToRepo = A.CallTo(() => songRepository.Update(song)); callToRepo.Returns(song); var callToSongRep = A.CallTo(() => songRepository.GetSong(1)); callToSongRep.Returns(song); A.CallTo(homeController).WithReturnType <string>().Returns("FakeUniueFileName"); homeController.Edit(model); }
public IActionResult Edit(SongEditViewModel model) { if (ModelState.IsValid) { Song song = _songRepository.GetSong(model.Id); song.Artist = model.Artist; song.SongName = model.SongName; song.License = model.License; string uniqueFileName = ProcessUploadedFile(model); if (model.Photo != null) { if (model.ExistingPhotoPath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath); System.IO.File.Delete(filePath); } song.PhotoPath = ProcessUploadedFile(model); } Song newSong = new Song { Artist = model.Artist, SongName = model.SongName, License = model.License, PhotoPath = uniqueFileName }; Song updatedSong = _songRepository.Update(song); return(RedirectToAction("index2")); } return(View()); }
public ActionResult Edit(SongEditViewModel viewModel) { var model = viewModel.EditedSong; // Note: name is allowed to be whitespace, but not empty. if (model.Names.All(n => string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Names", SongValidationErrors.UnspecifiedNames); } if (model.Lyrics.Any(n => string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Lyrics", "Lyrics cannot be empty"); } try { viewModel.CheckModel(); } catch (InvalidFormException x) { AddFormSubmissionError(x.Message); } if (!ModelState.IsValid) { return(View(new SongEditViewModel(Service.GetSong(model.Id), PermissionContext, model))); } queries.UpdateBasicProperties(model); return(RedirectToAction("Details", new { id = model.Id })); }
public ActionResult Edit(int id) { CheckConcurrentEdit(EntryType.Song, id); var model = new SongEditViewModel(Service.GetSong(id), PermissionContext); return(View(model)); }
public ViewResult Edit(int id) // public ViewResult Edit (int id) { Song song = _songRepository.GetSong(id); SongEditViewModel songEditViewModel = new SongEditViewModel { Id = song.Id, Artist = song.Artist, SongName = song.SongName, License = song.License, ExistingPhotoPath = song.PhotoPath }; return(View(songEditViewModel)); }
public async Task <IActionResult> Edit(int id, SongEditViewModel vm) { var origSong = await _applicationDbContext.Songs .Include(song => song.Album) .ThenInclude(album => album.Band) .FirstOrDefaultAsync(item => item.Id == id); origSong.Duration = vm.Duration; DotNetEnv.Env.Load(); origSong.SongLink = vm.Link.Replace(DotNetEnv.Env.GetString("YOUTUBE_LINK"), ""); if (origSong.NormalizedTitle != vm.SongTitle.ToUpper()) { origSong.Title = vm.SongTitle; origSong.NormalizedTitle = vm.SongTitle.ToUpper(); } if (origSong.Album?.NormalizedTitle != vm.AlbumTitle) { await _songService.ChangeAlbum(vm.AlbumTitle, origSong); origSong.Album.ReleaseDate = vm.ReleaseDate; } if (origSong.Album != null && !origSong.Album.ReleaseDate.HasValue) { origSong.Album.ReleaseDate = vm.ReleaseDate; } if (origSong.Album?.Band?.NormalizedName != vm.BandName) { await _songService.ChangeBand(vm.BandName, origSong); } if (vm.PhotoUrl != null && origSong.Album != null) { if (!String.IsNullOrEmpty(origSong.Album.PhotoUrl)) { _photoService.DeletePhoto(origSong.Album.PhotoUrl); } origSong.Album.PhotoUrl = _photoService.AddPhoto(vm.PhotoUrl); } await _applicationDbContext.SaveChangesAsync(); return(RedirectToAction("Detail", new { Id = id })); }
public async Task <ActionResult> Edit(SongEditViewModel viewModel) { // Unable to continue if viewmodel is null because we need the ID at least if (viewModel?.EditedSong == null) { s_log.Warn("Viewmodel was null"); return(HttpStatusCodeResult(HttpStatusCode.BadRequest, "Viewmodel was null - probably JavaScript is disabled")); } try { viewModel.CheckModel(); } catch (InvalidFormException x) { AddFormSubmissionError(x.Message); } var model = viewModel.EditedSong; // Note: name is allowed to be whitespace, but not empty. if (model.Names == null || model.Names.All(n => n == null || string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Names", SongValidationErrors.UnspecifiedNames); } if (model.Lyrics != null && model.Lyrics.Any(n => string.IsNullOrEmpty(n.Value))) { ModelState.AddModelError("Lyrics", "Lyrics cannot be empty"); } if (!ModelState.IsValid) { return(View(Service.GetSong(model.Id, song => new SongEditViewModel(new SongContract(song, PermissionContext.LanguagePreference, false), PermissionContext, EntryPermissionManager.CanDelete(PermissionContext, song), InstrumentalTagId, model)))); } await _queries.UpdateBasicProperties(model); return(RedirectToAction("Details", new { id = model.Id, albumId = viewModel.AlbumId })); }