I have this Complex Type included in my entity class, such as:
public class Logbook
{
public string CreatedBy { get; set; }
public DateTimeOffset DateCreated { get; set; }
public string ModifiedBy { get; set; }
public DateTimeOffset DateModified { get; set; }
}
Then my main class:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public Logbook Logbook { get; set; }
}
I then set class Logbook as a complex type. My question is, I'm wondering on how to set the values in Logbook as soon as Customer entity is inserted/modified? Say, set the DateCreated to DateTime.UtcNow and set CreatedBy to a user's name.. And so on. Any help would be much appreciated. Thanks!
EDIT:
I'm using Entity Framework for my data access. And this is how I save my Customer
public ActionResult Create(Customer customer)
{
if ( Model.IsValid() )
{
_customerRepository.Insert(customer);
return View("Index");
}
return View(customer);
}