public async Task <bool> UpdateManyAsync(Predicate <T> filter, dynamic item) { bool UpdateAction(List <T> data) { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } foreach (var toUpdate in matches) { ObjectExtensions.CopyProperties(item, toUpdate); } return(true); }; if (!ExecuteLocked(UpdateAction, _data.Value)) { return(false); } return(await _commit(_path, UpdateAction, true).ConfigureAwait(false)); }
private Task <bool> Update(string key, dynamic item, bool isAsync = false) { (bool, JObject) UpdateAction() { if (_jsonData[key] == null) { return(false, _jsonData); } var toUpdate = SingleDynamicItemReadConverter(_jsonData[key]); if (ObjectExtensions.IsReferenceType(item) && ObjectExtensions.IsReferenceType(toUpdate)) { ObjectExtensions.CopyProperties(item, toUpdate); _jsonData[key] = JToken.FromObject(toUpdate); } else { _jsonData[key] = JToken.FromObject(item); } return(true, _jsonData); } return(CommitItem(UpdateAction, isAsync)); }
public async Task <bool> ReplaceOneAsync(Predicate <T> filter, T item, bool upsert = false) { bool UpdateAction(List <T> data) { var matches = data.Where(e => filter(e)); if (!matches.Any()) { if (!upsert) { return(false); } var newItem = _createNewInstance(); ObjectExtensions.CopyProperties(item, newItem); data.Add(_insertConvert(newItem)); return(true); } var index = data.IndexOf(matches.First()); data[index] = item; return(true); }; if (!ExecuteLocked(UpdateAction, _data.Value)) { return(false); } return(await _commit(_path, UpdateAction, true).ConfigureAwait(false)); }
public bool UpdateOne(Predicate <T> filter, dynamic item) { bool UpdateAction(List <T> data) { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } var toUpdate = matches.First(); ObjectExtensions.CopyProperties(item, toUpdate); return(true); }; if (!ExecuteLocked(UpdateAction, _data.Value)) { return(false); } return(_commit(_path, UpdateAction, false).Result); }
public async Task <bool> UpdateManyAsync(Predicate <T> filter, dynamic item) { var updateAction = new Func <List <T>, bool>(data => { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } foreach (var toUpdate in matches) { ObjectExtensions.CopyProperties(item, toUpdate); } return(true); }); if (!updateAction(_data.Value)) { return(false); } return(await _commit(_path, updateAction, true).ConfigureAwait(false)); }
public bool ReplaceOne(Predicate <T> filter, T item, bool upsert = false) { var updateAction = new Func <List <T>, bool>(data => { var matches = data.Where(e => filter(e)); if (!matches.Any()) { if (!upsert) { return(false); } var newItem = _createNewInstance(); ObjectExtensions.CopyProperties(item, newItem); data.Add(_insertConvert(newItem)); return(true); } var index = data.IndexOf(matches.First()); data[index] = item; return(true); }); if (!updateAction(_data.Value)) { return(false); } return(_commit(_path, updateAction, false).Result); }
public bool UpdateMany(Predicate <T> filter, dynamic item) { var updateAction = new Func <List <T>, bool>(data => { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } foreach (var toUpdate in matches) { ObjectExtensions.CopyProperties(item, toUpdate); } return(true); }); if (!ExecuteLocked(updateAction, _data.Value)) { return(false); } return(_commit(_path, updateAction, false).Result); }
public bool UpdateOne(Predicate <T> filter, dynamic item) { var updateAction = new Func <List <T>, bool>(data => { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } var toUpdate = matches.First(); ObjectExtensions.CopyProperties(item, toUpdate); return(true); }); if (!updateAction(_data.Value)) { return(false); } return(_commit(_path, updateAction, false).Result); }
public async Task <bool> UpdateOneAsync(Predicate <T> filter, dynamic item) { var updateAction = new Func <List <T>, bool>(data => { var matches = data.Where(e => filter(e)); if (!matches.Any()) { return(false); } var toUpdate = matches.First(); ObjectExtensions.CopyProperties(item, toUpdate); return(true); }); if (!ExecuteLocked(updateAction, _data.Value)) { return(false); } return(await _commit(_path, updateAction, true).ConfigureAwait(false)); }