コード例 #1
0
        public TestVM TestCreate()
        {
            var testVM = testHelper.TestFullData();

            if (validator.Validate(testVM).IsValid)
            {
                var mappedTest = mapper.Map <TestVM, Test>(testVM);
                testService.AddTest(mappedTest);

                Dye.Succsess();
                Console.WriteLine("You have successfully created test");
                Console.ResetColor();

                return(testVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(testVM));
                Console.ResetColor();
                TestCreate();

                return(null);
            }
        }
コード例 #2
0
        public bool AddCourseToUserProgress(CourseVM courseVM)
        {
            var mappedCourse = mapper.Map <CourseVM, Course>(courseVM);

            if (mappedCourse == null)
            {
                Dye.Fail();
                Console.WriteLine("Unknown course Id");
                Console.ResetColor();
                return(false);
            }
            if (userService.AddCourseToProgress(mappedCourse))
            {
                Dye.Succsess();
                Console.WriteLine("Course passing started!");
                Console.ResetColor();
                return(true);
            }
            else
            {
                Dye.Inform();
                Console.WriteLine("You have passed this course early");
                Console.ResetColor();
                return(false);
            }
        }
コード例 #3
0
 public void Execute()
 {
     userService.LogOut();
     Dye.Fail();
     Console.WriteLine("LogOut");
     Console.ResetColor();
 }
コード例 #4
0
        public QuestionVM QuestionData(int variant)
        {
            QuestionVM questionVM = new QuestionVM();

            Console.WriteLine("Enter question");
            questionVM.Name    = Console.ReadLine();
            questionVM.Answers = new List <AnswerVM>();

            bool infinity = true;

            while (infinity)
            {
                Console.WriteLine("1 - Add answer\n2 - Finish adding answers");
                switch (Console.ReadLine())
                {
                case "1":
                    Dye.Succsess();
                    Console.WriteLine(questionVM.Name);
                    Console.ResetColor();
                    var answer = answerHelper.AnswerData(variant++);
                    if (questionVM.Answers.Count(x => x.IsTrue == true) == 1 && answer.IsTrue == true)
                    {
                        Dye.Fail();
                        Console.WriteLine(new Exception("True answer alredy exist!"));
                        Console.ResetColor();
                        break;
                    }
                    Dye.Succsess();
                    Console.WriteLine("Answer added");
                    Console.ResetColor();

                    //Вставить маппинг ответов
                    questionVM.Answers.Add(answer);
                    break;

                case "2":
                    if (questionVM.Answers.Any(x => x.IsTrue == true) && questionVM.Answers.Count() >= 2 && questionVM.Answers.Count() <= 6)
                    {
                        return(questionVM);
                    }
                    Dye.Fail();
                    Console.WriteLine(new Exception("Atleast 1 answer must be true. Min. 2 answers. Max. 6 answers"));
                    Console.ResetColor();
                    break;

                default:
                    continue;
                }
            }
            return(null);
        }
コード例 #5
0
        public void Execute()
        {
            Console.Clear();
            var(login, password) = UserHelper.UserLoginData();

            if (userService.LogIn(login, password))
            {
                Dye.Succsess();
                Console.WriteLine("Authorized");
                Console.ResetColor();
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(new Exception("Something went wrong, try again"));
                Console.ResetColor();
            }
        }
コード例 #6
0
        public void Execute()
        {
            Console.Clear();
            var userVM = UserHelper.UserFullData();

            if (validator.Validate(userVM).IsValid)
            {
                userService.Register(mapper.Map <UserVM, User>(userVM));
                Dye.Succsess();
                Console.WriteLine("You have successfully registered and authorized");
                Console.ResetColor();
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(userVM));
                Console.ResetColor();
            }
        }
