public async Task ProcessTags(string userId, string url, DateTimeOffset savedAt, string tagsString) { List<string> tags = new List<string>(_tagParser.FromString(tagsString)); foreach (string tagString in tags) { bool exists = false; bool needsIncrement = false; UserTag tag = new UserTag(userId, tagString) { NumberOfItems = 1 }; DateOrderedUserTagItem dateOrderedTagItem = new DateOrderedUserTagItem(userId, tagString, url, savedAt); UniqueUserTagItem uniqueTagItem = new UniqueUserTagItem(userId, tagString, url, savedAt); try { await _userTagRepository.Save(tag); } catch (UniqueKeyViolation) { needsIncrement = true; } try { await _userTagRepository.Save(uniqueTagItem); } catch (UniqueKeyViolation) { exists = true; } List<Task> tasks = new List<Task>(); if (!exists) { tasks.Add(_userTagRepository.Save(dateOrderedTagItem)); } if (needsIncrement) { tasks.Add(_userTagRepository.IncrementTagItemCount(userId, tagString)); } await Task.WhenAll(tasks); } }
public async Task Save(DateOrderedUserTagItem dateOrderedUserTagItem) { await _dateOrderedUserTagItemsTable.InsertAsync(dateOrderedUserTagItem); }