Ejemplo n.º 1
0
        public void GetUserByUserName()
        {
            var response   = Task.FromResult(_stringConstant.UserDetailsFromOauthServer);
            var requestUrl = string.Format("{0}{1}", _stringConstant.LoginUserDetail, _stringConstant.TestUserName);

            _mockHttpClient.Setup(x => x.GetAsync(_stringConstant.UserUrl, requestUrl, _stringConstant.TestAccessToken)).Returns(response);
            var userDetails = _projectUserRepository.GetUserByUserName(_stringConstant.TestUserName, _stringConstant.TestAccessToken).Result;

            Assert.Equal(userDetails.UserName, _stringConstant.TestUserName);
        }
        /// <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);
        }