βHooks & Events
Custom before / after hooks make even more advanced APIs possible
[Api("/people")]
public class Person : IObjectBase<int>, IBeforeCreate<Person>, IAfterUpdate<Person>
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime DateOfBirth { get; set; }
public async Task<Person> AfterUpdate(Person newItem, Person oldItem, IApplicationDataService<GenericDbContext, AuthDbContext> data)
{
using(var client = new HttpClient())
{
await client.PostAsync("someUrl", newItem);
}
}
public Task<Person> BeforeCreate(Person newItem, IApplicationDataService<GenericDbContext, AuthDbContext> data)
{
// lets make sure the date of birth is correct!
if (newItem.DateOfBirth < new DateTime(1900, 01, 01))
{
newItem.DateOfBirth = DateTime.MinValue;
}
return Task.FromResult(newItem);
}
}Last updated