| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Labels.Contracts; |
| | | 3 | | using Elsa.Labels.Entities; |
| | | 4 | | using Elsa.Persistence.EFCore.Extensions; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Persistence.EFCore.Modules.Labels; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// An Entity Framework Core implementation of <see cref="ILabelStore"/>. |
| | | 10 | | /// </summary> |
| | | 11 | | public class EFCoreLabelStore : ILabelStore |
| | | 12 | | { |
| | | 13 | | private readonly EntityStore<LabelsElsaDbContext, Label> _labelStore; |
| | | 14 | | private readonly EntityStore<LabelsElsaDbContext, WorkflowDefinitionLabel> _workflowDefinitionLabelStore; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of <see cref="EFCoreLabelStore"/>. |
| | | 18 | | /// </summary> |
| | 0 | 19 | | public EFCoreLabelStore(EntityStore<LabelsElsaDbContext, Label> labelStore, EntityStore<LabelsElsaDbContext, Workflo |
| | | 20 | | { |
| | 0 | 21 | | _labelStore = labelStore; |
| | 0 | 22 | | _workflowDefinitionLabelStore = workflowDefinitionLabelStore; |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | 0 | 26 | | public async Task SaveAsync(Label record, CancellationToken cancellationToken = default) => await _labelStore.SaveAs |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | 0 | 29 | | public async Task SaveManyAsync(IEnumerable<Label> records, CancellationToken cancellationToken = default) => await |
| | | 30 | | |
| | | 31 | | /// <inheritdoc /> |
| | | 32 | | public async Task<bool> DeleteAsync(string id, CancellationToken cancellationToken = default) |
| | | 33 | | { |
| | 0 | 34 | | await _workflowDefinitionLabelStore.DeleteWhereAsync(x => x.LabelId == id, cancellationToken); |
| | 0 | 35 | | return await _labelStore.DeleteWhereAsync(x => x.Id == id, cancellationToken) > 0; |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public async Task<long> DeleteManyAsync(IEnumerable<string> ids, CancellationToken cancellationToken = default) |
| | | 40 | | { |
| | 0 | 41 | | var idList = ids.ToList(); |
| | 0 | 42 | | await _workflowDefinitionLabelStore.DeleteWhereAsync(x => idList.Contains(x.LabelId), cancellationToken); |
| | 0 | 43 | | return await _labelStore.DeleteWhereAsync(x => idList.Contains(x.Id), cancellationToken); |
| | 0 | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | public async Task<Label?> FindByIdAsync(string id, CancellationToken cancellationToken = default) => await _labelSto |
| | | 47 | | |
| | | 48 | | public async Task<Page<Label>> ListAsync(PageArgs? pageArgs = null, CancellationToken cancellationToken = default) |
| | | 49 | | { |
| | 0 | 50 | | await using var dbContext = await _labelStore.CreateDbContextAsync(cancellationToken); |
| | 0 | 51 | | var set = dbContext.Labels.OrderBy(x => x.Name); |
| | 0 | 52 | | return await set.PaginateAsync(pageArgs); |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public async Task<IEnumerable<Label>> FindManyByIdAsync(IEnumerable<string> ids, CancellationToken cancellationToken |
| | | 56 | | { |
| | 0 | 57 | | var idList = ids.ToList(); |
| | 0 | 58 | | return await _labelStore.FindManyAsync(x => idList.Contains(x.Id), cancellationToken); |
| | 0 | 59 | | } |
| | | 60 | | } |