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(); } }
public EmployeesDataContext GetDataContext(out string error) { EmployeesDataContext dataContext = new EmployeesDataContext(); error = null; dataContext.modelNotifiedForEmployeesMain = GetAllEmployees(out error); dataContext.modelNotifiedForEmployees = GetAll_Employees(out error); dataContext.PopulateComboBoxesItemSource(); this.LoadNxNComboFor_EmployeeTerritories(dataContext, out error); return(dataContext); }