public List <DeptViewModel> GetDepartments() { List <Department> depts = commonContext.GetAllDepartments(); // await Task.Run(() => commonContext.GetAllDepartments() ); List <DeptViewModel> deptViewModels = depts.Select(p => new DeptViewModel(p)).ToList(); return(deptViewModels); }
public async Task <IActionResult> GetRatings(int empId) { Employee employee = empContext.GetEmployee(empId); int empRate = 0; if (employee != null) { RatingViewModel rVM = null; if (employee.EmpAvgRating.HasValue) { empRate = (int)employee.EmpAvgRating; } // Get all Emp of his dept List <Employee> empsOfDept = await empContext.GetEmployeesOfDeptAsync(employee.DeptId); List <EmpRateModel> empVMDepts = new List <EmpRateModel>(); //empsOfDept.ConvertAll<EmployeeViewModel>(e => new EmployeeViewModel(e)); foreach (Employee e in empsOfDept) { empVMDepts.Add(new EmpRateModel() { EmployeeId = e.EmployeeId, EmpName = e.FirstName + " " + e.LastName, Email = e.Email, EmpAvgRating = e.EmpAvgRating, DeptId = e.DeptId }); } // Get all Dept Ratings List <Department> depts = commonContext.GetAllDepartments(); List <DeptRateModel> deptVMList = new List <DeptRateModel>(); //depts.ConvertAll<DeptViewModel>(d => new DeptViewModel(d)); foreach (Department d in depts) { deptVMList.Add(new DeptRateModel() { DeptId = d.DeptId, DeptName = d.DeptName, DeptAvgRating = d.DeptAvgRating }); } empsOfDept = null; depts = null; rVM = new RatingViewModel(empRate, empVMDepts, deptVMList); return(Ok(rVM)); } else { return(NotFound("Employee with Id: {employeeId} not found. Provide valid Id of Employee")); } }