public IActionResult Create([Bind("Id,Name")] Genre genre) { if (ModelState.IsValid) { _genreRepository.Add(genre); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task Should_add_new_item(Genre genre) { genre.GenreId = Guid.NewGuid(); var sut = new GenreRepository(_factory.ContextInstance); sut.Add(genre); await sut.UnitOfWork.SaveEntitiesAsync(); _factory.ContextInstance.Genres .FirstOrDefault(x => x.GenreId == genre.GenreId) .ShouldNotBeNull(); }
public void Add_Genre_AddGenreToDatabase() { var genre = new Genre { Id = Guid.NewGuid() }; _genreRepository.Add(genre); var genres = _context.Genres.ToList(); Assert.IsTrue(genres.Contains(genre)); }
public async Task should_add_new_item(Genre request) { request.GenreId = Guid.NewGuid(); var sut = new GenreRepository(_testDataContextFactory.ContextInstance); sut.Add(request); await sut.UnitOfWork.SaveEntitiesAsync(); _testDataContextFactory.ContextInstance.Genres .FirstOrDefault(x => x.GenreId == request.GenreId) .ShouldNotBeNull(); }
public ActionResult Index([Bind(Include = "Id,genreName")] Genre genre) { if (ModelState.IsValid) { db.Add(genre); return(RedirectToAction("Index")); } return(View(new GenreCreateList() { Genre = genre, ExistingGenres = db.GetAll() })); }
public Genre Add(Genre genre) { var result = _genreRepository.Add(new GenreDto() { Id = genre.Id, Name = genre.Name }); return(new Genre() { Id = result.Id, Name = result.Name }); }
public async Task should_add_new_item(object jsonPayload) { var genre = JsonConvert.DeserializeObject <Genre>(jsonPayload.ToString()); genre.GenreId = Guid.NewGuid(); var sut = new GenreRepository(_testDataContextFactory.ContextInstance); sut.Add(genre); await sut.UnitOfWork.SaveEntitiesAsync(); _testDataContextFactory.ContextInstance.Genres .FirstOrDefault(x => x.GenreId == genre.GenreId) .ShouldNotBeNull(); }
private GenreRepository ReadGenres(XElement xmlElement, XNamespace xmlNamespace) { GenreRepository genreRepository = new GenreRepository(); IEnumerable <Genre> genres = from genre in xmlElement.Descendants(xmlNamespace + MusicXmlConstants.GENRE_NODE) select new Genre() { Id = genre.Attribute(MusicXmlConstants.GENRE_ID).Value, Name = genre.Attribute(MusicXmlConstants.GENRE_NAME).Value }; foreach (Genre genre in genres) { genreRepository.Add(genre); } return(genreRepository); }
public void Test_Add_ListAll() { Genre genre = new Genre() { Id = 1, Name = "Anime", }; GenreRepository repository = new GenreRepository(); int numberOfGenres = repository.GetAll().Count(); Genre result = repository.Add(genre); Assert.NotNull(result); int finalNumberOfGenres = repository.GetAll().Count(); Assert.AreEqual(numberOfGenres + 1, finalNumberOfGenres); }
public ActionResult Create(Genre genre) { if (ModelState.IsValid) { try { UpdateModel(genre); genreRepo.Add(genre); genreRepo.Save(); return(RedirectToAction("Index")); } catch { ModelState.AddRuleViolations(genre.GetRuleViolations()); } } return(View(genre)); }
static void GetImportedMovies() { //import movies from json file: importedmovies.json var importedmovies = _movieRepository.GetImportedMovies(); var movies = _movieRepository.Get(); //importedmovies.json file / movies.json file is needed to show movies if (!importedmovies.Any() && !movies.Any()) { Console.WriteLine("The file: importedmovies.json is needed for import. Please add it to folder: User\\Documents\\Project\\Movies\\Movies\\bin\\Debug"); } else { if (!movies.Any()) { Console.WriteLine($"Importing movies from external file..."); foreach (var importedmovie in importedmovies) { //----for each movie in importedmovie.json add list of cast and genre ------- //------------- Cast - start ------------------------------- var newListCast = new List <Cast>(); var cast = importedmovie.Cast; //--------- loop thru cast in string array format from importedmovies.json //--------- to create List of Cast to be inserted into Movies.json ------- foreach (String c in cast) { //----- create new cast for one movie ------- var newCast = new Cast { Name = c }; int newCastId = _castRepository.Add(newCast); newCast = _castRepository.Get(newCastId); // Get new cast along with id newListCast.Add(newCast); //Add to Cast List collection //Console.WriteLine($"New Cast Id: {newCastId} {c}"); //----- create new cast for one movie ------- } //------------- Cast - End --------------------------------- //------------- Genres - start ------------------------------- var newListGenres = new List <Genre>(); var genre = importedmovie.Genres; foreach (String g in genre) { //----- create new cast for one movie ------- var newGenre = new Genre { Category = g }; int newGenreId = _genreRepository.Add(newGenre); newGenre = _genreRepository.Get(newGenreId); // Get new cast along with id newListGenres.Add(newGenre); //Add to Cast List collection //Console.WriteLine($"New Genre Id: {newGenreId} {g}"); //----- create new cast for one movie ------- } //------------- Genres - End ------------------------------- //------------- Add Movie start ---------------------- var newMovie = new Movie() { Title = importedmovie.Title, Year = importedmovie.Year, Cast = newListCast, //includes List of casts Genre = newListGenres //includes List of genres }; int newMovieId = _movieRepository.Add(newMovie); //------------- Add Movie end------------------------- Console.WriteLine($"Movie: {newMovieId} {importedmovie.Title}, {importedmovie.Year}"); newMovie = _movieRepository.Get(newMovieId); } } } Clear(); }
public IActionResult Post(Genre genre) { _genreRepository.Add(genre); return(CreatedAtAction(nameof(Get), new { id = genre.Id }, genre)); }