I’m enjoying the simplicity of autoCRUD and wondering if there is a way to use the AutoPopulate attribute to set a property from two properties in the request DTO.
Specifically, the request DTO includes Latitude and Longitude properties, but the db insert is using a custom converter to the postgres GIS type geometry. So my entity DTO is using the .net Point type from the NTS extensions for GIS.
What would be nice is to be able to use the AutoPopulate to do a new Point(new Position(Latitude,Longitude)) to set the property.
I know it’s a long shot.
I’ve currently implemented a custom service to handle it but you know…
#Script has a lot of .NET integration capabilities in Scripting .NET which shows how to create instances and call constructors however I’d recommend instead adding your own Script Methods in your AppHost.Configure(), e.g:
public class MyScriptMethods : ScriptMethods
{
public Point toPosition(IRequest req) => ...;
}
//...
ScriptContext.ScriptMethods.Add(new MyScriptMethods());
Then have your AutoPopulate expression call your C# method instead passing in Request for the IRequest or Request.Dto for the Request DTO.
public class GisScriptMethods: ScriptMethods
{
public Point? toPosition(IRequest request)
{
if (request.Dto is not IHaveGisRequestModel r) return null;
if (r.Latitude.HasValue && r.Longitude.HasValue)
return new Point(new Position(r.Latitude.Value, r.Longitude.Value, r.Altitude));
return null;
}
}