Пример #1
0
        /// <summary>
        /// Used to fetch the next question based on the given parameters
        /// </summary>
        /// <param name="scrumId"></param>
        /// <param name="groupName"></param>
        /// <param name="employees"></param>
        /// <param name="questions"></param>
        ///<param name="projectId"></param>
        ///<param name="accessToken"></param>
        /// <returns>The next question or the scrum complete message</returns>
        private async Task <string> GetQuestion(int scrumId, string groupName, List <Question> questions, List <User> employees, int projectId, string accessToken)
        {
            string             returnMsg   = string.Empty;
            List <ScrumAnswer> scrumAnswer = _scrumAnswerRepository.Fetch(x => x.ScrumId == scrumId).ToList();

            if (questions == null)
            {
                questions = _questionRepository.Fetch(x => x.Type == 1).OrderBy(x => x.OrderNumber).ToList();
            }
            if (employees == null)
            {
                employees = await _projectUser.GetUsersByGroupName(groupName, accessToken);
            }

            if (scrumAnswer.Any())
            {
                #region Normal Get Question
                int questionCount = questions.Count();
                //last acrum answer of the given scrum id.
                ScrumAnswer lastScrumAnswer = scrumAnswer.OrderByDescending(x => x.Id).FirstOrDefault();
                //no. of answers given by the employee who gave the last scrum answer.
                int answerListCount = scrumAnswer.FindAll(x => x.EmployeeId == lastScrumAnswer.EmployeeId).Count();
                if (answerListCount == questionCount)
                {
                    //all questions have been asked to the previous employee
                    //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());
                        returnMsg = _stringConstant.GoodDay + "<@" + user.SlackUserName + ">!\n" + FetchPreviousDayStatus(user.Id, projectId) + FetchQuestion(null, true);
                    }
                    else
                    {
                        MarkScrumComplete(lastScrumAnswer.ScrumId);
                        //answers of all the employees has been recorded
                        returnMsg = _stringConstant.ScrumComplete;
                    }
                }
                else
                {
                    //as not all questions have been answered by the last employee,the next question to that employee will be asked
                    User user = employees.FirstOrDefault(x => x.Id == lastScrumAnswer.EmployeeId);
                    returnMsg = "<@" + user.SlackUserName + "> " + FetchQuestion(lastScrumAnswer.QuestionId, false);
                }
                #endregion
            }
            else
            {
                //no scrum answer has been recorded yet. So first question to the first employee
                returnMsg = _stringConstant.GoodDay + "<@" + employees.FirstOrDefault().SlackUserName + ">!\n" + FetchPreviousDayStatus(employees.FirstOrDefault().Id, projectId) + questions.FirstOrDefault().QuestionStatement;
            }

            return(returnMsg);
        }
Пример #2
0
        /// <summary>
        /// Used to fetch the next question based on the given parameters
        /// </summary>
        /// <param name="scrumId"></param>
        /// <param name="employees"></param>
        /// <param name="questions"></param>
        ///<param name="projectId"></param>
        /// <returns>empty string if the expected user is same as the applicant</returns>
        private string ExpectedUser(int scrumId, List <Question> questions, List <User> employees, string applicant)
        {
            //List of scrum answer of the given scrumId.
            List <ScrumAnswer> scrumAnswer = _scrumAnswerRepository.Fetch(x => x.ScrumId == scrumId).ToList();
            User user = new User();

            if (scrumAnswer.Any())
            {
                int questionCount = questions.Count();
                //last acrum answer of the given scrum id.
                ScrumAnswer lastScrumAnswer = scrumAnswer.OrderByDescending(x => x.Id).FirstOrDefault();
                //no. of answers given by the employee who gave the last scrum answer.
                int answerListCount = scrumAnswer.FindAll(x => x.EmployeeId == lastScrumAnswer.EmployeeId).Count();
                if (answerListCount == questionCount)
                {
                    //all questions have been asked to the previous employee
                    //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 the next employee
                        user = employees.FirstOrDefault(x => x.Id == idList.FirstOrDefault());
                    }
                    else
                    {
                        return(_stringConstant.ScrumComplete);
                    }
                }
                else
                {
                    //as not all questions have been answered by the last employee,so to that employee itself
                    user = employees.FirstOrDefault(x => x.Id == lastScrumAnswer.EmployeeId);
                }
            }
            else
            {
                //no scrum answer has been recorded yet. So first employee
                user = employees.FirstOrDefault();
            }

            if (user != null && user.SlackUserName == applicant)
            {
                return(string.Empty);
            }
            else if (user == null)
            {
                return(string.Format(_stringConstant.NotExpected, applicant));
            }
            else
            {
                return(string.Format(_stringConstant.PleaseAnswer, user.SlackUserName));
            }
        }
Пример #3
0
        /// <summary>
        /// This method is used to add Scrum answer to the database
        /// </summary>
        /// <param name="scrumID"></param>
        /// <param name="questionId"></param>
        /// <param name="employeeId"></param>
        /// <param name="message"></param>
        /// <param name="status"></param>
        /// <returns>true if scrum answer is added successfully</returns>
        private bool AddAnswer(int scrumID, int questionId, string employeeId, string message)
        {
            ScrumAnswer answer = new ScrumAnswer();

            answer.Answer     = message;
            answer.AnswerDate = DateTime.UtcNow;
            answer.CreatedOn  = DateTime.UtcNow;
            answer.EmployeeId = employeeId;
            answer.QuestionId = questionId;
            answer.ScrumId    = scrumID;
            _scrumAnswerRepository.Insert(answer);
            return(true);
        }
Пример #4
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);
        }