Exemplo n.º 1
0
        /// <summary>
        /// Reads all records grouped by their department name
        /// </summary>
        /// <returns>The returned grouped collection</returns>
        public string RecordsGroupedByDepartment()
        {
            string final   = "";
            var    toGroup = EmployeeData.Select(emp => new
            {
                FirstName  = emp.FirstName,
                LastName   = emp.LastName,
                Email      = emp.Email,
                Phone      = emp.PhoneNumber,
                HireDate   = emp.HireDate.ToLongDateString(),
                Salary     = emp.Salary,
                Department = (emp.DepartmentId == null) ? null : DepartmentData.First(dept => dept.DepartmentId == emp.DepartmentId).DepartmentName
            }).GroupBy(item => item.Department).ToList();

            toGroup.ForEach(group =>
            {
                //string key = group.Key == null ? "Null" : group.Key;
                final += "\n Department - " + (@group.Key ?? "Null") + ":\n";
                final += " FirstName || LastName || Email || PhoneNumber || HireDate || Salary || Department\n";

                group.ToList().ForEach(item =>
                {
                    final += $" {item.FirstName}    {item.LastName}     {item.Email}    {item.Phone}    {item.HireDate} {item.Salary}   {item.Department} \n";
                });
            });

            return(final);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads all employees and their Departments, both null and not null
        /// </summary>
        /// <returns>The returned collection</returns>
        public IEnumerable AllEmployeesWithDepartments()
        {
            //EmployeeContext context = new EmployeeContext();
            //return context.Employees.Include(d => d.Department.DepartmentName).ToList();
            //return context.Database.ExecuteSqlRaw("SELECT FirstName, DepartmentName FROM Employees FULL JOIN Departments ON Employees.DepartmentId = Departments.DepartmentId").ToString();//.ToList();

            return(EmployeeData.Select(emp => new
            {
                FirstName = emp.FirstName,
                LastName = emp.LastName,
                Department = (emp.DepartmentId == null) ? null : DepartmentData.First(dept => dept.DepartmentId == emp.DepartmentId).DepartmentName
            }));
        }
Exemplo n.º 3
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Reads all record with their department name
 /// </summary>
 /// <returns>The returned record collection</returns>
 public IEnumerable AllRecordsWithDepartmentName()
 {
     return(EmployeeData.Select(emp => new
     {
         FirstName = emp.FirstName,
         LastName = emp.LastName,
         Email = emp.Email,
         Phone = emp.PhoneNumber,
         HireDate = emp.HireDate.ToLongDateString(),
         Salary = emp.Salary,
         Department = (emp.DepartmentId == null) ? null : DepartmentData.First(dept => dept.DepartmentId == emp.DepartmentId).DepartmentName
     }));
 }