Esempio n. 1
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));
        }
Esempio n. 2
0
        private async Task CreateTag(string tagName, string fanficId)
        {
            TagDTO tag = _tagService.GetTagByName(tagName);

            if (tag == null)
            {
                tag = await _tagService.Create(new TagDTO()
                {
                    TagName = tagName, Uses = 1
                });
            }
            await _fanficTagsService.Create(new FanficTagsDTO()
            {
                TagId = tag.Id, FanficId = fanficId
            });

            return;
        }