public async Task <CommandResult> Handle(CreateAppCommand command) { var result = new CommandResult(); var app = command.CreateApp(); if (!await _validator.IsValid(app)) { result.AddValidationErrors(_validator.Errors); } else { if (await _store.AppExists(app.Id)) { result.AddValidationError(new ValidationError { Name = "Id", ErrorMessage = "AppIdAlreadyExists", Parameters = new[] { app.Id } }); } else { await _store.AddApp(app); result.SetResultData(app); } } return(result); }
public async Task <CommandResult> Handle(DeleteContentCollectionCommand command) { var result = new CommandResult(); // Verify that the collection has no content. if (await _contentStore.CollectionContainsContent(command.Id, command.AppId)) { result.AddValidationError(new ValidationError() { Name = "", ErrorMessage = "DeleteCollectionContainsContent" }); } if (!result.ValidationErrors.Any()) { await _contentStore.DeleteContentCollection(command.Id, command.AppId); } return(result); }
public async Task <CommandResult> Handle(DeleteContentTypeCommand command) { var result = new CommandResult(); // Verify that no collection with the content type exists (except snapshot collections). var collections = await _contentStore.GetContentCollections(new ContentCollectionQuery { AppId = command.AppId }); // TODO: exclude snapshot collections if (collections.Any(c => c.ContentType.Id == command.Id)) { var collectionNames = collections.Where(c => c.ContentType.Id == command.Id).Select(c => c.Name); result.AddValidationError(new ValidationError() { Name = "", ErrorMessage = "DeleteContentTypeInUse", Parameters = new[] { string.Join(",", collectionNames) } }); } if (!result.ValidationErrors.Any()) { await _contentDefinitionStore.DeleteContentType(command.Id, command.AppId); } return(result); }