protected Task On(UpdateRule command, CommandContext context) { return(handler.UpdateAsync <RuleDomainObject>(context, async c => { await GuardRule.CanUpdate(command, schemas); c.Update(command); })); }
protected async Task On(AssignContributor command, CommandContext context) { if (await userResolver.FindByIdAsync(command.ContributorId) == null) { var error = new ValidationError("Cannot find contributor the contributor", nameof(AssignContributor.ContributorId)); throw new ValidationException("Cannot assign contributor to app", error); } await handler.UpdateAsync <AppDomainObject>(context, a => { var oldContributors = a.ContributorCount; var maxContributors = appPlansProvider.GetPlan(a.PlanId).MaxContributors; a.AssignContributor(command); if (maxContributors > 0 && a.ContributorCount > oldContributors && a.ContributorCount > maxContributors) { var error = new ValidationError("You have reached your max number of contributors"); throw new ValidationException("Cannot assign contributor to app", error); } }); }
protected async Task On(UpdateAsset command, CommandContext context) { await handler.UpdateAsync <AssetDomainObject>(context, async c => { command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead()); c.Update(command); await assetStore.UploadAsync(c.Id.ToString(), c.FileVersion, null, command.File.OpenRead()); }); }
protected async Task On(AssignContributor command, CommandContext context) { await handler.UpdateAsync <AppDomainObject>(context, async a => { await GuardAppContributors.CanAssign(a.Contributors, command, userResolver, appPlansProvider.GetPlan(a.Plan?.PlanId)); a.AssignContributor(command); }); }
protected async Task On(UpdateContent command, CommandContext context) { await handler.UpdateAsync <ContentDomainObject>(context, async content => { var schemaAndApp = await ResolveSchemaAndAppAsync(command); ExecuteScriptAndTransform(command, content, schemaAndApp.SchemaEntity.ScriptUpdate, "Update"); await ValidateAsync(schemaAndApp, command, () => "Failed to update content", false); content.Update(command); context.Complete(new ContentDataChangedResult(content.Data, content.Version)); }); }
protected async Task On(UpdateContent command, CommandContext context) { await handler.UpdateAsync <ContentDomainObject>(context, async content => { GuardContent.CanUpdate(command); var operationContext = await CreateContext(command, content, () => "Failed to update content."); await operationContext.ValidateAsync(true); await operationContext.ExecuteScriptAndTransformAsync(x => x.ScriptUpdate, "Update"); content.Update(command); context.Complete(new ContentDataChangedResult(content.Snapshot.Data, content.Version)); }); }
public static Task UpdateAsync <T>(this IAggregateHandler handler, CommandContext context, Action <T> updater) where T : class, IAggregate { return(handler.UpdateAsync <T>(context, x => { updater(x); return TaskHelper.Done; })); }
protected async Task On(AssignContributor command, CommandContext context) { if (await userRepository.FindUserByIdAsync(command.ContributorId) == null) { var error = new ValidationError("Cannot find contributor the contributor", nameof(AssignContributor.ContributorId)); throw new ValidationException("Cannot assign contributor to app", error); } await handler.UpdateAsync <AppDomainObject>(context, a => a.AssignContributor(command)); }
protected async Task On(UpdateAsset command, CommandContext context) { command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead()); try { var asset = await handler.UpdateAsync <AssetDomainObject>(context, async a => { a.Update(command); await assetStore.UploadTemporaryAsync(context.ContextId.ToString(), command.File.OpenRead()); context.Complete(new AssetSavedResult(a.Version, a.FileVersion)); }); await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), asset.Id.ToString(), asset.FileVersion, null); } finally { await assetStore.DeleteTemporaryAsync(context.ContextId.ToString()); } }
protected async Task On(UpdateContent command, CommandContext context) { await ValidateAsync(command, () => "Failed to update content"); await handler.UpdateAsync <ContentDomainObject>(context, c => c.Update(command)); }
protected Task On(AddField command, CommandContext context) { return(handler.UpdateAsync <SchemaDomainObject>(context, s => { s.AddField(command); context.Complete(EntityCreatedResult.Create(s.Schema.FieldsById.Values.First(x => x.Name == command.Name).Id, s.Version)); })); }
public static Task <T> UpdateAsync <T>(this IAggregateHandler handler, CommandContext context, Action <T> updater) where T : class, IDomainObject { return(handler.UpdateAsync(context, updater.ToAsync())); }