예제 #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 <IActionResult> Put([Required] string id, [FromBody] TagModel item)
        {
            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name);

                FanficDTO fanfic = await _fanficService.GetById(id);

                if (fanfic.ApplicationUserId == user.Id || await _authenticationManager.UserManager.IsInRoleAsync(user, "Admin"))
                {
                    TagDTO tag = _tagService.GetTagByName(item.tagName);
                    if (tag == null)
                    {
                        tag = await _tagService.Create(new TagDTO()
                        {
                            TagName = item.tagName, Uses = 1
                        });
                    }
                    await _fanficTagsService.Create(new FanficTagsDTO()
                    {
                        TagId = tag.Id, FanficId = id
                    });

                    return(Ok());
                }
            }
            return(BadRequest(ModelState));
        }
예제 #3
0
        public async Task <IActionResult> GetAsync([Required] string id)
        {
            FanficDTO fanfic = await _fanficService.GetById(id);

            if (fanfic == null)
            {
                return(NotFound());
            }

            return(Ok(await GetFanficModelFromDTO(fanfic)));
        }