public IHttpActionResult Patch(Delta<SampleModel> delta) { // Using the Patch method on Delta<T>, will only overwrite only the properties whose value has // changed. var model = new SampleModel(); delta.Patch(model); // Using Delta doesn't invoke validation on the values that are provided, so use the Validate method // on the model object after patching to validate it. this.Validate(model); if (!ModelState.IsValid) { return BadRequest(ModelState); } var builder = new StringBuilder(); builder.AppendLine("Updated Properties:"); foreach(var property in delta.GetChangedPropertyNames()) { object value; delta.TryGetPropertyValue(property, out value); builder.AppendLine(String.Format("\t{0} : {1}", property, value)); } return Text(builder.ToString()); }
public void CanChangeDerivedClassProperties() { // Arrange dynamic delta = new Delta <Base>(typeof(Derived)); // Act delta.DerivedInt = 10; // Assert Assert.Equal(delta.GetChangedPropertyNames(), new[] { "DerivedInt" }); }
public IHttpActionResult Patch([FromODataUri] int key, Delta<Product> patch) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Delta<V2VM.Product> v2Patch = new Delta<V2VM.Product>(); foreach (string name in patch.GetChangedPropertyNames()) { object value; if (patch.TryGetPropertyValue(name, out value)) { v2Patch.TrySetPropertyValue(name, value); } } var v2Product = _repository.Patch((long)key, v2Patch, Request); return Updated(Mapper.Map<Product>(v2Product)); }
public void CanChangeDerivedClassProperties() { // Arrange dynamic delta = new Delta<Base>(typeof(Derived)); // Act delta.DerivedInt = 10; // Assert Assert.Equal(delta.GetChangedPropertyNames(), new[] { "DerivedInt" }); }