I have the following View Model:
namespace App.ViewModels
{
public class PersonVM
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}
...
Suppose I call a method from the controller to update a Person by sending a partial PersonVM object (some fields are set, some are null). So not all the properties of the passed in variable are set. Hence I want to loop the ones that do and update the ViewModel
//still in ViewModels namespace
public static void UpdatePerson(PersonVM p, DatabaseContext ctx){
var person = ctx.People.Where(r => r.Id == person.Id).FirstOrDefault();
for (var prop in p){
...
}
}
How can I loop over each of the set properties?