public async Task AddEpisodeAsync(AddEpisodeInputModel input, string webRootPath) { var webtoon = this.webtoonsRepository.GetWebtoonByTitleNumber(input.TitleNumber); webtoon.Episodes = this.episodesRepository.GetEpisodesByWebtoonId(webtoon.Id); var episodesCount = webtoon.Episodes.Count + 1; string episodeName = "Episode" + episodesCount; string topFolder = $@"{webRootPath}\Webtoons\{webtoon.Title}"; string episodeFolder = Path.Combine(topFolder, episodeName); Directory.CreateDirectory(episodeFolder); var episode = new Episode { Name = episodeName, WebtoonId = webtoon.Id, IsDeleted = false, CreatedOn = DateTime.UtcNow, EpisodeNumber = episodesCount.ToString(), }; episode.Pages = this.pagesService.AddPagesAsync(input.Pages, episodeFolder, episode.Id).Result; await this.episodesRepository.AddAsync(episode); await this.episodesRepository.SaveChangesAsync(); }
public async Task <IActionResult> AddEpisodeAsync(AddEpisodeInputModel input) { var webRootPath = this.webHostEnvironment.WebRootPath; await this.episodesService.AddEpisodeAsync(input, webRootPath); return(this.Redirect("/")); }
public IActionResult AddEpisode(string webtoonTitleNumber) { var input = new AddEpisodeInputModel { TitleNumber = webtoonTitleNumber, }; return(this.View(input)); }
public async Task AddEpisodeAsyncWorksCorrectly() { var mockWebtoonsRepo = new Mock <IWebtoonsRepository>(); var webtoon = new Webtoon() { Title = "test", Id = "gosho", TitleNumber = "123", AuthorId = "test", Episodes = new List <Episode>() }; mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon); var episodes = new List <Episode>(); var mockEpisodesRepo = new Mock <IEpisodesRepository>(); mockEpisodesRepo.Setup(x => x.GetEpisodesByWebtoonId("gosho")).Returns(episodes); mockEpisodesRepo.Setup(x => x.AddAsync(It.IsAny <Episode>())).Callback((Episode episode) => episodes.Add(episode)); var pages = new List <Page>(); var mockPageService = new Mock <IPagesService>(); var episodeInputModel = new AddEpisodeInputModel() { Pages = new List <IFormFile>(), TitleNumber = "123" }; var pathToTestResults = $@"C:\MyWebtoonWebProject\MyWebtoonWebProject\TestResults"; var service = new EpisodesService(mockWebtoonsRepo.Object, mockEpisodesRepo.Object, null, mockPageService.Object, null, null, null, null); await service.AddEpisodeAsync(episodeInputModel, pathToTestResults); Assert.Single(episodes); Assert.Equal(0, episodes.First().Comments.Count); Assert.Equal(0, episodes.First().EpisodeLikes.Count); Assert.Equal("1", episodes.First().EpisodeNumber); Assert.False(episodes.First().IsDeleted); Assert.Equal("Episode1", episodes.First().Name); Assert.Equal("gosho", episodes.First().WebtoonId); }