コード例 #1
0
        private async Task <FanficDTO> GetFanficDTO(CreateFanfic item)
        {
            ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name);

            return(new FanficDTO()
            {
                Title = item.title,
                Description = item.description,
                ApplicationUserId = user.Id,
                PictureURL = item.pictureUrl,
                GenreId = _genreService.GetByName(item.genre).Id,
                DateOfCreation = DateTime.Now,
                LastModifyingDate = DateTime.Now
            });
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] CreateFanfic item)
        {
            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                if (_fanficService.CheckUniqueName(item.title))
                {
                    FanficDTO fanfic = await GetFanficDTO(item);

                    fanfic = await _fanficService.Create(fanfic);
                    await CreateTags(item.tags.ToList(), fanfic.Id);

                    return(Ok(fanfic.Id));
                }
                return(BadRequest("title is already exists"));
            }
            return(BadRequest(ModelState));
        }