Пример #1
0
        public async Task <FanficTagsDTO> Update(FanficTagsDTO item)
        {
            FanficTags fanficTags = _mapper.Map <FanficTagsDTO, FanficTags>(item);

            fanficTags = await _database.FanficTagsRepository.Update(fanficTags);

            return(_mapper.Map <FanficTags, FanficTagsDTO>(fanficTags));
        }
Пример #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));
        }