private async Task DeleteFanficTagsByFanficId(string id) { List <FanficTagsDTO> tags = _fanficTagsService.GetFanficTagsByFanficId(id).ToList(); if (tags == null) { return; } foreach (var tag in tags) { await _fanficTagsService.Delete(tag.Id); } }
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)); }