Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get all itens to populate NXN relation used in ComboNxNEmployeeTerritories
        /// </summary>
        public List <ModelNotifiedForEmployeeTerritories> GetAllEmployeeTerritories(int EmployeeID, out string error)
        {
            error = null;
            try
            {
                EmployeeTerritoriesBsn  bsn    = new EmployeeTerritoriesBsn(wpfConfig);
                EmployeeTerritoriesInfo filter = new EmployeeTerritoriesInfo();
                filter.EmployeeID = EmployeeID;

                List <EmployeeTerritoriesInfo>             dbItems       = bsn.GetSome(filter);
                List <ModelNotifiedForEmployeeTerritories> notifiedItems = new List <ModelNotifiedForEmployeeTerritories>();

                foreach (EmployeeTerritoriesInfo dbItem in dbItems)
                {
                    ModelNotifiedForEmployeeTerritories itemToAdd = new ModelNotifiedForEmployeeTerritories();
                    Cloner.CopyAllTo(typeof(EmployeeTerritoriesInfo), dbItem, typeof(ModelNotifiedForEmployeeTerritories), itemToAdd);
                    itemToAdd.ItemChanged = false;
                    notifiedItems.Add(itemToAdd);
                }

                return(notifiedItems);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            return(null);
        }