Esempio n. 1
0
        public IActionResult CreateChapter(int id)
        {
            Manga manga = _mangaRepository.GetManga(id);

            if (manga == null)
            {
                return(View("404Error"));
            }

            MangaChapterCreateViewModel model = new MangaChapterCreateViewModel();

            model.Manga = manga;
            var chapterList = _mangaRepository.GetAllChapters(id);

            if (chapterList.Count() == 0)
            {
                model.ChapterNo = 1;
            }
            else
            {
                model.ChapterNo = chapterList.Max(c => c.ChapterNo) + 1;
            }

            return(View(model));
        }
Esempio n. 2
0
        public IActionResult CreateChapter(int id, MangaChapterCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Files != null && model.Files.Count > 0)
                {
                    foreach (IFormFile file in model.Files)
                    {
                        string uploadsFolder =
                            Path.Combine(_hostingEnvironment.WebRootPath, "Mangas");
                        string filePath =
                            Path.Combine(uploadsFolder,
                                         id.ToString(),
                                         model.ChapterNo.ToString());
                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }

                        string fullPath =
                            Path.Combine(filePath, file.FileName);
                        file.CopyTo(new FileStream(fullPath, FileMode.Create));
                    }
                }

                MangaChapter newChapter = new MangaChapter()
                {
                    ChapterNo = model.ChapterNo,
                    MangaId   = id,
                    Title     = model.Title,
                    ChFolder  =
                        Path.Combine(_hostingEnvironment.WebRootPath,
                                     "Mangas",
                                     id.ToString(),
                                     model.ChapterNo.ToString())
                };
                _mangaRepository.AddChapter(newChapter);
                return(RedirectToAction("Chapters", new { id = id }));
            }

            return(View(model));
        }