Пример #1
0
        public Action AddIsStudentCommand(Message message, QueueMessage nextTrueMessage, QueueMessage nextFalseMessage)
        {
            return(() =>
            {
                var answer = message.Text;
                var chatId = message.Chat.Id;
                bool?isStudent = null;

                bool?isAnsweredAllQuestions = null;
                if (Compare(answer, "да"))
                {
                    isStudent = true;
                }

                if (Compare(answer, "нет"))
                {
                    isStudent = false;
                    isAnsweredAllQuestions = true;
                }

                _userRepository.SaveStudentOrNot(chatId, isStudent, isAnsweredAllQuestions);
                if (!isStudent.HasValue)
                {
                    var factory = new QueueMessageFactory(message);
                    _queueService.Add(factory.AskIsStudentMessage);
                }

                if (isStudent.HasValue && isStudent.Value)
                {
                    _queueService.Add(nextTrueMessage);
                }
                else
                {
                    if (!_resultRepository.IsQuizMember(chatId))
                    {
                        _userRepository.SetQuizMember(chatId, null);
                    }

                    _queueService.Add(nextFalseMessage);
                }
            });
        }
Пример #2
0
        private Action CreateCommand(Message message)
        {
            var chatId = message.Chat.Id;
            var user   = _users.Get(chatId);

            var factory = new QueueMessageFactory(message);

            if (user == null)
            {
                return(_generalCommandsFactory.StartCommand(factory.WelcomeMessage));
            }

            // handle contact message
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (message.Type)
            {
            case MessageType.Contact when user.Phone is null:
                return(_generalCommandsFactory.AddContactCommand(message,
                                                                 factory.AskNameMessage(message.Contact.FirstName)));

            case MessageType.Contact:
                return(_generalCommandsFactory.Command(factory.WrongMessage));
            }

            // handle text messages
            if (user.Phone == null)
            {
                return(_generalCommandsFactory.Command(factory.AskContactMessage));
            }

            if (user.Name == null)
            {
                return(_generalCommandsFactory.AddNameCommand(message, factory.AskStartQuizMessage));
            }

            // ReSharper disable once ConvertIfStatementToSwitchStatement
            if (user.IsQuizMember == null)
            {
                return(_questionCommandFactory.AddQuizCommand(user, message, user.IsAnsweredAll
                        ? factory.EndMessage
                        : factory.AskEmail,
                                                              factory.AskStartQuizMessage));
            }

            if (user.IsQuizMember is true)
            {
                // add handler to quiz
                return(_questionCommandFactory.QuestionCommand(message,
                                                               user.IsAnsweredAll ? factory.EndMessage : factory.AskEmail, user.IsAnsweredAll));
            }

            if (user.EMail == null)
            {
                return(_generalCommandsFactory.AddEMailCommand(message, factory.AskProfessionMessage));
            }

            if (user.Profession == null)
            {
                return(_generalCommandsFactory.AddProfessionCommand(message, factory.AskIsStudentMessage));
            }

            // ReSharper disable once ConvertIfStatementToSwitchStatement
            if (user.IsStudent == null)
            {
                return(_generalCommandsFactory.AddIsStudentCommand(
                           message,
                           factory.AskUniversityMessage,
                           _resultRepository.IsQuizMember(chatId) ? factory.EndMessage : factory.AskStartQuizMessageAgain));
            }

            if (user.IsStudent is true && user.University == null)
            {
                return(_generalCommandsFactory.AddUniversityCommand(message, factory.AskCourse));
            }

            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (user.IsStudent is true && user.Course == null)
            {
                return(_generalCommandsFactory.AddCourseCommand(
                           message,
                           _resultRepository.IsQuizMember(chatId) ? factory.EndMessage : factory.AskStartQuizMessageAgain,
                           factory.AskCourse));
            }

            // ReSharper disable once ConvertIfStatementToReturnStatement
            if (user.IsAnsweredAll)
            {
                return(_generalCommandsFactory.Command(factory.EndMessage));
            }

            return(_generalCommandsFactory.Command(factory.WrongMessage));
        }