Beispiel #1
0
        public async Task FindByIdAsync()
        {
            await _botQuestionRepository.AddQuestionAsync(question);

            var responseQuestion = await _botQuestionRepository.FindByIdAsync(1);

            Assert.NotEqual(BotQuestionType.Scrum, responseQuestion.Type);
        }
        /// <summary>
        /// Method to start task mail and send first question of task mail
        /// </summary>
        /// <param name="userId">User's slack user Id</param>
        /// <returns>questionText in string format containing question statement</returns>
        public async Task <string> StartTaskMailAsync(string userId)
        {
            // method to get user's details, user's accesstoken, user's task mail details and list or else appropriate message will be send
            var userAndTaskMailDetailsWithAccessToken = await GetUserAndTaskMailDetailsAsync(userId);

            _logger.Info("Task Mail Bot Module, Is task mail question text : " + userAndTaskMailDetailsWithAccessToken.QuestionText);
            bool questionTextIsNull = string.IsNullOrEmpty(userAndTaskMailDetailsWithAccessToken.QuestionText);

            // if question text is null or not request to start task mail then only allowed
            if (questionTextIsNull || CheckQuestionTextIsRequestToStartMailOrNot(userAndTaskMailDetailsWithAccessToken.QuestionText))
            {
                _logger.Info("Task Mail Bot Module, task mail process start - StartTaskMailAsync");
                TaskMailDetails taskMailDetail = new TaskMailDetails();
                #region Task Mail Details
                if (userAndTaskMailDetailsWithAccessToken.TaskList != null)
                {
                    taskMailDetail = userAndTaskMailDetailsWithAccessToken.TaskList.Last();
                    var previousQuestion = await _botQuestionRepository.FindByIdAsync(taskMailDetail.QuestionId);

                    var questionOrder = previousQuestion.OrderNumber;
                    // If previous task mail is on the process and user started new task mail then will need to first complete pervious one
                    if (questionOrder < QuestionOrder.TaskMailSend)
                    {
                        userAndTaskMailDetailsWithAccessToken.QuestionText = await QuestionAndAnswerAsync(null, userId);

                        userAndTaskMailDetailsWithAccessToken.IsTaskMailContinue = true;
                    }
                }
                else
                {
                    // If task mail is not started for that day
                    userAndTaskMailDetailsWithAccessToken.TaskMail = await AddTaskMailAsync(userAndTaskMailDetailsWithAccessToken.User.Id);
                }
                #endregion

                #region If Task mail not send for that day
                // if question text is null or not request to start task mail then only allowed
                if (!userAndTaskMailDetailsWithAccessToken.IsTaskMailContinue && (questionTextIsNull || CheckQuestionTextIsRequestToStartMailOrNot(userAndTaskMailDetailsWithAccessToken.QuestionText)))
                {
                    SendEmailConfirmation confirmation = taskMailDetail.SendEmailConfirmation;
                    switch (confirmation)
                    {
                    case SendEmailConfirmation.yes:
                    {
                        // If mail is send then user will not be able to add task mail for that day
                        userAndTaskMailDetailsWithAccessToken.QuestionText = _stringConstant.AlreadyMailSend;
                    }
                    break;

                    case SendEmailConfirmation.no:
                    {
                        // If mail is not send then user will be able to add task mail for that day
                        userAndTaskMailDetailsWithAccessToken.QuestionText = await AddTaskMailDetailAndGetQuestionStatementAsync(userAndTaskMailDetailsWithAccessToken.TaskMail.Id);
                    }
                    break;
                    }
                }
                #endregion
            }
            return(userAndTaskMailDetailsWithAccessToken.QuestionText);
        }