private void LoadNxNComboFor_EmployeeTerritories(EmployeesDataContext dataContext, out string error) { List <ModelNotifiedForTerritories> allTerritories = GetAllTerritories(out error); if (dataContext == null) { return; } foreach (ModelNotifiedForEmployees item in dataContext.modelNotifiedForEmployeesMain) { List <ModelNotifiedForEmployeeTerritories> listEmployeeTerritories = GetAllEmployeeTerritories(item.EmployeeID, out error); List <ModelNotifiedForTerritories> comboItens = new List <ModelNotifiedForTerritories>(); foreach (ModelNotifiedForTerritories item2 in allTerritories) { ModelNotifiedForEmployeeTerritories aux = listEmployeeTerritories.Where(x => x.TerritoryID == item2.TerritoryID).FirstOrDefault(); bool existsInDB = (aux != null); ModelNotifiedForTerritories newComboItem = new ModelNotifiedForTerritories(); Cloner.CopyAllTo(typeof(ModelNotifiedForTerritories), item2, typeof(ModelNotifiedForTerritories), newComboItem); if (existsInDB) { newComboItem.Check_Status = true; } else { newComboItem.Check_Status = false; } newComboItem.ItemChanged = false; comboItens.Add(newComboItem); } item.LookDownComboDataTerritories = comboItens.OrderBy(x => x.TerritoryDescription).ToList(); } }
/// <summary> /// Get all LookUp itens to populate NXN relation used in ComboNxNEmployeeTerritories /// </summary> public List <ModelNotifiedForTerritories> GetAllTerritories(out string error) { error = null; try { TerritoriesBsn bsn = new TerritoriesBsn(wpfConfig); List <TerritoriesInfo> dbItems = bsn.GetAll(); List <ModelNotifiedForTerritories> notifiedItems = new List <ModelNotifiedForTerritories>(); foreach (TerritoriesInfo dbItem in dbItems) { ModelNotifiedForTerritories itemToAdd = new ModelNotifiedForTerritories(); Cloner.CopyAllTo(typeof(TerritoriesInfo), dbItem, typeof(ModelNotifiedForTerritories), itemToAdd); itemToAdd.ItemChanged = false; notifiedItems.Add(itemToAdd); } return(notifiedItems); } catch (Exception ex) { error = ex.Message; } return(null); }