public async Task <Result <CollectionDocumentChangeEventArgs> > CreateItem(IScreen context, CollectionReference collection) { if (collection is FileCollectionReference) { return(await AddFileToDatabase(context, collection.Database)); } var addDocumentOptions = new AddDocumentOptions(collection); var optionsResult = await ShowHostDialog(context).For(addDocumentOptions); if (optionsResult.Action is AddDocumentOptions.ACTION_CANCEL) { return(Result.Failure <CollectionDocumentChangeEventArgs>(Fails.Canceled)); } var newId = optionsResult.Model.NewId; var newDoc = new BsonDocument { ["_id"] = newId }; var documentReference = collection.AddItem(newDoc); var documentsCreated = new CollectionDocumentChangeEventArgs(ReferenceNodeChangeAction.Add, documentReference, collection) { PostAction = (optionsResult.Model.EditAfterCreate || optionsResult.Action is AddDocumentOptions.ACTION_OK_AND_EDIT) ? "edit" : null }; return(Result.Ok(documentsCreated)); }
private void AddItemToCollection(CollectionReference collectionReference) { BsonDocument newDoc = new BsonDocument { ["_id"] = ObjectId.NewObjectId() }; collectionReference.AddItem(newDoc); }
public Task <Result <CollectionDocumentChangeEventArgs> > ImportDataFromText(CollectionReference collection, string textData) { try { if (string.IsNullOrWhiteSpace(textData)) { return(Task.FromResult(Result.Ok(CollectionDocumentChangeEventArgs.Nome))); } var newValue = JsonSerializer.Deserialize(textData); var newDocs = new List <DocumentReference>(); if (newValue.IsArray) { foreach (var value in newValue.AsArray) { var doc = value.AsDocument; var documentReference = collection.AddItem(doc); newDocs.Add(documentReference); } } else { var doc = newValue.AsDocument; var documentReference = collection.AddItem(doc); newDocs.Add(documentReference); } var documentsUpdate = new CollectionDocumentChangeEventArgs(ReferenceNodeChangeAction.Add, newDocs, collection); return(Task.FromResult(Result.Ok(documentsUpdate))); } catch (Exception e) { var message = "Failed to import document from text content: " + e.Message; Logger.Warn(e, "Cannot process clipboard data."); _applicationInteraction.ShowError(e, message, "Import Error"); return(Task.FromResult(Result.Fail <CollectionDocumentChangeEventArgs>(message))); } }
public Result <InteractionEvents.CollectionDocumentsCreated> ImportDataFromText(CollectionReference collection, string textData) { try { if (string.IsNullOrWhiteSpace(textData)) { return(Result.Ok(new InteractionEvents.CollectionDocumentsCreated(collection, null))); } var newValue = JsonSerializer.Deserialize(textData); var newDocs = new List <DocumentReference>(); if (newValue.IsArray) { foreach (var value in newValue.AsArray) { var doc = value.AsDocument; var documentReference = collection.AddItem(doc); newDocs.Add(documentReference); } } else { var doc = newValue.AsDocument; var documentReference = collection.AddItem(doc); newDocs.Add(documentReference); } var documentsUpdate = new InteractionEvents.CollectionDocumentsCreated(collection, newDocs); return(Result.Ok(documentsUpdate)); } catch (Exception e) { var message = "Failed to import document from text content: " + e.Message; Logger.Warn(e, "Cannot process clipboard data."); ErrorInteraction(message, "Import Error"); return(Result.Fail <InteractionEvents.CollectionDocumentsCreated>(message)); } }
public Result ImportDataFromText(CollectionReference collection, string textData) { try { if (string.IsNullOrWhiteSpace(textData)) { return(Result.Ok()); } var newValue = JsonSerializer.Deserialize(textData); var newDocs = new List <BsonDocument>(); if (newValue.IsArray) { foreach (var value in newValue.AsArray) { var doc = value.AsDocument; collection.AddItem(doc); newDocs.Add(doc); } } else { var doc = newValue.AsDocument; collection.AddItem(doc); newDocs.Add(doc); } _eventAggregator.BeginPublishOnUIThread(new InteractionEvents.DocumentsUpdated(nameof(ImportDataFromText), newDocs)); } catch (Exception e) { var message = "Failed to import document from text content: " + e.Message; Logger.Warn(e, "Cannot process clipboard data."); ErrorInteraction(message, "Import Error"); return(Result.Fail(message)); } return(Result.Ok()); }
public Task <Result <CollectionDocumentChangeEventArgs> > CreateItem(CollectionReference collection) { if (collection is FileCollectionReference) { return(AddFileToDatabase(collection.Database)); } var newDoc = new BsonDocument { ["_id"] = ObjectId.NewObjectId() }; var documentReference = collection.AddItem(newDoc); var documentsCreated = new CollectionDocumentChangeEventArgs(ReferenceNodeChangeAction.Add, documentReference, collection); return(Task.FromResult(Result.Ok(documentsCreated))); }
public Result <InteractionEvents.CollectionDocumentChange> CreateItem(CollectionReference collection) { if (collection is FileCollectionReference) { return(AddFileToDatabase(collection.Database)); } var newDoc = new BsonDocument { ["_id"] = ObjectId.NewObjectId() }; var documentReference = collection.AddItem(newDoc); var documentsCreated = new InteractionEvents.CollectionDocumentChange(ReferenceNodeChangeAction.Add, documentReference, collection); return(Result.Ok(documentsCreated)); }
public Result <TypedDocumentReference> CreateItem(CollectionReference collection) { if (collection is FileCollectionReference) { return(AddFileToDatabase(collection.Database)); } var newDoc = new BsonDocument { ["_id"] = ObjectId.NewObjectId() }; var documentReference = collection.AddItem(newDoc); Store.Current.SelectDocument(documentReference); _eventAggregator.BeginPublishOnUIThread(new InteractionEvents.DocumentsUpdated(nameof(CreateItem), newDoc)); return(Result.Ok(new TypedDocumentReference(DocumentType.BsonDocument, documentReference))); }