Exemplo n.º 1
0
        public void AccessToken()
        {
            var user = new ApplicationUser()
            {
                Email = _stringConstant.EmailForTest, UserName = _stringConstant.EmailForTest, SlackUserName = _stringConstant.FirstNameForTest
            };
            var           result       = _userManager.CreateAsync(user).Result;
            UserLoginInfo info         = new UserLoginInfo(_stringConstant.PromactStringName, _stringConstant.AccessTokenForTest);
            var           secondResult = _userManager.AddLoginAsync(user.Id, info).Result;
            var           accessToken  = _attachmentRepository.AccessToken(user.Email).Result;

            Assert.Equal(accessToken, _stringConstant.AccessTokenForTest);
        }
        public async Task <IHttpActionResult> LeaveReport()
        {
            try
            {
                var accessToken = await _attachmentRepository.AccessToken(User.Identity.Name);

                var loginUser = await _userManager.FindByNameAsync(User.Identity.Name);

                return(Ok(await _leaveReport.LeaveReport(accessToken, loginUser.UserName)));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                throw ex;
            }
        }
        public void AddNewUserFromExternalLogin()
        {
            var user        = _oAuthLoginRepository.AddNewUserFromExternalLogin(_stringConstant.EmailForTest, _stringConstant.AccessTokenForTest, _stringConstant.FirstNameForTest, _stringConstant.UserIdForTest).Result;
            var accessToken = _attachmentRepository.AccessToken(user.UserName).Result;

            Assert.Equal(user.UserName, _stringConstant.EmailForTest);
            Assert.Equal(accessToken, _stringConstant.AccessTokenForTest);
        }
Exemplo n.º 4
0
        public async Task LeaveRequest(SlashCommand leave)
        {
            SlackAction actionType;
            // method to convert slash command to list of string
            var slackText = _attachmentRepository.SlackText(leave.Text);
            // to get user details by slack user name
            var user = _userManager.FirstOrDefault(x => x.SlackUserName == leave.Username);

            if (user != null)
            {
                leave.Text.ToLower();
                // getting access token of user of promact oauth server
                var accessToken = await _attachmentRepository.AccessToken(user.UserName);

                // checking whether string ca convert to Slack Action or not, if true then further process will be conduct
                var actionConvertResult = Enum.TryParse(slackText[0], out actionType);
                if (actionConvertResult)
                {
                    // convert string to slack action type
                    var action = (SlackAction)Enum.Parse(typeof(SlackAction), slackText[0]);
                    switch (action)
                    {
                    case SlackAction.apply:
                        replyText = await LeaveApply(slackText, leave, accessToken);

                        break;

                    case SlackAction.list:
                        replyText = await SlackLeaveList(slackText, leave, accessToken);

                        break;

                    case SlackAction.cancel:
                        replyText = await SlackLeaveCancel(slackText, leave, accessToken);

                        break;

                    case SlackAction.status:
                        replyText = await SlackLeaveStatus(slackText, leave, accessToken);

                        break;

                    case SlackAction.balance:
                        replyText = await SlackLeaveBalance(leave, accessToken);

                        break;

                    case SlackAction.update:
                        await UpdateSickLeave(slackText, user, accessToken);

                        break;

                    default:
                        replyText = SlackLeaveHelp(leave);
                        break;
                    }
                }
                else
                {
                    // if error in converting then user will get message to enter proper action command
                    replyText = _stringConstant.RequestToEnterProperAction;
                }
            }
            else
            {
                // if user doesn't exist then will get message of user doesn't exist and ask to externally logic from Oauth server
                replyText = _stringConstant.SorryYouCannotApplyLeave;
            }
            _client.SendMessage(leave, replyText);
        }
