/// <summary> /// Updates tags and dish-tag links /// </summary> /// <param name="dishTagNames">List of tag names for dish</param> /// <param name="dish">Dish</param> /// <param name="cancellationToken"></param> /// <returns></returns> private async Task UpdateTagLinks(HashSet <TagToAdd> dishTagNames, DishDB dish, CancellationToken cancellationToken = default) { foreach (var item in dishTagNames) { TagDB tag = await _context.Tags.IgnoreQueryFilters().Where(_ => _.TagName == item.TagName).Select(_ => _).FirstOrDefaultAsync(cancellationToken); if (tag is null) { var tagAfter = await _tagService.AddTagDBAsync(item); dish.DishTags.Add(new DishTagDB { TagId = tagAfter.Data.Id, DishId = dish.Id }); } else if (_context.Entry(tag).Property <bool>("IsDeleted").CurrentValue) { _context.Entry(tag).Property <bool>("IsDeleted").CurrentValue = false; dish.DishTags.Add(new DishTagDB { TagId = tag.Id, DishId = dish.Id }); } else { dish.DishTags.Add(new DishTagDB { TagId = tag.Id, DishId = dish.Id }); } } }