Beispiel #1
0
        public List <Company> FindCompany(SearchDefiniton search)
        {
            var result    = new List <Company>();
            var byKeyword = search.Keyword != null?Ctx.Companies.Include(c => c.Employees).Where(c => c.Name.Contains(search.Keyword) ||
                                                                                                 c.Employees.Any(e => e.FirstName.Contains(search.Keyword) || e.LastName.Contains(search.Keyword))).ToList()
                                : null;

            if (byKeyword != null)
            {
                result.AddRange(byKeyword);
            }

            if (search.EmployeeDateOfBirthFrom != null && search.EmployeeDateOfBirthTo != null)
            {
                var byBirthRange = Ctx.Companies.Include(c => c.Employees).Where(c => c.Employees.Any(e => e.DateOfBirth > search.EmployeeDateOfBirthFrom && e.DateOfBirth < search.EmployeeDateOfBirthTo));
                if (byBirthRange != null)
                {
                    result.AddRange(byBirthRange);
                }
            }
            else if (search.EmployeeDateOfBirthFrom != null || search.EmployeeDateOfBirthTo != null)
            {
                var byBirthDate = Ctx.Companies.Include(c => c.Employees).Where(c => c.Employees.Any(e => e.DateOfBirth > search.EmployeeDateOfBirthFrom || e.DateOfBirth < search.EmployeeDateOfBirthTo));
                if (byBirthDate != null)
                {
                    result.AddRange(byBirthDate);
                }
            }
            var byJobTitle = search.EmployeeJobTitle != null?Ctx.Companies.Include(c => c.Employees).Where(c => c.Employees.Any(e => search.EmployeeJobTitle.Contains(e.JobTitle.ToString()))) : null;

            if (byJobTitle != null)
            {
                result.AddRange(byJobTitle);
            }

            return(result.Distinct().ToList());
        }
Beispiel #2
0
        public IActionResult Search(SearchDefiniton search)
        {
            var result = Db.FindCompany(search);

            return(Ok(result));
        }