Exemplo n.º 1
0
        private IList <NameItem> GetEmployeeList(int?exceptId)
        {
            IList <EmployeeModel> employees;

            using (HumanResourceEntities db = new HumanResourceEntities())
            {
                employees = (from b in db.Employees
                             where (exceptId == null || exceptId != b.Id) && b.EndDate == null // проверяем, что сотрудник не уволился
                             select new EmployeeModel
                {
                    Id = b.Id,
                    Surname = b.Surname,
                    Name = b.Name,
                    Patronymic = b.Patronymic
                }).OrderBy(e => e.Surname).ThenBy(e => e.Name).ToList();
            }

            IList <NameItem> list = new List <NameItem>();

            list.Insert(0, new NameItem()
            {
                Id = null, Name = string.Empty
            });
            foreach (var m in employees)
            {
                list.Add(new NameItem()
                {
                    Id = m.Id, Name = EmployeeModel.GetDisplayName(m.Surname, m.Name, m.Patronymic)
                });
            }
            return(list);
        }