public async Task Delete(int id, bool onlyMark = true) { var category = await _repository.LoadAsync <Category>(id); if (category == null) { throw new ArgumentException($"Нет категории с идентификатором {id}"); } var products = await _productQueries.GetCategoryProducts(category.Id, true); if (onlyMark) { await _productCommands.GroupDeletion(products.Select(x => x.Id).ToArray()); category.IsDeleted = true; _repository.Update(category); } else { await _productCommands.GroupDeletion(products.Select(x => x.Id).ToArray(), false); _repository.Delete(category); } await _repository.SaveChangesAsync().ConfigureAwait(false); }