Add validation
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:vm="using:Wallet"
|
||||
Margin="0,0,0,-18"
|
||||
x:DataType="vm:ItemHeaderViewModel">
|
||||
<UserControl.Resources>
|
||||
<x:Double x:Key="PersonPictureSize">144</x:Double>
|
||||
@@ -72,63 +73,70 @@
|
||||
Text="" />
|
||||
</DropDownButton>
|
||||
</Grid>
|
||||
<TextBox
|
||||
MaxWidth="{StaticResource TextBoxMaxWidth}"
|
||||
Text="{Binding Value}"
|
||||
TextAlignment="Center"
|
||||
Watermark="Enter name">
|
||||
<TextBox.Styles>
|
||||
<Style Selector="TextBox.Write">
|
||||
<Setter Property="MinWidth" Value="{StaticResource TextBoxMinWidth}" />
|
||||
</Style>
|
||||
<Style Selector="TextBox.Read">
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="IsReadOnly" Value="True" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Foreground">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style Selector="^:pointerover">
|
||||
<StackPanel>
|
||||
<TextBox
|
||||
MaxWidth="{StaticResource TextBoxMaxWidth}"
|
||||
Text="{Binding Value}"
|
||||
TextAlignment="Center"
|
||||
Watermark="Enter name">
|
||||
<TextBox.Styles>
|
||||
<Style Selector="TextBox.Write">
|
||||
<Setter Property="MinWidth" Value="{StaticResource TextBoxMinWidth}" />
|
||||
</Style>
|
||||
<Style Selector="TextBox.Read">
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="IsReadOnly" Value="True" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Foreground">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Style Selector="^:pointerover">
|
||||
<Setter Property="Foreground">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
</Style>
|
||||
<Style Selector="^:focus">
|
||||
<Setter Property="Foreground">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
</Style>
|
||||
</Style>
|
||||
</Style>
|
||||
<Style Selector="^:focus">
|
||||
<Setter Property="Foreground">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ Border#PART_BorderElement">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
</Style>
|
||||
</Style>
|
||||
</Style>
|
||||
</TextBox.Styles>
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Read}">
|
||||
<AddClassAction ClassName="Read" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Write" />
|
||||
</DataTriggerBehavior>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.New}">
|
||||
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Read" />
|
||||
</DataTriggerBehavior>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Write}">
|
||||
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Read" />
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</TextBox>
|
||||
</TextBox.Styles>
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Read}">
|
||||
<AddClassAction ClassName="Read" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Write" />
|
||||
</DataTriggerBehavior>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.New}">
|
||||
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Read" />
|
||||
</DataTriggerBehavior>
|
||||
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Write}">
|
||||
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||
<RemoveClassAction ClassName="Read" />
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</TextBox>
|
||||
<TextBlock
|
||||
Margin="0,4,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="{DynamicResource SystemFillColorCriticalBrush}"
|
||||
Text="{ReflectionBinding Validation.Errors[Value]}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace Wallet.Data;
|
||||
|
||||
[Table("Blobs")]
|
||||
public record BlobEntry
|
||||
public record BlobEntity
|
||||
{
|
||||
public byte[]? Data { get; set; }
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace Wallet.Data;
|
||||
|
||||
[Table("Items")]
|
||||
public record ItemEntry
|
||||
public record ItemEntity
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
@@ -17,11 +17,11 @@ public record ItemEntry
|
||||
|
||||
public Guid? ImageId { get; set; }
|
||||
|
||||
public BlobEntry? Image { get; set; }
|
||||
public BlobEntity? Image { get; set; }
|
||||
|
||||
public required string Category { get; set; }
|
||||
|
||||
public ICollection<TagEntry> Tags { get; set; } = new List<TagEntry>();
|
||||
public ICollection<TagEntity> Tags { get; set; } = new List<TagEntity>();
|
||||
|
||||
public ICollection<BlobEntry> Blobs { get; set; } = new List<BlobEntry>();
|
||||
public ICollection<BlobEntity> Blobs { get; set; } = new List<BlobEntity>();
|
||||
}
|
||||
@@ -6,11 +6,11 @@ public interface IConnection;
|
||||
|
||||
public class WalletContext(IConnection connection) : DbContext
|
||||
{
|
||||
public DbSet<BlobEntry> Blobs { get; set; }
|
||||
public DbSet<BlobEntity> Blobs { get; set; }
|
||||
|
||||
public DbSet<ItemEntry> Items { get; set; }
|
||||
public DbSet<ItemEntity> Items { get; set; }
|
||||
|
||||
public DbSet<TagEntry> Tags { get; set; }
|
||||
public DbSet<TagEntity> Tags { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@@ -19,27 +19,27 @@ public class WalletContext(IConnection connection) : DbContext
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<ItemEntry>()
|
||||
modelBuilder.Entity<ItemEntity>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<ItemEntry>()
|
||||
modelBuilder.Entity<ItemEntity>()
|
||||
.HasMany(x => x.Tags)
|
||||
.WithOne()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<ItemEntry>()
|
||||
modelBuilder.Entity<ItemEntity>()
|
||||
.HasMany(x => x.Blobs)
|
||||
.WithOne()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<ItemEntry>().
|
||||
modelBuilder.Entity<ItemEntity>().
|
||||
HasOne(i => i.Image)
|
||||
.WithOne()
|
||||
.HasForeignKey<ItemEntry>(i => i.ImageId)
|
||||
.HasForeignKey<ItemEntity>(i => i.ImageId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<BlobEntry>()
|
||||
modelBuilder.Entity<BlobEntity>()
|
||||
.HasKey(x => x.Id);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace Wallet.Data;
|
||||
|
||||
[Table("Tags")]
|
||||
public class TagEntry
|
||||
public class TagEntity
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
@@ -28,12 +28,12 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
||||
thumbData = memoryStream.ToArray();
|
||||
}
|
||||
|
||||
ItemEntry itemEntry = new()
|
||||
ItemEntity itemEntry = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Category = category,
|
||||
Image = thumbData != null ? new BlobEntry
|
||||
Image = thumbData != null ? new BlobEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Data = thumbData,
|
||||
@@ -42,7 +42,7 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
||||
} : null,
|
||||
Blobs =
|
||||
{
|
||||
new BlobEntry
|
||||
new BlobEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Data = Encoding.UTF8.GetBytes(content),
|
||||
@@ -53,7 +53,7 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
||||
};
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
EntityEntry<ItemEntry>? result = await context.AddAsync(itemEntry, cancellationToken);
|
||||
EntityEntry<ItemEntity>? result = await context.AddAsync(itemEntry, cancellationToken);
|
||||
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class DeleteItemHandler(IDbContextFactory<WalletContext> dbContextFactory
|
||||
Guid id = item.Value;
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
if (await context.FindAsync<ItemEntity>(id) is ItemEntity result)
|
||||
{
|
||||
context.Items.Remove(result);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record ItemEntry;
|
||||
@@ -19,9 +19,9 @@ public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
|
||||
double width) :
|
||||
Observable<string, TValue>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
INotificationHandler<ConfirmEventArgs<ItemEntry>>,
|
||||
INotificationHandler<UpdateEventArgs<ItemEntry>>,
|
||||
INotificationHandler<CancelEventArgs<ItemEntry>>
|
||||
where TValue : notnull
|
||||
{
|
||||
[ObservableProperty]
|
||||
@@ -36,10 +36,10 @@ public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private double width = width;
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args) =>
|
||||
public Task Handle(UpdateEventArgs<ItemEntry> args) =>
|
||||
Task.FromResult(State = ItemState.Write);
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
public Task Handle(CancelEventArgs<ItemEntry> args)
|
||||
{
|
||||
Revert();
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(ConfirmEventArgs<Item> args)
|
||||
public Task Handle(ConfirmEventArgs<ItemEntry> args)
|
||||
{
|
||||
Commit();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
Guid id = item.Value;
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
var result = await context.Set<ItemEntry>()
|
||||
var result = await context.Set<ItemEntity>()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(x => new
|
||||
{
|
||||
@@ -35,7 +35,7 @@ public class ItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
if (result is not null)
|
||||
{
|
||||
ItemConfiguration? configuration = null;
|
||||
if (result.Blob is BlobEntry blob && blob.Data is { Length: > 0 } data)
|
||||
if (result.Blob is BlobEntity blob && blob.Data is { Length: > 0 } data)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Xml.Linq;
|
||||
using Toolkit.Foundation;
|
||||
using Wallet.Data;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public partial class ItemHeaderViewModel :
|
||||
Observable<string>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>,
|
||||
IHandler<ValidateEventArgs<ItemEntry>, bool>,
|
||||
INotificationHandler<UpdateEventArgs<ItemEntry>>,
|
||||
INotificationHandler<ConfirmEventArgs<ItemEntry>>,
|
||||
INotificationHandler<CancelEventArgs<ItemEntry>>,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>,
|
||||
INotificationHandler<NotifyEventArgs<Item<IImageDescriptor>>>,
|
||||
IItemViewModel
|
||||
@@ -30,11 +33,14 @@ public partial class ItemHeaderViewModel :
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
IValidation validation,
|
||||
ItemHeaderConfiguration configuration,
|
||||
ItemState state,
|
||||
string value,
|
||||
IImageDescriptor? imageDescriptor = null) : base(provider, factory, mediator, publisher, subscriber, disposer, value)
|
||||
{
|
||||
Validation = validation;
|
||||
|
||||
this.configuration = configuration;
|
||||
|
||||
State = state;
|
||||
@@ -43,12 +49,18 @@ public partial class ItemHeaderViewModel :
|
||||
|
||||
Track(nameof(Value), () => Value, x => Value = x);
|
||||
Track(nameof(ImageDescriptor), () => ImageDescriptor, x => ImageDescriptor = x);
|
||||
|
||||
Validation.Add(() => Value, [new ValidationRule(() => Value is { Length: > 0 }, "Name is required")],
|
||||
ValidationTrigger.Deferred);
|
||||
}
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args) =>
|
||||
[ObservableProperty]
|
||||
private IValidation validation;
|
||||
|
||||
public Task Handle(UpdateEventArgs<ItemEntry> args) =>
|
||||
Task.FromResult(State = ItemState.Write);
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
public Task Handle(CancelEventArgs<ItemEntry> args)
|
||||
{
|
||||
Revert();
|
||||
|
||||
@@ -56,7 +68,7 @@ public partial class ItemHeaderViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(ConfirmEventArgs<Item> args)
|
||||
public Task Handle(ConfirmEventArgs<ItemEntry> args)
|
||||
{
|
||||
Commit();
|
||||
|
||||
@@ -85,6 +97,9 @@ public partial class ItemHeaderViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<bool> Handle(ValidateEventArgs<ItemEntry> args,
|
||||
CancellationToken cancellationToken) => await Validation.Validate();
|
||||
|
||||
protected override void OnValueChanged()
|
||||
{
|
||||
if (configuration is not null)
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ItemImageHandler(IDbContextFactory<WalletContext> dbContextFactory,
|
||||
Guid id = item.Value;
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
var result = await context.Set<ItemEntry>()
|
||||
var result = await context.Set<ItemEntity>()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(x => new
|
||||
{
|
||||
@@ -25,7 +25,7 @@ public class ItemImageHandler(IDbContextFactory<WalletContext> dbContextFactory,
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (result is not null &&
|
||||
result.Image is BlobEntry image &&
|
||||
result.Image is BlobEntity image &&
|
||||
image.Data is { Length: > 0 } data)
|
||||
{
|
||||
MemoryStream stream = new(data);
|
||||
|
||||
+22
-10
@@ -1,5 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
using Wallet.Data;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
@@ -77,6 +78,7 @@ public partial class ItemViewModel :
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Update.As<ItemEntry>());
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<ConfirmItemActionViewModel>(),
|
||||
@@ -89,6 +91,7 @@ public partial class ItemViewModel :
|
||||
|
||||
public Task Handle(CancelEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Cancel.As<ItemEntry>());
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
@@ -99,20 +102,29 @@ public partial class ItemViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(ConfirmEventArgs<Item> args)
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
List<bool> results = [];
|
||||
await foreach (bool result in Mediator.HandleManyAsync<ValidateEventArgs<ItemEntry>, bool>(Validate.As<ItemEntry>()))
|
||||
{
|
||||
Factory.Create<FavouriteItemActionViewModel>(Favourite),
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
Publisher.Publish(Confirm.As<Item>(),
|
||||
State is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write));
|
||||
if (results.All(result => result))
|
||||
{
|
||||
Publisher.Publish(Confirm.As<ItemEntry>());
|
||||
Publisher.Publish(Notify.As(Factory.Create<ItemCommandHeaderCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<FavouriteItemActionViewModel>(Favourite),
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
|
||||
State = ItemState.Read;
|
||||
return Task.CompletedTask;
|
||||
Publisher.Publish(Confirm.As<Item>(),
|
||||
State is ItemState.New ? nameof(ItemState.New) : nameof(ItemState.Write));
|
||||
|
||||
State = ItemState.Read;
|
||||
}
|
||||
}
|
||||
|
||||
public override Task OnActivated()
|
||||
|
||||
@@ -16,8 +16,8 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
||||
{
|
||||
(string filter, string text) = Wallet.Value;
|
||||
|
||||
ExpressionStarter<ItemEntry> predicate =
|
||||
PredicateBuilder.New<ItemEntry>(true);
|
||||
ExpressionStarter<ItemEntity> predicate =
|
||||
PredicateBuilder.New<ItemEntity>(true);
|
||||
|
||||
if (filter is { Length: <= 0 })
|
||||
{
|
||||
@@ -49,7 +49,7 @@ public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactor
|
||||
}
|
||||
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
var results = await context.Set<ItemEntry>()
|
||||
var results = await context.Set<ItemEntity>()
|
||||
.Where(predicate)
|
||||
.Select(x => new
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ public class UpdateItemHander(IDbContextFactory<WalletContext> dbContextFactory,
|
||||
try
|
||||
{
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
ItemEntry? result = result = await context.Set<ItemEntry>()
|
||||
ItemEntity? result = result = await context.Set<ItemEntity>()
|
||||
.Include(x => x.Image).FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
|
||||
if (result is not null)
|
||||
@@ -40,7 +40,7 @@ public class UpdateItemHander(IDbContextFactory<WalletContext> dbContextFactory,
|
||||
imageWriter.Write(imageDescriptor, memoryStream);
|
||||
thumbData = memoryStream.ToArray();
|
||||
|
||||
if (result.Image is BlobEntry existingImageBlob)
|
||||
if (result.Image is BlobEntity existingImageBlob)
|
||||
{
|
||||
existingImageBlob.Data = thumbData;
|
||||
existingImageBlob.DateTime = DateTime.UtcNow;
|
||||
@@ -49,7 +49,7 @@ public class UpdateItemHander(IDbContextFactory<WalletContext> dbContextFactory,
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Image = new BlobEntry
|
||||
result.Image = new BlobEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Data = thumbData,
|
||||
|
||||
@@ -13,7 +13,7 @@ public class UpdateItemStateHandler(IDbContextFactory<WalletContext> dbContextFa
|
||||
if (args.Sender is (Guid id, int state))
|
||||
{
|
||||
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
if (await context.FindAsync<ItemEntity>(id) is ItemEntity result)
|
||||
{
|
||||
result.State = state;
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user