Пример #1
0
        public void GetProjectUsersByTeamLeaderId()
        {
            var response   = Task.FromResult(_stringConstant.ProjectUsers);
            var requestUrl = string.Format("{0}{1}", _stringConstant.ProjectUsersByTeamLeaderId, _stringConstant.EmployeeIdForTest);

            _mockHttpClient.Setup(x => x.GetAsync(_stringConstant.ProjectUrl, requestUrl, _stringConstant.TestAccessToken)).Returns(response);
            var userName = _stringConstant.EmptyString;
            var users    = _projectUserRepository.GetProjectUsersByTeamLeaderId(_stringConstant.EmployeeIdForTest, _stringConstant.TestAccessToken).Result;

            foreach (var user in users)
            {
                userName = user.UserName;
            }
            Assert.Equal(userName, _stringConstant.FirstUserName);
        }
        /// <summary>
        /// Method that returns the list of employees with their leave status based on their roles
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="userName"></param>
        /// <returns>List of employees with leave status based on roles</returns>
        public async Task <IEnumerable <LeaveReport> > LeaveReport(string accessToken, string userName)
        {
            List <LeaveRequest> leaveRequests = _leaveRequest.GetAll().ToList();

            User loginUser = await _projectUserCall.GetUserByUserName(userName, accessToken);

            if (loginUser.Role.Equals(_stringConstant.Admin))
            {
                List <LeaveRequest> distinctLeaveRequests = leaveRequests.GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
                List <LeaveReport>  leaveReports          = await GetLeaveReportList(distinctLeaveRequests, accessToken);

                return(leaveReports);
            }
            else if (loginUser.Role.Equals(_stringConstant.Employee))
            {
                List <LeaveRequest> distinctLeaveRequests = leaveRequests.FindAll(x => x.EmployeeId == loginUser.Id);
                List <LeaveReport>  leaveReports          = await GetLeaveReportList(distinctLeaveRequests, accessToken);

                return(leaveReports);
            }
            if (loginUser.Role.Equals(_stringConstant.TeamLeader))
            {
                List <User> projectUsers = await _projectUserCall.GetProjectUsersByTeamLeaderId(loginUser.Id, accessToken);

                List <LeaveReport> leaveReports = new List <LeaveReport>();
                foreach (var projectUser in projectUsers)
                {
                    List <LeaveRequest> distinctLeaveRequests = leaveRequests.Where(x => x.EmployeeId.Contains(projectUser.Id)).GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
                    List <LeaveReport>  leaveReport           = await GetLeaveReportList(distinctLeaveRequests, accessToken);

                    leaveReports.AddRange(leaveReport);
                }
                return(leaveReports);
            }
            return(null);
        }