Exemplo n.º 5
0
        /// <summary>
        ///  This method is called whenever a message other than the default keywords is written in the group. - JJ
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="message"></param>
        /// <param name="groupName"></param>
        /// <returns>the next question statement</returns>
        private async Task <string> AddScrumAnswer(string userName, string message, string groupName)
        {
            string reply = string.Empty;
            //today's scrum of the group
            List <Scrum> scrumList = _scrumRepository.Fetch(x => String.Compare(x.GroupName, groupName, true) == 0 && x.ScrumDate.Date == DateTime.UtcNow.Date).ToList();

            if (scrumList.Count > 0)
            {
                Scrum scrum = scrumList.FirstOrDefault();
                if (scrum.IsOngoing && !scrum.IsHalted)
                {
                    // getting user name from user's slack name
                    ApplicationUser applicationUser = _applicationUser.FirstOrDefault(x => x.SlackUserName == userName);
                    // getting access token for that user
                    if (applicationUser != null)
                    {
                        // get access token of user for promact oauth server
                        string accessToken = await _attachmentRepository.AccessToken(applicationUser.UserName);

                        //list of scrum questions. Type =1
                        List <Question> questions = _questionRepository.Fetch(x => x.Type == 1).OrderBy(x => x.OrderNumber).ToList();
                        //employees of the given group name fetched from the oauth server
                        List <User> employees = await _projectUser.GetUsersByGroupName(groupName, accessToken);

                        int questionCount = questions.Count();
                        //scrum answer of that day's scrum
                        List <ScrumAnswer> scrumAnswer = _scrumAnswerRepository.Fetch(x => x.ScrumId == scrum.Id).ToList();
                        //status would be empty if the interacting user is same as the expected user.
                        string status = ExpectedUser(scrum.Id, questions, employees, userName);
                        if (status == string.Empty)
                        {
                            #region Normal Scrum

                            if ((employees.Count() * questionCount) > scrumAnswer.Count)
                            {
                                Question    firstQuestion   = questions.OrderBy(x => x.OrderNumber).FirstOrDefault();
                                ScrumAnswer lastScrumAnswer = scrumAnswer.OrderByDescending(x => x.Id).FirstOrDefault();
                                //scrum answers of the given employee
                                int answerListCount = scrumAnswer.FindAll(x => x.EmployeeId == lastScrumAnswer.EmployeeId).Count();

                                if (scrumAnswer.Any())
                                {
                                    if (answerListCount < questionCount)
                                    {
                                        //not all questions have been answered
                                        Question prevQuestion = _questionRepository.FirstOrDefault(x => x.Id == lastScrumAnswer.QuestionId);
                                        Question question     = _questionRepository.FirstOrDefault(x => x.Type == 1 && x.OrderNumber == prevQuestion.OrderNumber + 1);
                                        AddAnswer(lastScrumAnswer.ScrumId, question.Id, lastScrumAnswer.EmployeeId, message);
                                    }
                                    else
                                    {
                                        //A particular employee's first answer
                                        //list of Employee ids who have not answer yet
                                        List <string> idList = employees.Where(x => !scrumAnswer.Select(y => y.EmployeeId).ToList().Contains(x.Id)).Select(x => x.Id).ToList();
                                        if (idList != null && idList.Count > 0)
                                        {
                                            //now fetch the first question to the next employee
                                            User user = employees.FirstOrDefault(x => x.Id == idList.FirstOrDefault());
                                            AddAnswer(lastScrumAnswer.ScrumId, firstQuestion.Id, user.Id, message);
                                        }
                                    }
                                    //get the next question
                                    //donot shift message
                                    reply = await GetQuestion(scrum.Id, groupName, questions, employees, scrum.ProjectId, accessToken);
                                }
                                else
                                {
                                    //First Employee's first answer
                                    User user = employees.FirstOrDefault();
                                    AddAnswer(scrum.Id, firstQuestion.Id, user.Id, message);
                                    //get the next question . donot shift message
                                    reply = await GetQuestion(scrum.Id, groupName, questions, employees, scrum.ProjectId, accessToken);
                                }
                            }

                            #endregion
                        }
                        //the user interacting is not the expected user
                        else if ((status != _stringConstant.ScrumConcludedButLater) && (status != _stringConstant.ScrumComplete))
                        {
                            return(status);
                        }
                    }
                    else
                    {
                        // if user doesn't exist then this message will be shown to user
                        return(_stringConstant.YouAreNotInExistInOAuthServer);
                    }
                }
            }
            return(reply);
        }