예제 #1
0
        /// <summary>
        /// Method that returns leave report based on the role of logged in user
        /// </summary>
        /// <param name="userId">userId of user</param>
        /// <returns>list of Leave report</returns>
        public async Task <IEnumerable <LeaveReport> > LeaveReportAsync(string userId)
        {
            //Get all approved leave requests
            List <LeaveRequest> leaveRequests = _leaveRequest.GetAll().ToList().FindAll(x => x.Status.Equals(Condition.Approved));
            List <LeaveReport>  leaveReports  = new List <LeaveReport>();

            //Get details of logged in user
            User loginUser = await GetEmployeeByIdAsync(userId);

            //Check if there exists any approved leave request
            if (leaveRequests.Any())
            {
                //Return leave report as per the role of logged in user
                //For admin, leave report of all the employees
                if (loginUser.Role.Equals(_stringConstant.Admin))
                {
                    List <LeaveRequest> distinctLeaveRequests = leaveRequests.GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
                    leaveReports = await GetLeaveReportListAsync(distinctLeaveRequests);
                }
                //For teamleader, leave report of all the team member(s)
                else
                {
                    var projectUsers = await _oauthCallsRepository.GetListOfEmployeeAsync(loginUser.Id);

                    foreach (var projectUser in projectUsers)
                    {
                        List <LeaveRequest> distinctLeaveRequests = leaveRequests.Where(x => x.EmployeeId.Contains(projectUser.UserId)).GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
                        List <LeaveReport>  leaveReport           = await GetLeaveReportListAsync(distinctLeaveRequests);

                        leaveReports.AddRange(leaveReport);
                    }
                }
            }
            return(leaveReports);
        }
 /// <summary>
 /// Getting user information
 /// </summary>
 /// <param name="loginId"></param>
 /// <returns>fetch users role</returns>
 private async Task <List <UserRoleAc> > GetUserRoleAsync(string loginId)
 {
     //getting user information from Promact Oauth Server
     return(await _oauthCallsRepository.GetListOfEmployeeAsync(loginId));
 }