public async Task <Result <CollectionReference> > AddCollection(IScreen context, DatabaseReference database) { var exportOptions = new AddCollectionOptions(database); var optionsResult = await ShowHostDialog(context).For(exportOptions); if (optionsResult.Action is "cancel") { return(Result.Failure <CollectionReference>(Fails.Canceled)); } try { var collectionName = optionsResult.Model.NewCollectionName; if (!string.IsNullOrEmpty(collectionName)) { var collectionReference = database.AddCollection(collectionName); return(Result.Ok(collectionReference)); } return(Result.Ok <CollectionReference>(null)); } catch (Exception exc) { var message = "Failed to add new collection:" + Environment.NewLine + exc.Message; _applicationInteraction.ShowError(exc, message, "Database error"); return(Result.Failure <CollectionReference>(message)); } }
public Task <Result <CollectionReference> > AddCollection(DatabaseReference database) { try { if (InputBoxWindow.ShowDialog("New collection name:", "Enter new collection name", "", out string name) == true) { var collectionReference = database.AddCollection(name); return(Task.FromResult(Result.Ok(collectionReference))); } return(Task.FromResult(Result.Ok <CollectionReference>(null))); } catch (Exception exc) { var message = "Failed to add new collection:" + Environment.NewLine + exc.Message; _applicationInteraction.ShowError(exc, message, "Database error"); return(Task.FromResult(Result.Fail <CollectionReference>(message))); } }
public Result <bool> AddCollection(DatabaseReference database) { try { if (InputBoxWindow.ShowDialog("New collection name:", "Enter new collection name", "", out string name) == true) { database.AddCollection(name); return(Result.Ok(true)); } return(Result.Ok(false)); } catch (Exception exc) { var message = "Failed to add new collection:" + Environment.NewLine + exc.Message; ErrorInteraction(message); return(Result.Fail <bool>(message)); } }
public async Task <Result <CollectionReference> > AddCollection(DatabaseReference database) { try { var maybeName = await _applicationInteraction.ShowInputDialog("New collection name:", "Enter new collection name"); if (maybeName.HasValue) { var collectionReference = database.AddCollection(maybeName.Value); return(Result.Ok(collectionReference)); } return(Result.Ok <CollectionReference>(null)); } catch (Exception exc) { var message = "Failed to add new collection:" + Environment.NewLine + exc.Message; _applicationInteraction.ShowError(exc, message, "Database error"); return(Result.Fail <CollectionReference>(message)); } }