コード例 #1
0
        // Twist user entered phrase based on user selected option.
        public Task <string> TwistIt(WordTwisterModel twister)
        {
            try
            {
                string twistedPhrase = null;

                // Produce result based on Twist Action selecteed.
                switch (twister.TwistAction)
                {
                case Twist.ReverseWordOrder:
                    twistedPhrase = WordTwisterEngine.ReverseWordOrder(twister.Text);
                    break;

                case Twist.ReverseCharacters:
                    twistedPhrase = WordTwisterEngine.ReverseCharacters(twister.Text);
                    break;

                case Twist.SortWordsAlphabetically:
                    twistedPhrase = WordTwisterEngine.SortWordsAlphabetically(twister.Text);
                    break;

                case Twist.EncryptInput:
                    // .Result is used to extract the result.
                    twistedPhrase = WordTwisterEngine.EncryptInput(twister.Text).Result;
                    break;
                }

                // Return the result.
                return(Task.FromResult(twistedPhrase));
            }
            catch (Exception ex)
            {
                return(Task.FromException <string>(ex));
            }
        }
コード例 #2
0
        public ActionResult WordTwister(WordTwisterModel twister)
        {
            if (ModelState.IsValid)
            {
                twister.Text =
                    WordTwisterProcessor.Instance
                    .TwistIt(twister).Result;

                ModelState.Clear();
            }

            return(View(twister));
        }