public async Task <bool> UpdateFlowGraphItemAsync(string id, FlowGraphItem item) { try { var all = await GetAllFlowGraphItemAsync(); var filter = Builders <FlowGraphItem> .Filter.Where(x => x._id.Equals(id)); if ((item.FlowGraphs == null) || (item.FlowGraphs.Count == 0)) { var result = await GetCollection <FlowGraphItem>(CollectionNames.DrawFlowGraphs).DeleteOneAsync(filter); return(result.IsAcknowledged); } var options = new FindOneAndReplaceOptions <FlowGraphItem, FlowGraphItem> { IsUpsert = false, ReturnDocument = ReturnDocument.After }; var updatedEntity = await GetCollection <FlowGraphItem>(CollectionNames.DrawFlowGraphs).FindOneAndReplaceAsync(filter, item, options); return(updatedEntity._id == id); } catch (Exception ex) { logger.LogError(ex, string.Empty); return(false); } }
public async Task <bool> Put(string id, [FromBody] FlowGraphItem value) { try { return(await _botMongoDal.UpdateFlowGraphItemAsync(value._id, value).ConfigureAwait(false));; } catch (Exception e) { _logger.LogError(e, string.Empty); return(false); } }
public async Task <bool> InsertFlowGraphItemAsync(FlowGraphItem item) { try { item._id = item._id == null || item._id.Equals(ObjectId.Empty.ToString()) ? ObjectId.GenerateNewId().ToString() : item._id; var filter = Builders <FlowGraphItem> .Filter.Where(x => x._t.Equals(item._t)); var options = new FindOneAndReplaceOptions <FlowGraphItem, FlowGraphItem> { IsUpsert = true, ReturnDocument = ReturnDocument.After }; var updatedEntity = await GetCollection <FlowGraphItem>(CollectionNames.DrawFlowGraphs).FindOneAndReplaceAsync(filter, item, options); return(updatedEntity._id != ObjectId.Empty.ToString()); } catch (Exception ex) { logger.LogError(ex, string.Empty); return(false); } }