コード例 #7
0
        public QuestionVM QuestionCreate()
        {
            var questionVM = questionHelper.QuestionData(answerLetter);

            if (validator.Validate(questionVM).IsValid)
            {
                Dye.Succsess();
                Console.WriteLine("You have successfully created question");
                Console.ResetColor();
                return(questionVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(questionVM));
                Console.ResetColor();
                QuestionCreate();
                return(null);
            }
        }
        public VideoMaterialVM VideoCreate()
        {
            var videoVM = materialHelper.VideoFullData();

            if (validations.Validate(videoVM).IsValid&& videoValidator.Validate(videoVM).IsValid)
            {
                var mappedVideo = mapper.Map <VideoMaterialVM, VideoMaterial>(videoVM);
                videoMaterialService.AddVideoMaterial(mappedVideo);
                Dye.Succsess();
                Console.WriteLine("You have add video");
                Console.ResetColor();
                return(videoVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(videoValidator.Validate(videoVM) + " " + " " + validations.Validate(videoVM));
                Console.ResetColor();
                VideoCreate();
                return(null);
            }
        }
コード例 #9
0
        public void UserPassCourse(CourseVM courseVM)
        {
            int rightAnswers = 0;

            //нужен джоин thenInclude answers()
            var test = testController.GetTestById(courseVM.Test.Id);

            Console.WriteLine(string.Join(". ", courseVM.Name, courseVM.Description));

            foreach (var question in test.Questions)
            {
                Dye.Succsess();
                Console.WriteLine(question.Name);
                Console.ResetColor();
                Console.WriteLine("Choose the variant");
                foreach (var answers in question.Answers)
                {
                    Console.WriteLine(answers.Name);
                }
                var userVariatnt = Console.ReadLine().Trim().Split("")[0];
                testController.AnswersCounting(question, userVariatnt, ref rightAnswers);
            }

            var mappedCourse = mapper.Map <CourseVM, Course>(courseVM);

            if (userService.IsCoursePassed(mappedCourse, rightAnswers))
            {
                Dye.Succsess();
                Console.WriteLine($"Test - passed. Right answers {rightAnswers}/{courseVM.Test.Questions.Count()} CONGRATULATIONS!!!");
                Console.ResetColor();
            }
            else
            {
                Dye.Fail();
                Console.WriteLine("Learn materials hard, and try again");
                Console.ResetColor();
            }
        }
コード例 #10
0
        public ArticleMaterialVM ArticleCreate()
        {
            var articleVM = materialHelper.ArticleFullData();

            if (validations.Validate(articleVM).IsValid&& acticleValidator.Validate(articleVM).IsValid)
            {
                var mappedArticle = mapper.Map <ArticleMaterialVM, ArticleMaterial>(articleVM);
                articleMaterialService.AddArticleMaterial(mappedArticle);

                Dye.Succsess();
                Console.WriteLine("You have add article");
                Console.ResetColor();
                return(articleVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(acticleValidator.Validate(articleVM) + " " + " " + validations.Validate(articleVM));
                Console.ResetColor();
                ArticleCreate();
                return(null);
            }
        }
コード例 #11
0
        public void CourseCreate()
        {
            var courseVM = courseHelper.CourseFullData();

            if (validator.Validate(courseVM).IsValid&& courseVM.Skills.Count >= 1 && courseVM.Materials.Count >= 1)
            {
                var mappedCourse = mapper.Map <CourseVM, Course>(courseVM);
                courseService.AddCourse(mappedCourse);

                courseVM.Id = mappedCourse.Id;

                Dye.Succsess();
                Console.WriteLine("You have successfully created course");
                Console.ResetColor();
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(courseVM));
                Console.WriteLine(new Exception("Course is not added, try again."));
                Console.ResetColor();
            }
        }
コード例 #12
0
        public SkillVM SkillCreate()
        {
            var skillVM = SkillHelper.SkillFullData();

            if (validator.Validate(skillVM).IsValid)
            {
                var mappedSkill = mapper.Map <SkillVM, Skill>(skillVM);
                skillService.AddSkill(mappedSkill);

                Dye.Succsess();
                Console.WriteLine("Skill has successfully added");
                Console.ResetColor();
                return(skillVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(skillVM));
                Console.ResetColor();
                SkillCreate();
                return(null);
            }
        }
コード例 #13
0
        public TestVM TestFullData()
        {
            TestVM testVM = new TestVM();

            Console.WriteLine("Enter test Name");
            testVM.Name      = Console.ReadLine();
            testVM.Questions = new List <QuestionVM>();
            bool infinity = true;

            while (infinity)
            {
                Console.WriteLine("1 - Add question\n2 - Finish adding questions");
                switch (Console.ReadLine())
                {
                case "1":
                    Console.Clear();
                    var question = questionController.QuestionCreate();
                    //Вставить маппинг вопросов
                    testVM.Questions.Add(question);
                    break;

                case "2":
                    if (testVM.Questions.Count() >= 0)
                    {
                        return(testVM);
                    }
                    Dye.Fail();
                    Console.WriteLine("Count of questions must be greater than 3");
                    Console.ResetColor();
                    break;

                default:
                    continue;
                }
            }
            return(null);
        }
        public BookMaterialVM BookCreate()
        {
            var bookVM = materialHelper.BookFullData();

            if (validations.Validate(bookVM).IsValid&& bookValidator.Validate(bookVM).IsValid)
            {
                var mappedBook = mapper.Map <BookMaterialVM, BookMaterial>(bookVM);
                bookMaterialService.AddBookMaterial(mappedBook);

                Dye.Succsess();
                Console.WriteLine("You have add book");
                Console.ResetColor();

                return(bookVM);
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(bookValidator.Validate(bookVM) + " " + " " + validations.Validate(bookVM));
                Console.ResetColor();

                return(null);
            }
        }
コード例 #15
0
        public CourseVM CourseFullData()
        {
            var courseVM = new CourseVM();

            Console.WriteLine("Enter course Name");
            courseVM.Name = Console.ReadLine();
            Console.WriteLine("Enter course Description");
            courseVM.Description = Console.ReadLine();
            courseVM.Materials   = new List <MaterialVM>();
            courseVM.Skills      = new List <SkillVM>();

            bool infinity = true;

            while (infinity)
            {
                Console.WriteLine("1 - Add video material\n2 - Add book material\n3 - Add article material\n 4 - Select existing material\n5 - Finish adding materials");
                switch (Console.ReadLine())
                {
                case "1":
                    videoMaterialController.VideoCreate();
                    break;

                case "2":
                    bookMaterialController.BookCreate();
                    break;

                case "3":
                    articleMaterialController.ArticleCreate();
                    break;

                case "4":
                    Console.Clear();
                    Console.WriteLine("List existing materials");
                    materialController.MaterialList();
                    Console.WriteLine("\nEnter Id of existing material");
                    var Id = int.Parse(Console.ReadLine());

                    if (courseVM.Materials.Any(x => x.Id == Id))
                    {
                        Dye.Fail();
                        Console.WriteLine("Material already exists in course");
                        Console.ResetColor();
                    }
                    else
                    {
                        var materialVM = materialController.AddMaterialById(Id);

                        if (materialVM == null)
                        {
                            Dye.Fail();
                            Console.WriteLine("Invalid material Id");
                            Console.ResetColor();
                            break;
                        }

                        courseVM.Materials.Add(materialVM);
                        Dye.Succsess();
                        Console.WriteLine("Material added successfully");
                        Console.ResetColor();
                    }
                    break;

                case "5":
                    Dye.Succsess();
                    Console.WriteLine("Materials added successfully");
                    Console.ResetColor();
                    infinity = false;
                    break;

                default:
                    continue;
                }
            }

            infinity = true;
            while (infinity)
            {
                Console.WriteLine("1 - Add new skill\n2 - Select existing\n3 - Finish adding skills");

                switch (Console.ReadLine())
                {
                case "1":
                    var skill = skillController.SkillCreate();
                    Dye.Succsess();
                    Console.WriteLine("Skill created successfully, now you can add it to your course");
                    Console.ResetColor();
                    break;

                case "2":
                    Console.Clear();
                    Console.WriteLine("List existing skills: ");
                    skillController.SkillsList();
                    Console.WriteLine("\nEnter the name of existing skill");
                    var name = Console.ReadLine().ToLower();
                    if (courseVM.Skills.Any(x => x.Name.ToLower() == name.ToLower()))
                    {
                        Dye.Fail();
                        Console.WriteLine("Invalid name or Skill already exists in course");
                        Console.ResetColor();
                    }
                    else
                    {
                        var skillVM = skillController.AddSkillByName(name);
                        if (skillVM == null)
                        {
                            Dye.Fail();
                            Console.WriteLine("Invalid skill name");
                            Console.ResetColor();
                            break;
                        }
                        courseVM.Skills.Add(skillVM);
                        Dye.Succsess();
                        Console.WriteLine("Skill added successfully");
                        Console.ResetColor();
                    }
                    break;

                case "3":
                    Dye.Succsess();
                    Console.WriteLine("Skills added successfully");
                    Console.ResetColor();
                    infinity = false;
                    break;

                default:
                    continue;
                }
            }
            //Айдишник теста равен нулю
            var test       = testController.TestCreate();
            var mappedTest = testController.GetTestByName(test.Name);

            courseVM.Test   = mappedTest;
            courseVM.TestId = mappedTest.Id;

            return(courseVM);
        }