protected override void SaveChanges(Context context, RecordModel record = null) { base.SaveChanges(context, record); if (record == null) { return; } var users = new System.Collections.Generic.HashSet <AspNetUsers>(); foreach (var group in record.ApplicationGroups) { foreach (var user in group.AspNetUsers) { users.Add(user); } } foreach (var user in users) { if (AspNetUsersHub.SyncUserRoles(user)) { AddChange("AspNetUsers", "change", user.Id); base.SaveChanges(context, record); } } }
// Notificar todos los objetos foráneos que han sido afectados por el cambio protected override void AddForeignChanges(Context context, string change, RecordModel record, Record oldRecord = null) { var rolesKeys = record.AspNetRoles.Select(r => r.Id); var usersKeys = record.AspNetUsers.Select(r => r.Id); if (oldRecord != null) { rolesKeys = rolesKeys.Union(oldRecord.AspNetRolesIds); usersKeys = usersKeys.Union(oldRecord.AspNetUsersIds); } AddChanges("AspNetRoles", "change", rolesKeys.ToList()); AddChanges("AspNetUsers", "change", usersKeys.ToList()); foreach (var userid in usersKeys) { var user = context.AspNetUsers.Find(userid); if (user != null && AspNetUsersHub.SyncUserRoles(user)) { AddChange("AspNetUsers", "change", user.Id); base.SaveChanges(context, record); } } }