public void AddRelationColumnHeadersClient(ObservableCollection<ColumnHeader> columnHeaders, Client client) { Client clientInDB = dbContext.Clients.Include("ColumnHeaderClients").Where(c => c.Id == client.Id).FirstOrDefault(); foreach (var ch in columnHeaders) { var newColumnHeaderClient = new ColumnHeaderClient { ClientId = client.Id, ColumnHeaderId = ch.Id, Changed = DateTime.Now, SaveToDB = true }; if (!clientInDB.ColumnHeaderClients.Any(colh => colh.ColumnHeaderId == newColumnHeaderClient.ColumnHeaderId && colh.ClientId == newColumnHeaderClient.ClientId)) clientInDB.ColumnHeaderClients.Add(newColumnHeaderClient); } dbContext.SaveChanges(); }
internal RelatedClientInfo RelatedClientsContainClient(Client client, ICollection<RelatedClientInfo> clientList) { return clientList.FirstOrDefault(c => c.Client.Id == client.Id); }