private void CheckActorForDuplication(EditActorBindingModel model) { if (this.Data.Actors.All().Any(a => a.Name == model.Name && a.Id != model.Id)) { throw new InvalidOperationException($"There is already actor with name {model.Name}"); } }
public void EditActor(EditActorBindingModel model) { this.CheckModelForNull(model); this.CheckActorForDuplication(model); var actor = this.GetActorById(model.Id); Mapper.Map(model, actor); this.Data.SaveChanges(); }
public void EditActorView_ShouldEditIt_() { var fakeUser = this.mocks.UserRepositoryMock.Object.All().FirstOrDefault(u => u.Id == "12345"); var fakeGenres = this.mocks.GenreRepositoryMock.Object.All().ToList(); var fakeActor = this.mocks.ActorRepositoryMock.Object.All().FirstOrDefault(a => a.Id == 1); fakeActor.Movies = new List <Movie>() { new Movie() { Id = 1, Name = "Test Movie 1", Country = "Test Country 1", Description = "Test Test Test Test Test Test Test", Price = 9.99m, DurationInMinutes = 120, Poster = "Test Poster", Trailer = "Test Trailer", Genres = fakeGenres }, new Movie() { Id = 2, Name = "Test Movie 2", Country = "Test Country 2", Description = "Test Test Test Test Test Test Test", Price = 9.99m, DurationInMinutes = 120, Poster = "Test Poster", Trailer = "Test Trailer", Genres = fakeGenres }, }; this.CheckUserCredentials(fakeUser); var editActorBm = new EditActorBindingModel() { Id = 1, Name = "Edited Name", Photo = "Photo", IMDBProfile = "Profile" }; this.controller.WithCallTo(c => c.Edit(editActorBm)).ShouldRedirectToRoute(""); this.controller.WithCallTo(c => c.Edit(1)).ShouldRenderDefaultView() .WithModel <ActorViewModel>(a => a.Id == 1 && a.Name == "Edited Name" && a.Photo == "Photo" && a.IMDBProfile == "Profile"); }
public ActionResult Edit(EditActorBindingModel model) { if (this.ModelState.IsValid) { try { this.actorsService.EditActor(model); this.AddNotification("Edited successfully", NotificationType.SUCCESS); return(RedirectToAction("Index", "Actors", new { Area = "" })); } catch (Exception ex) { this.AddNotification(ex.Message, NotificationType.ERROR); return(this.View()); } } return(View()); }