Ejemplo n.º 1
0
        public static Task CreateAsync <T>(this IAggregateHandler handler, CommandContext context, Action <T> creator) where T : class, IAggregate
        {
            return(handler.CreateAsync <T>(context, x =>
            {
                creator(x);

                return TaskHelper.Done;
            }));
        }
Ejemplo n.º 2
0
        protected Task On(CreateSchema command, CommandContext context)
        {
            return(handler.CreateAsync <SchemaDomainObject>(context, async s =>
            {
                await GuardSchema.CanCreate(command, appProvider);

                s.Create(command);

                context.Complete(EntityCreatedResult.Create(s.Id, s.Version));
            }));
        }
Ejemplo n.º 3
0
        protected async Task On(CreateApp command, CommandContext context)
        {
            if (await appRepository.FindAppAsync(command.Name) != null)
            {
                var error =
                    new ValidationError($"An app with name '{command.Name}' already exists",
                                        nameof(CreateApp.Name));

                throw new ValidationException("Cannot create a new app", error);
            }

            await handler.CreateAsync <AppDomainObject>(context, a =>
            {
                a.Create(command);

                context.Succeed(EntityCreatedResult.Create(a.Id, a.Version));
            });
        }
Ejemplo n.º 4
0
        protected async Task On(CreateAsset command, CommandContext context)
        {
            command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead());

            try
            {
                var asset = await handler.CreateAsync <AssetDomainObject>(context, async a =>
                {
                    a.Create(command);

                    await assetStore.UploadTemporaryAsync(context.ContextId.ToString(), command.File.OpenRead());

                    context.Complete(EntityCreatedResult.Create(a.Id, a.Version));
                });

                await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), asset.Id.ToString(), asset.FileVersion, null);
            }
            finally
            {
                await assetStore.DeleteTemporaryAsync(context.ContextId.ToString());
            }
        }
        protected async Task On(CreateWebhook command, CommandContext context)
        {
            await ValidateAsync(command, () => "Failed to create webhook");

            await handler.CreateAsync <WebhookDomainObject>(context, c => c.Create(command));
        }
Ejemplo n.º 6
0
 public static Task <T> CreateAsync <T>(this IAggregateHandler handler, CommandContext context, Action <T> creator) where T : class, IDomainObject
 {
     return(handler.CreateAsync(context, creator.ToAsync()));
 }