private RecordPatch RecordToPatch(Record record) { RecordPatch patch = new RecordPatch(); patch.Key = record.Key; patch.Value = record.Value; patch.SyncCount = record.SyncCount; patch.Op = (record.Value == null ? Operation.Remove : Operation.Replace); return(patch); }
private static RecordPatch RecordToPatch(Record record) { RecordPatch patch = new RecordPatch(); patch.DeviceLastModifiedDate = record.DeviceLastModifiedDate.Value; patch.Key = record.Key; patch.Value = record.Value; patch.SyncCount = record.SyncCount; patch.Op = (record.Value == null ? Operation.Remove : Operation.Replace); return(patch); }
private static RecordPatch RecordToPatch(Record record) { var patch = new RecordPatch { deviceLastModifiedDate = SdkUtils.ConvertToUnixEpochMilliSeconds(record.DeviceLastModifiedDate), key = record.Key, value = record.Value }; return(patch); }
public async Task PatchAsync(int recordId, RecordPatch recordPatch) { var userId = await GetUserIdAsync(); var entity = await _repository.GetRecordAsync(recordId); await InvokeGuard(() => _guard.AgainstInvalidRecordPatchAsync(userId, entity.DatasetId, recordPatch)); _mapper.Patch(entity, recordPatch); await _unitOfWork.SaveChangesAsync(); }
public async Task <ActionResult> PatchAsync(int recordId, [FromBody] RecordPatch recordPatch) { try { await _recordService.PatchAsync(recordId, recordPatch); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public void Patch(RecordEntity entity, RecordPatch patch) { if (patch.DateTime.HasValue) { entity.DateTime = patch.DateTime.Value; } if (patch.Properties is not null) { foreach (var seriesId in patch?.Properties.Keys) { if (patch.Properties.TryGetValue(seriesId, out decimal? outValue)) { var property = entity.Properties.SingleOrDefault(z => z.SeriesId == seriesId); if (property is null) { // Add entity.Properties.Add(new() { SeriesId = seriesId, Value = outValue.Value.ToString() }); } else if (outValue.HasValue) { // Update property.Value = outValue.Value.ToString(); } else { // Remove entity.Properties.Remove(property); } } } } }
public async Task <ValidationResult> AgainstInvalidRecordPatchAsync(int?userId, int datasetId, RecordPatch patch) { var result = new ValidationResult(); if (userId.HasValue) { await _userValidator.UserOwnsDatasetAsync(userId.Value, datasetId, result); } if (patch.Properties != null && patch.Properties.Keys.Count > 0) { await _datasetValidator.DatasetContainsSeriesAsync(datasetId, new List <int>(patch.Properties.Keys), result); foreach (var property in patch.Properties) { if (property.Value.HasValue) { await _propertyValidator.PropertyValueIsValid(property.Key, property.Value.Value, result); } } } return(result); }