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

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

            Assert.Equal(userDetails.UserName, _stringConstant.TestUserName);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to update sick leave, only admin allowed
        /// </summary>
        /// <param name="slackText"></param>
        /// <param name="user"></param>
        /// <param name="accessToken"></param>
        /// <returns>replyText</returns>
        private async Task <string> UpdateSickLeave(List <string> slackText, ApplicationUser user, string accessToken)
        {
            // checking from oAuth whether user is Admin or not
            var IsAdmin = await _projectUser.UserIsAdmin(user.UserName, accessToken);

            if (IsAdmin)
            {
                int      leaveIdType;
                DateTime dateTime;
                // checking whether string can be convert to integer or not, true then only further process will be conduct
                var leaveIdResult = int.TryParse(slackText[1], out leaveIdType);
                if (leaveIdResult)
                {
                    var leave = _leaveRepository.LeaveById(Convert.ToInt32(slackText[1]));
                    if (leave != null && leave.Type == LeaveType.sl)
                    {
                        // checking whether string can convert to date of indian culture or not, if return true then further process will be conduct
                        var firstDateConvertorResult  = DateTime.TryParseExact(slackText[2], "dd-MM-yyyy", CultureInfo.CreateSpecificCulture("hi-IN"), DateTimeStyles.None, out dateTime);
                        var secondDateConvertorResult = DateTime.TryParseExact(slackText[3], "dd-MM-yyyy", CultureInfo.CreateSpecificCulture("hi-IN"), DateTimeStyles.None, out dateTime);
                        if (firstDateConvertorResult && secondDateConvertorResult)
                        {
                            var newUser = await _projectUser.GetUserByEmployeeId(leave.EmployeeId, accessToken);

                            // convert string to date of indian culture
                            leave.EndDate    = DateTime.ParseExact(slackText[2], "dd-MM-yyyy", CultureInfo.CreateSpecificCulture("hi-IN"));
                            leave.RejoinDate = DateTime.ParseExact(slackText[3], "dd-MM-yyyy", CultureInfo.CreateSpecificCulture("hi-IN"));
                            _leaveRepository.UpdateLeave(leave);
                            replyText = string.Format("Sick leave of {0} from {1} to {2} for reason {3} has been updated, will rejoin on {4}"
                                                      , newUser.SlackUserName, leave.FromDate.ToShortDateString(), leave.EndDate.Value.ToShortDateString(),
                                                      leave.Reason, leave.RejoinDate.Value.ToShortDateString());
                            await _client.SendMessageWithoutButtonAttachmentIncomingWebhook(leave, accessToken, replyText, newUser.FirstName);

                            _client.SendSickLeaveMessageToUserIncomingWebhook(leave, user.Email, replyText, newUser);
                        }
                        else
                        {
                            // if date is not proper than date format error message will be send to user
                            replyText = _stringConstant.DateFormatErrorMessage;
                        }
                    }
                    else
                    {
                        // if sick leave will doesn't exist for leaveId
                        replyText = _stringConstant.SickLeaveDoesnotExist;
                    }
                }
                else
                {
                    // if string converting to integer return false then user will get cancel command error message
                    replyText = _stringConstant.UpdateEnterAValidLeaveId;
                }
            }
            else
            {
                // if user is not admin then this message will be show to user
                replyText = _stringConstant.AdminErrorMessageUpdateSickLeave;
            }
            return(replyText);
        }
        /// <summary>
        /// Method to get user details from the Oauth server using id and access token
        /// </summary>
        /// <param name="employeeId"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        private async Task <User> GetEmployeeById(string employeeId, string accessToken)
        {
            User user = await _projectUserCall.GetUserByEmployeeId(employeeId, accessToken);

            return(user);
        }