public async Task Create(TVShowsCreateModel input) { var tvshow = new TVShow() { ImageUrl = input.ImageUrl, Title = input.Title, Year = input.Year, Description = input.Description, HomePageLink = input.HomePageLink, IMDBLink = input.IMDBLink, TrailerLink = input.TrailerLink, FacebookLink = input.FacebookLink, Creater = input.Creater, Producer = input.Producer, Country = input.Country, Seasons = input.Seasons, ReleaseDate = input.ReleaseDate, EndDate = input.EndDate, }; var tvshowGenre = this.genresRepository .All() .FirstOrDefault(x => x.Id == input.GenreId); tvshow.Genres.Add(tvshowGenre); await this.tvshowRepository.AddAsync(tvshow); await this.tvshowRepository.SaveChangesAsync(); }
public IActionResult Create() { var genres = this.tvshowsService.GetAllGenres <GenreViewModel>(); var viewModel = new TVShowsCreateModel { Genres = genres, }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(TVShowsCreateModel input) { var tvshow = AutoMapperConfig.MapperInstance.Map <TVShow>(input); if (!this.ModelState.IsValid) { return(this.View(input)); } await this.tvshowsService.Create(input); return(this.RedirectToAction(nameof(this.TVShowView), new { title = input.Title })); }
public async Task Create_WithInvalidInput_ShouldThrowException() { var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext(); await this.SeedData(dbContext); var tvshowRepository = new EfDeletableEntityRepository <TVShow>(dbContext); var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext); var service = new TVShowsService(tvshowRepository, genresRepository); var input = new TVShowsCreateModel() { }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.Create(input)); }
public async Task Create_WithValidInput_ShouldReturnValidResult() { var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext(); await this.SeedData(dbContext); var tvshowRepository = new EfDeletableEntityRepository <TVShow>(dbContext); var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext); var service = new TVShowsService(tvshowRepository, genresRepository); var input = new TVShowsCreateModel() { Title = "Titanic", Country = "USA", GenreId = 1, }; var movie = service.Create(input); var result = service.GetByTitle <TVShowViewModel>("Titanic"); Assert.Equal("USA", result.Country); }