Today I noticed that if I scaffold for exemple table Customer,
In the created controller Put method, it calls OnCustomerUpdated and then OnAfterCustomerUpdated but in the Patch method, it only calls OnCustomerUpdated but not OnAfterCustomerUpdated. I am wondering what is the reason for that.
Here is what I mean, you see partial methods that can be implemented later.
the call to both is included in PUT but not PATCH.
I could add it manually but if i do this for 30 controllers then I will have to manually reapply the change everytime I rescaffold the db.
partial void OnProductMappingUpdated(AciRadzen.Server.Models.aci.ProductMapping item);
partial void OnAfterProductMappingUpdated(AciRadzen.Server.Models.aci.ProductMapping item);
[HttpPut("/odata/aci/ProductMappings(id={id})")]
[EnableQuery(MaxExpansionDepth=10,MaxAnyAllExpressionDepth=10,MaxNodeCount=1000)]
public IActionResult PutProductMapping(int key, [FromBody]AciRadzen.Server.Models.aci.ProductMapping item)
{
try
{
if(!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (item == null || (item.id != key))
{
return BadRequest();
}
this.OnProductMappingUpdated(item);
this.context.ProductMappings.Update(item);
this.context.SaveChanges();
var itemToReturn = this.context.ProductMappings.Where(i => i.id == key);
this.OnAfterProductMappingUpdated(item);
return new ObjectResult(SingleResult.Create(itemToReturn));
}
catch(Exception ex)
{
ModelState.AddModelError("", ex.Message);
return BadRequest(ModelState);
}
}
[HttpPatch("/odata/aci/ProductMappings(id={id})")]
[EnableQuery(MaxExpansionDepth=10,MaxAnyAllExpressionDepth=10,MaxNodeCount=1000)]
public IActionResult PatchProductMapping(int key, [FromBody]Delta<AciRadzen.Server.Models.aci.ProductMapping> patch)
{
try
{
if(!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var item = this.context.ProductMappings.Where(i => i.id == key).FirstOrDefault();
if (item == null)
{
return BadRequest();
}
patch.Patch(item);
this.OnProductMappingUpdated(item);
this.context.ProductMappings.Update(item);
this.context.SaveChanges();
var itemToReturn = this.context.ProductMappings.Where(i => i.id == key);
//missing call to this.OnAfterProductMappingUpdated(item); ????
return new ObjectResult(SingleResult.Create(itemToReturn));
}
catch(Exception ex)
{
ModelState.AddModelError("", ex.Message);
return BadRequest(ModelState);
}
}
Thanks! Will be fixed in our next update!.
1 Like