Open rpundlik opened 6 years ago
I'm using validation in azure functions; the model is sent to the function as json to validate via a http post or a queue; it is then deserialized into a POCO that has attributes and using the models static extension method of Validate it validates returning a json of the error messages
@grahamehorner Can you pls give me example of this ? I am looking this very badly and from long days.
Thanks for the help !
/// <summary>
/// </summary>
/// <param name="instance"></param>
/// <returns></returns>
public static List<ValidationResult> Validate(EntityType instance)
=> EntityType .Validate(instance, new ValidationContext(instance, null, null));
/// <summary>
/// </summary>
/// <param name="instance"></param>
/// <param name="context"></param>
/// <returns></returns>
public static List<ValidationResult> Validate(EntityType instance, ValidationContext context)
{
var results = new List<ValidationResult>();
Validator.TryValidateObject(instance, context, results, true);
return results;
}
@grahamehorner Thanks for the help ! But how did u called this? can u give me full example of this ? It will be really good for me !
We are calling web api from angular js and in web api we are having all the models. So basically we need to send the response to angularJS pages back after validation.
@rpundlik you simply handle the json returned the same way that you would any other payload in the SPA framework of choice as the ValidationResult list is fully serialize, you dont need to do anythinv different because it is an azure function. However you do need to remember CORS
@grahamehorner So, as per my understanding I need to write validation logic in azure function and pass entire model/query string parameters from angular to azure function and return response.
@rpundlik yes; the view model that your angular application uses can be sent to the azure function, as per any web service, the response from the azure function can be the same model with error notifications; and then your angular application simply uses the response as the updated view model.
Sorry for the delay in reply, as I’m currently on holiday with family; I’ll attempt to get a sample across on my return
Hi All,
We are trying to consume azure functions in web applications.
However, we were thinking of can we use the azure functions for validation purpose in web application like POCO validation with attributes, DB validation etc.
If yes then how can we use it.
Regards, Rohit Pundlik