Exemplo n.º 1
0
        //社員リスト取得
        public List <EmployeeSearchOutput> getEmployees()
        {
            List <EmployeeSearchOutput> employees = new List <EmployeeSearchOutput>();

            using (sys_employeeEntities db = new sys_employeeEntities())
            {
                var query = (from e in db.employee
                             join c in db.customer
                             on e.customerId equals c.customerId into ecGroup
                             from ec in ecGroup.DefaultIfEmpty()
                             join a in db.authority
                             on e.authorityId equals a.authorityId into ecaGroup
                             from eca in ecaGroup.DefaultIfEmpty()
                             where e.leavingDate == null
                             select new
                {
                    e.employeeId,
                    e.name,
                    e.kataName,
                    e.telephoneNumber,
                    e.mailAddress,
                    customerName = ec.name,
                    entryDate = e.entryDate,
                    authority = eca.authorityName,
                    e.description
                })
                            .ToList();
                foreach (var item in query)
                {
                    EmployeeSearchOutput employee = new EmployeeSearchOutput();
                    employee.Id              = item.employeeId;
                    employee.Name            = item.name;
                    employee.KataName        = item.kataName;
                    employee.TelephoneNumber = item.telephoneNumber;
                    employee.MailAddress     = item.mailAddress;
                    employee.CustomerName    = item.customerName;
                    employee.EntryDate       = item.entryDate;
                    employee.Authority       = item.authority;
                    employee.Description     = item.description;

                    employees.Add(employee);
                }
            }

            return(employees);
        }
Exemplo n.º 2
0
        // 名前またIDで社員検索
        public List <EmployeeSearchOutput> searchEmployees(EmployeeSearchInput employeeSearchInput)
        {
            List <EmployeeSearchOutput> employees = new List <EmployeeSearchOutput>();

            using (sys_employeeEntities db = new sys_employeeEntities())
            {
                var query = (from e in db.employee
                             join c in db.customer
                             on e.customerId equals c.customerId into ecGroup
                             from ec in ecGroup.DefaultIfEmpty()
                             join a in db.authority
                             on e.authorityId equals a.authorityId into ecaGroup
                             from eca in ecaGroup.DefaultIfEmpty()
                             select new
                {
                    e.employeeId,
                    e.name,
                    e.kataName,
                    e.telephoneNumber,
                    e.mailAddress,
                    customerName = ec.name,
                    entryDate = e.entryDate,
                    authority = eca.authorityName,
                    eca.authorityId,
                    e.leavingDate,
                    e.customerId,
                    e.description
                });
                if (!string.IsNullOrWhiteSpace(employeeSearchInput.Id))
                {
                    query = query.Where(p => p.employeeId.Equals(employeeSearchInput.Id));
                }

                if (!string.IsNullOrWhiteSpace(employeeSearchInput.Name))
                {
                    query = query.Where(p => p.name.Contains(employeeSearchInput.Name));
                }

                switch (employeeSearchInput.WorkSituation)
                {
                case ConstantCommon.ZAISHA:
                    query = query.Where(p => p.leavingDate == null);
                    break;

                case ConstantCommon.TAISHA:
                    query = query.Where(p => p.leavingDate != null);
                    break;

                default:
                    break;
                }

                if (!string.IsNullOrWhiteSpace(employeeSearchInput.CustomerId))
                {
                    query = query.Where(p => p.customerId.Equals(employeeSearchInput.CustomerId));
                }

                if (!string.IsNullOrWhiteSpace(employeeSearchInput.AuthorityId))
                {
                    query = query.Where(p => p.authorityId.Equals(employeeSearchInput.AuthorityId));
                }

                query.ToList();

                foreach (var item in query)
                {
                    EmployeeSearchOutput employee = new EmployeeSearchOutput();
                    employee.Id              = item.employeeId;
                    employee.Name            = item.name;
                    employee.KataName        = item.kataName;
                    employee.TelephoneNumber = item.telephoneNumber;
                    employee.MailAddress     = item.mailAddress;
                    employee.CustomerName    = item.customerName;
                    employee.EntryDate       = item.entryDate;
                    employee.Authority       = item.authority;
                    employee.Description     = item.description;

                    employees.Add(employee);
                }
            }

            return(employees);
        }