예제 #1
0
        public async Task <IActionResult> Index()
        {
            var model = new EmployeesListModel
            {
                Employees = (await this.employeeService.GetBySearchCriteriaAsync <EmployeesViewModel>(new EmployeesViewModel())).ToHashSet(),
            };

            return(this.View(model));
        }
예제 #2
0
        public async Task <IActionResult> Index(string name, string jobTitle, string department, DateTime?joinedOn)
        {
            var searchedCriteria = new EmployeesViewModel
            {
                Name       = name,
                JobTitle   = jobTitle,
                Department = department,
                JoinedOn   = joinedOn,
            };
            var model = new EmployeesListModel
            {
                Employees = (await this.employeeService.GetBySearchCriteriaAsync <EmployeesViewModel>(searchedCriteria)).ToHashSet(),
            };

            return(this.View(model));
        }
예제 #3
0
        public IActionResult Index(bool groupByDepartment = true)
        {
            var model = new DepartmentEmployeeModel
            {
                GroupByDepartment = groupByDepartment
            };

            var employesModel = new EmployeesListModel {
                Department = new DepartmentModel {
                    Name = ""
                }
            };

            var emailCount = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var d in _employeeService.GetOrderedDepartments(showUnpublished: false))
            {
                if (groupByDepartment)
                {
                    employesModel = new EmployeesListModel {
                        Department = d.ToModel()
                    };
                }
                foreach (var employee in _employeeService.GetEmployeesByDepartmentId(d.Id, showUnpublished: false))
                {
                    var e = employee.ToModel();

                    if (emailCount.ContainsKey(e.Email))
                    {
                        emailCount[e.Email]++;
                    }
                    else
                    {
                        emailCount[e.Email] = 1;
                    }

                    e.PhotoUrl            = GetPictureUrl(e.PictureId);
                    e.DepartmentPublished = d.Published;
                    e.DepartmentName      = d.Name;

                    employesModel.Employees.Add(e);
                }
                if (groupByDepartment)
                {
                    // The Model is a list of departments each with a list of employees
                    model.EmployeesList.Add(employesModel);
                }
            }
            if (!groupByDepartment)
            {
                // The Model is a single-entry list (empty department) with a list of all employees
                model.EmployeesList.Add(employesModel);
            }

            foreach (var employeeList in model.EmployeesList)
            {
                foreach (var employee in employeeList.Employees)
                {
                    employee.HasUniqueEmail = emailCount[employee.Email] == 1;
                }
            }

            if (_permissionService.Authorize(EmployeePermissionProvider.ManageEmployees))
            {
                DisplayEditLink(Url.Action(nameof(List), ControllerName, new { area = "Admin" }));
            }

            return(View($"{Route}{nameof(Index)}.cshtml", model));
        }