I'm trying to come up with realizing "changes validator".
I'm using Entity framework at back-end and angular at front-end.
Communication via WebApi.
For many reason client send me List<DepartmentSettingDto>
and other properties to my controller.
This list can contains many objects which can be unmodified from user.
So, I dont want to update database if DepartmentSetting
has no changes with data from db.
I want to have something like this:
public void UpdateDepartmentsSettings(DepatmentsSettingsDto depatmentsSettings)
{
using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew
, new TransactionOptions {IsolationLevel = IsolationLevel.Serializable}))
{
foreach (var departmentSetting in DepatmentsSettingsDto.DepartmentSettings)
{
var currentSetting = _context.DepartmentSettings.Find(departmentSetting.Id)
if departmentSetting.Modified(currentSetting)
{
var newSetting = Mapper.Map<DepartmentSettingDto, DepartmentSetting>
(departmentSetting, currentSetting);
Mapper.Map(currentSetting, newSetting);
}
}
_context.SaveChanges();
transaction.Complete();
}
}
Is it possible to write an extension method or something like this to avoid saving unmodified changes? Thanks in advance!