private void AddScript()
        {
            var command = new ScriptCreateCommand(NewContent, NewSection);

            scriptApplicationService.Create(command);
            AddMode = false;
            ReloadScripts();
        }
Ejemplo n.º 2
0
 public ActionResult Create(IFormCollection collection, ScriptCreateRequestModel scriptCreateRequestModel)
 {
     try
     {
         var content = scriptCreateRequestModel.Content;
         var section = scriptCreateRequestModel.Section;
         var command = new ScriptCreateCommand(content, section);
         scriptApplicationService.Create(command);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 3
0
        public ScriptCreateResult Create(ScriptCreateCommand command)
        {
            using (var transaction = new TransactionScope())
            {
                var content = command.Content;
                var section = command.Section;

                var script = new Script(content, section);

                scriptRepository.Save(script);

                transaction.Complete();

                return(new ScriptCreateResult(script.Id));
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Startup();
            var scriptApplicationService = serviceProvider.GetService <IScriptApplicationService>();
            var quizApplicationService   = serviceProvider.GetService <IQuizApplicationService>();

            while (true)
            {
                Console.WriteLine("Select operation (cs: Create script / ls: Display script list / sq: Start quiz");
                Console.Write(">");
                var mode = Console.ReadLine();
                if (mode == "cs")
                {
                    Console.WriteLine("Input section");
                    Console.Write(">");
                    var section = Console.ReadLine();
                    Console.WriteLine("Input content");
                    Console.Write(">");
                    var content = Console.ReadLine();
                    var command = new ScriptCreateCommand(content, section);
                    scriptApplicationService.Create(command);
                    Console.WriteLine("--------");
                    Console.WriteLine("Script created.");
                    Console.WriteLine("--------");
                }
                else if (mode == "ls")
                {
                    var scripts = scriptApplicationService.GetAll();
                    Console.WriteLine("--------");
                    foreach (var script in scripts.Scripts)
                    {
                        Console.WriteLine("ID:" + script.Id + ", Section: " + script.Section + ", Content: " + script.Content);
                    }
                    Console.WriteLine("--------");
                }
                else if (mode == "sq")
                {
                    var quizCreateResult = quizApplicationService.Create();
                    var createdQuizId    = quizCreateResult.CreatedQuizId;
                    var quizGetCommand   = new QuizGetCommand(createdQuizId);
                    var quizGetResult    = quizApplicationService.Get(quizGetCommand);
                    var quiz             = quizGetResult.Quiz;
                    Console.WriteLine("--------");
                    Console.WriteLine("Question: " + quiz.Question);
                    Console.WriteLine("Choices: ");

                    int number = 1;
                    foreach (var choice in quiz.Choices)
                    {
                        Console.WriteLine(number.ToString() + ": " + choice);
                        number++;
                    }

                    while (true)
                    {
                        Console.WriteLine("--------");
                        Console.WriteLine("Input answer number");
                        Console.Write(">");
                        var answerNumberOfAnswerer = Console.ReadLine();
                        var quizAnswerCommand      = new QuizAnswerCommand(createdQuizId, Int32.Parse(answerNumberOfAnswerer) - 1);
                        var quizAnswerResult       = quizApplicationService.Answer(quizAnswerCommand);
                        var isCorrect = quizAnswerResult.IsCorrect;
                        if (isCorrect)
                        {
                            Console.WriteLine("Correct!!");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Incorrect...");
                        }
                    }
                    Console.WriteLine("--------");
                }

                Console.WriteLine("continue? (y/n)");
                Console.Write(">");
                var yesOrNo = Console.ReadLine();
                if (yesOrNo == "n")
                {
                    break;
                }
            }
        }