Hi,
I am implementing a ContactManager, where a Contact is linked to a Company. Once the Contact has been created, the company should no longer be allowed to change.
I have implemented the following method in ContactManager to achieve this validation:
protected async Task<IdentityResult> CheckCompanyUnchanged(int id, int companyId)
{
var contact = await _contactRepository.FirstOrDefaultAsync(c => c.Id == id);
if (contact != null && contact.CompanyId != companyId)
{
return AbpIdentityResult.Failed(string.Format(L("ContactCompanyChanged")));
}
return IdentityResult.Success;
}
The problem I am having is that when fetching the Contact to make the comparrison, it contains the updated company value rather than the original one due to entity tracking. Is there a way to access the original values from the Core project? I know this can be done via the dbContext, but have no access to this.
3 Answer(s)
-
0
Hi,
Maybe, you can do it with a custom repository, it allows you to access DbContext in it <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Repositories#custom-repositories">https://aspnetboilerplate.com/Pages/Doc ... positories</a>.
-
0
Thank you. Managed to find a solution using a custom repository.
-
0
Great :)