Пример #1
0
        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));
        }
Пример #2
0
        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 }));
            }
        }
Пример #4
0
        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)));
            }
        }
Пример #5
0
 public BaseResponse <ChapterDetailOutputDto> Create([FromBody] ChapterInputDto chapterInputDto)
 {
     return(_chapterService.Create(chapterInputDto));
 }
Пример #6
0
 public IActionResult AddChapter(string name, string text, int fanficId)
 {
     _chapterService.Create(name, text, fanficId, null);
     return(RedirectToAction("Read", "Fanfic", new { id = fanficId }));
 }
Пример #7
0
        public async Task <IActionResult> Post([FromBody] NewChapterDto data)
        {
            var result = await _chapterService.Create(data);

            return(new JsonResult(result));
        }