private void UpdateCollectionServices(User user, List<Service> services) { db.Entry(user).Collection(a => a.Services).Load(); var tmpServices=user.Services.ToList(); foreach (var service in tmpServices) { if (!services.Any(a => a.Id == service.Id)) { user.Services.Remove(service); } } foreach (var service in services) { if (!user.Services.Any(a => a.Id == service.Id)) { user.Services.Add(service); } } db.SaveChanges(); }
private void UpdateCollectionPostes(User user, List<PosteTravail> postes) { db.Entry(user).Collection(a => a.PosteTravails).Load(); var tmpPostes = user.PosteTravails.ToList(); foreach (var poste in tmpPostes) { if (!postes.Any(a => a.Id == poste.Id)) { user.PosteTravails.Remove(poste); } } foreach (var poste in postes) { if (!user.PosteTravails.Any(a => a.Id == poste.Id)) { user.PosteTravails.Add(poste); } } db.SaveChanges(); }