private async Task ImportTagsToTransactionsAsync(List <TagToTransactionSyncDTO> t2ts) { var tagIds = t2ts.Select(x => x.TagId.ToString()).ToList(); var transactionIds = t2ts.Select(x => x.TransactionId.ToString()).ToList(); var tags = (await this.tagRepository.GetAsync(tagIds)) .ToDictionary(x => x.ExternalId, x => x); var transactions = (await this.transactionRepository.GetTransactionsAsync()) .Where(x => transactionIds.Contains(x.ExternalId)).ToList() .ToDictionary(x => x.ExternalId, x => x); var newTags = new List <TagToTransaction>(); foreach (var item in t2ts) { var t2t = new TagToTransaction { Tag = tags[item.TagId.ToString()], Transaction = transactions[item.TransactionId.ToString()], }; newTags.Add(t2t); } if (newTags.Any()) { await this.tagRepository.AddAsync(newTags); } }
public async Task RemoveAsync(TagToTransaction tagToTransaction) { this.Context.TagsToTransactions.Remove(tagToTransaction); await this.Context.SaveChangesAsync(); }
public async Task AddAsync(TagToTransaction tagToTransaction) { await this.Context.TagsToTransactions.AddAsync(tagToTransaction); await this.Context.SaveChangesAsync(); }