示例#1
0
        protected Task On(UpdateRule command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <RuleDomainObject>(context, async r =>
            {
                await GuardRule.CanUpdate(command, appProvider);

                r.Update(command);
            }));
        }
示例#2
0
        protected async Task On(UpdateAsset command, CommandContext context)
        {
            command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead());

            try
            {
                var asset = await handler.UpdateSyncedAsync <AssetDomainObject>(context, async a =>
                {
                    GuardAsset.CanUpdate(command);

                    a.Update(command);

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

                    context.Complete(new AssetSavedResult(a.Version, a.Snapshot.FileVersion));
                });

                await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), command.AssetId.ToString(), asset.Snapshot.FileVersion, null);
            }
            finally
            {
                await assetStore.DeleteTemporaryAsync(context.ContextId.ToString());
            }
        }
        protected Task On(AddField command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanAdd(s.Snapshot.SchemaDef, command);

                s.Add(command);

                context.Complete(EntityCreatedResult.Create(s.Snapshot.SchemaDef.FieldsById.Values.First(x => x.Name == command.Name).Id, s.Version));
            }));
        }
示例#4
0
        protected Task On(AssignContributor command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, async a =>
            {
                await GuardAppContributors.CanAssign(a.Snapshot.Contributors, command, userResolver, appPlansProvider.GetPlan(a.Snapshot.Plan?.PlanId));

                a.AssignContributor(command);
            }));
        }
示例#5
0
 public static Task <T> UpdateSyncedAsync <T>(this IAggregateHandler handler, CommandContext context, Action <T> updater) where T : class, IDomainObject
 {
     return(handler.UpdateSyncedAsync(context, updater.ToAsync()));
 }