public async Task <IActionResult> CreateChapterForFanfic([Required] string id, [FromBody] ChapterModel item) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name); FanficDTO fanfic = await _fanficService.GetById(id); if (fanfic == null) { return(NotFound()); } if (fanfic.ApplicationUserId == user.Id || await _authenticationManager.UserManager.IsInRoleAsync(user, "Admin")) { ChapterDTO newChapter = _mapper.Map <ChapterModel, ChapterDTO>(item); newChapter.Id = null; newChapter.FanficId = id; newChapter = await _chapterService.Create(newChapter); return(Ok(_mapper.Map <ChapterDTO, ChapterModel>(newChapter))); } } return(BadRequest(ModelState)); }
public async Task <IActionResult> DeleteChapterFromFanfic([Required] string id) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name); ChapterDTO chapter = await _chapterService.GetById(id); FanficDTO fanfic = await _fanficService.GetById(chapter.FanficId); if (fanfic == null) { return(NotFound()); } if (fanfic.ApplicationUserId == user.Id || await _authenticationManager.UserManager.IsInRoleAsync(user, "Admin")) { await DeleteChapterRatings(id); ChapterDTO deletedChapter = await _chapterService.Delete(id); return(Ok(_mapper.Map <ChapterDTO, ChapterModel>(deletedChapter))); } } return(BadRequest(ModelState)); }
public ChapterVM(ChapterDTO row) { Id = row.Id; Name = row.Name; Description = row.Description; ChapterPath = row.ChapterPath; }
private void UpdateChapterLikes(int chapterId) { ChapterDTO chapter = _fabric.CreateChaptersRepository().Get(chapterId).ToModel(); chapter.LikesCounter = chapter.Likes.Count; _fabric.CreateChaptersRepository().Update(chapter.ToEntity()); }
public IActionResult Edit(int id, string newName, string editedText) { ChapterDTO chapter = _chapterService.Get(id); chapter.Name = newName; chapter.Text = editedText; _chapterService.Update(chapter); return(RedirectToAction("Details", "Chapter", new { chapterId = id })); }
public bool UpdateChapter(Guid userId, ChapterDTO chapter) { Chapter c = chapterRepository.Get(chapter.Id); if (c == null) { return(false); } c.Name = chapter.Name; return(chapterRepository.UpdateChapter(c)); }
public ActionResult <ChapterDTO> GetFirstChapter(int bookId) { var chapter = _context.Chapters.AsNoTracking() .Include(x => x.NavigationChapters) .ThenInclude(x => x.ToNavigateChapter) .FirstOrDefault(x => x.Book_Id == bookId && x.Number == 1); ChapterDTO chapterDto = chapter.Map(); return(chapterDto); }
public async Task CreateChapter(ChapterDTO chapterDto) { if (chapterDto == null) { throw new ArgumentNullException("Input cannot be empty"); } Chapter chapter = Mapper.Map <ChapterDTO, Chapter>(chapterDto); _database.Chapters.Create(chapter); await _database.SaveAsync(); }
public void ChangeChapterNumber(ChapterDTO chapter, int newNumber) { FanficDTO fanfic = chapter.Fanfic; List <ChapterDTO> chapters = fanfic.Chapters; ChapterDTO chapterToSwapWith = chapters.FirstOrDefault(c => c.ChapterNumber == newNumber); chapterToSwapWith.ChapterNumber = chapter.ChapterNumber; chapter.ChapterNumber = newNumber; Update(chapter); Update(chapterToSwapWith); }
public ChapterDTO GetChapter(string chapterName) { Chapter chapter = _database.Chapters.GetOne(x => x.Name == chapterName); if (chapter == null) { throw new ArgumentNullException($"Chapter with such name does not exist. Name: {chapterName}"); } ChapterDTO chapterDto = Mapper.Map <Chapter, ChapterDTO>(chapter); return(chapterDto); }
public static Chapter ToEntity(this ChapterDTO chapter) { var entityChapter = new Chapter { Id = chapter.Id, Name = chapter.Name, ChapterNumber = chapter.ChapterNumber, FanficId = chapter.Fanfic.Id, LikesCounter = chapter.LikesCounter, Text = chapter.Text, Image = chapter.Image }; return(entityChapter); }
public string CreateChapter(ChapterDTO chapter) { if (chapter.Id == null) { return(""); } Chapter newChapter = new Chapter { Id = Guid.NewGuid(), CourseId = chapter.Id, Index = chapterRepository.CurrentIndex(chapter.Id) + 1, Name = chapter.Name }; return(chapterRepository.CreateChapter(newChapter) ? newChapter.Id.ToString() : ""); }
public async Task EditChapter(ChapterDTO chapterDto) { Chapter checkChapter = _database.Chapters.GetOne(x => x.Id == chapterDto.Id); if (checkChapter == null) { throw new ArgumentNullException("Chapter does not exist"); } chapterDto.Id = checkChapter.Id; Chapter chapter = Mapper.Map <ChapterDTO, Chapter>(chapterDto); _database.Chapters.Update(chapter); await _database.SaveAsync(); }
public static ChapterDTO Map(this Chapter chapter) { var chapterDTO = new ChapterDTO() { BookId = chapter.Book_Id, Id = chapter.Id, Number = chapter.Number, Description = chapter.Description, NavigationChapters = chapter?.NavigationChapters.Select(x => new NavigationChapterDTO() { ChapterId = x.ToNavigateChapterId, Number = x.ToNavigateChapter.Number }).ToList() }; return(chapterDTO); }
public IHttpActionResult addChapter(string mangaId, int chapterNumber, string chapterName) { ChapterDTO chapter = new ChapterDTO(); chapter.chapterName = chapterName; chapter.mangaId = mangaId; chapter.chapterNumber = chapterNumber; if (!chapterService.addChapter(chapter)) { return(NotFound()); } else { return(Ok("Success")); } }
public ActionResult <Priority> PostChapter(ChapterDTO chapter) { // Priority priority = _chapterRepository.getPriorityById(chapter.Priority.Id); // Theme theme = _chapterRepository.getThemeById(chapter.Theme.Id); Chapter newChapter = new Chapter() { Title = chapter.Title, Priority = chapter.Priority == null ? null : _chapterRepository.getPriorityById(chapter.Priority.Id), Theme = chapter.Theme == null ? null : _chapterRepository.getThemeById(chapter.Theme.Id), Date = chapter.Date }; _chapterRepository.Add(newChapter); _chapterRepository.SaveChanges(); return(CreatedAtAction(nameof(GetAllChaptersByThemeOrPriority), new { id = newChapter.Id }, newChapter)); }
public bool addChapter(ChapterDTO chapter) { Chapter ch = new Chapter(); ch.chapterId = chapter.chapterId; ch.chapterNumber = chapter.chapterNumber; ch.chapterName = chapter.chapterName; ch.mangaId = chapter.mangaId; try { db.Chapters.Add(ch); db.SaveChanges(); return(true); } catch { return(false); } }
public bool updateChapter(ChapterDTO chapter) { Chapter ch = db.Chapters.Where(x => x.chapterId.Equals(chapter.chapterId)).SingleOrDefault(); if (ch == null) { return(false); } else { ch.chapterName = chapter.chapterName; ch.mangaId = chapter.mangaId; try { db.SaveChanges(); return(true); } catch { return(false); } } }
public IActionResult Put(string id, [FromBody] ChapterDTO book) { _work.Chapters.Update(id, book); return(NoContent()); }
public ActionResult AddChapter(ChapterVM model, HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(model)); } using (Db db = new Db()) { if (db.Chapters .Any(x => x.Name == model.Name)) { ModelState .AddModelError("", "The chapter already exists!"); return(View(model)); } } int id = 0; using (Db db = new Db()) { ChapterDTO chapter = new ChapterDTO(); chapter.Name = model.Name; chapter.Description = model.Description; db.Chapters.Add(chapter); db.SaveChanges(); id = chapter.Id; } #region Create Chapter DirectoryInfo originalDirectory = new DirectoryInfo(string.Format("{0}Courses\\", Server.MapPath("~/"))); CourseDTO course; using (Db db = new Db()) { ChaptersForCoursesDTO dto = new ChaptersForCoursesDTO() { CourseId = ShopController.getCourseId(id), ChapterId = id }; course = db.Courses .Find(ShopController.getCourseId(id)); db.ChaptersForCourses.Add(dto); db.SaveChanges(); } string pathString = Path .Combine(originalDirectory.ToString() + "\\" + course.Name); string pathString2 = Path .Combine(pathString + "\\" + "Chapters"); int chaptersCount = 0; using (Db db = new Db()) { chaptersCount = db .ChaptersForCourses .Where(x => x.CourseId == ShopController.getCourseId(id)) .Count(); } string pathString3 = Path .Combine(pathString2 + "\\" + string.Format( "Chapter " + chaptersCount.ToString() + " - " + model.Name)); if (Directory.Exists(pathString3)) { Directory.CreateDirectory(pathString3); } #endregion TempData["SM"] = "You have added a new chapter!"; return(RedirectToAction("AddChapter")); }
public IActionResult Edit(int chapterId) { ChapterDTO chapter = _chapterService.Get(chapterId); return(View(chapter)); }
public void Delete(ChapterDTO chapter) { int fanficId = chapter.Fanfic.Id; _fabric.CreateChaptersRepository().Delete(chapter.ToEntity()); }
public void Update(ChapterDTO chapter) { _fabric.CreateChaptersRepository().Update(chapter.ToEntity()); }
public async Task <ChapterDTO> Update(ChapterDTO item) { Chapter chapter = await _database.ChapterRepository.Update(_mapper.Map <ChapterDTO, Chapter>(item)); return(_mapper.Map <Chapter, ChapterDTO>(chapter)); }