示例#1
0
        private async Task <List <string> > GetFanficTags(string fanficId)
        {
            List <FanficTagsDTO> items = _fanficTagsService.GetFanficTagsByFanficId(fanficId).ToList();

            if (items == null)
            {
                return(new List <string>());
            }

            List <TagDTO> tags = new List <TagDTO>();

            foreach (var fanficTag in items)
            {
                tags.Add(await _tagService.GetById(fanficTag.TagId));
            }
            return(GetFanficTags(tags));
        }
示例#2
0
        public async Task <IActionResult> Delete([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)
                    {
                        FanficTagsDTO fanficTag = _fanficTagsService.GetFanficTagsByFanficId(id).FirstOrDefault(x => x.TagId == tag.Id);
                        await _fanficTagsService.Delete(fanficTag.Id);
                    }
                    return(Ok());
                }
            }
            return(BadRequest(ModelState));
        }