Ensure item is updated when modified
This commit is contained in:
@@ -12,27 +12,38 @@ public class ConfirmItemHandler(IValueStore<Item> valueStore,
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
|
||||
if (valueStore?.Value is Item item)
|
||||
if (configuration is not null)
|
||||
{
|
||||
(bool Success, int Id, string Name) = await mediator.Handle<EditEventArgs<(int, ItemConfiguration)>,
|
||||
(bool, int, string)>(new EditEventArgs<(int, ItemConfiguration)>((item.Id, new ItemConfiguration { Name = configuration?.Name })));
|
||||
|
||||
if (Success)
|
||||
bool success = false;
|
||||
if (valueStore?.Value is Item item)
|
||||
{
|
||||
Item newItem = new Item { Id = Id, Name = Name };
|
||||
publisher.Publish(Modified.As(item, newItem));
|
||||
(bool Success, int Id, string Name) = await mediator.Handle<EditEventArgs<(int, ItemConfiguration)>,
|
||||
(bool, int, string)>(new EditEventArgs<(int, ItemConfiguration)>((item.Id, new ItemConfiguration { Name = configuration.Name })));
|
||||
|
||||
valueStore.Set(newItem);
|
||||
if (Success)
|
||||
{
|
||||
Item newItem = new() { Id = Id, Name = Name };
|
||||
publisher.Publish(Modified.As(item, newItem));
|
||||
|
||||
valueStore.Set(newItem);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(bool Success, int Id, string Name) = await mediator.Handle<CreateEventArgs<ItemConfiguration>,
|
||||
(bool, int, string)>(new CreateEventArgs<ItemConfiguration>(new ItemConfiguration { Name = configuration?.Name }));
|
||||
|
||||
if (Success)
|
||||
else
|
||||
{
|
||||
publisher.Publish(Created.As(new Item { Id = Id, Name = Name }));
|
||||
(bool Success, int Id, string Name) = await mediator.Handle<CreateEventArgs<ItemConfiguration>,
|
||||
(bool, int, string)>(new CreateEventArgs<ItemConfiguration>(new ItemConfiguration { Name = configuration.Name }));
|
||||
|
||||
if (Success)
|
||||
{
|
||||
publisher.Publish(Created.As(new Item { Id = Id, Name = Name }));
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
publisher.Publish(Notify.As(configuration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user