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 CreateNew_ValidData_ShouldReturnTrue() { var chapter = new NewChapterDto { ChapterNumber = 6, Contents = "CreateNew_ValidData_ShouldReturnTrue", IsPublished = false, NovelId = 1, Title = "CreateNew_ValidData_ShouldReturnTrue" }; var result = await _chapterService.Create(chapter); var novelChapters = await _chapterService.ByNovelId(1); var chapterFromDb = novelChapters.FirstOrDefault(m => m.Title == "CreateNew_ValidData_ShouldReturnTrue"); Assert.IsTrue(result.IsSuccess); Assert.IsNotNull(chapterFromDb); }
public IActionResult Create([FromBody] CreateChapterModel model) { // map model to entity var chapter = _mapper.Map <Chapter>(model); try { // create chapter _chapterService.Create(chapter); return(Ok(new { data = chapter, message = "Successfully created chapter." })); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IActionResult Create([FromBody] CreateChapterDto chapterDto) { try { var chapterEntity = _chapterService.Create(_mapper.Map <Chapter>(chapterDto)); var responseDto = _mapper.Map <CreateChapterResponseDto>(chapterEntity); return(Ok(responseDto)); } catch (UnauthorizedAccessException ex) { return(Unauthorized(new ErrorResponseDto { InternalErrorMessage = ex.Message, DisplayErrorMessage = "User is not authorized to execute the given request.", })); } catch (Exception ex) { return(BadRequest(new ErrorResponseDto(ex))); } }
public BaseResponse <ChapterDetailOutputDto> Create([FromBody] ChapterInputDto chapterInputDto) { return(_chapterService.Create(chapterInputDto)); }
public IActionResult AddChapter(string name, string text, int fanficId) { _chapterService.Create(name, text, fanficId, null); return(RedirectToAction("Read", "Fanfic", new { id = fanficId })); }
public async Task <IActionResult> Post([FromBody] NewChapterDto data) { var result = await _chapterService.Create(data); return(new JsonResult(result)); }