コード例 #1
0
        public void CreateNewUser()
        {
            Console.Clear();
            // create user
            UserViewModel userVM = UserVMInstanceCreator.CreateUser();

            // user data is valid?
            if (this.userService.GetAllUsers().Any(x => x.Email == userVM.Email))
            {
                Console.WriteLine("User with this email already exists!");
                Thread.Sleep(4000);
                ProgramBranch.StartApplication();
            }

            // Create new user, if not - false
            bool createUser = this.userService.CreateUser(Mapping.CreateMapFromVMToDomain <UserViewModel, User>(userVM));

            // Show result
            ProgramConsoleMessageHelper.
            ShowFunctionResult(
                createUser,
                "User successfully created!",
                "Something wrong",
                ProgramBranch.StartApplication,
                ProgramBranch.StartApplication
                );
        }
コード例 #2
0
 private void ShowMessageAndReturnToMainMenu(string message)
 {
     // Show message with error and return to main menu
     Console.WriteLine(message);
     Thread.Sleep(4000);
     ProgramBranch.SelectFirstStepForAuthorizedUser();
 }
コード例 #3
0
        public void CreateNewCourse()
        {
            Console.Clear();

            // Create course
            CourseViewModel courseVM = CourseVMInstanceCreator.CreateCourse();

            // mapping to Domain model
            var  courseDomain = Mapping.CreateMapFromVMToDomain <CourseViewModel, Course>(courseVM);
            bool success      = this.courseService.CreateCourse(courseDomain);

            if (success)
            {
                int courseId = this.courseService.GetAllCourses().Where(x => x.Name == courseVM.Name).FirstOrDefault().Id;

                // Add materials to course
                this.AddMaterialToCourse(courseId);

                // Add skills to course
                this.AddSkillsToCourse(courseId);

                // go ro start menu
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }
            else
            {
                Console.WriteLine("Course exist");

                // Go to start menu
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }
        }
コード例 #4
0
        public void StartPassCourse()
        {
            // Get all courses
            List <CourseViewModel> coursesListVM = this.GetListOfCoursesFromServiceAfterMappingToVM(this.userService.GetAvailableCoursesForUser());

            if (coursesListVM.Count <= 0)
            {
                this.ShowMessageAndReturnToMainMenu("No courses available");
            }

            // Show all courses
            this.ShowCoursesToPass(coursesListVM);

            // Get course id from user to passing
            int courseIdToPass = GetIdFromUserToPassCourse();

            // Check, may be we this course course already started
            if (this.userService.GetListWithCoursesInProgress().Any(x => x.Id == courseIdToPass))
            {
                this.ShowMessageAndReturnToMainMenu("You have already started this course");
            }

            if (!coursesListVM.Any(x => x.Id == courseIdToPass))
            {
                this.ShowMessageAndReturnToMainMenu("Сourses with this id do not exist");
            }

            // Greate course to continue passing
            CourseViewModel courseInProgress = coursesListVM.Where(x => x.Id == courseIdToPass).FirstOrDefault();

            if (courseInProgress != null)
            {
                Console.Clear();

                // add course to Progress List
                this.userService.AddCourseInProgress(courseInProgress.Id);
                PassCourseConsoleMessageHelper.ShowInfoToStartPassingCourse();

                // passing the course
                this.PassingCourse(ref courseInProgress, courseInProgress.Materials.ToList());

                // checking if all materials have been worked out
                bool allMaterialsPassed = courseInProgress.Materials.All(x => x.IsPassed == true);

                // add skills for user and add course to Passed list
                this.WorkAfterSuccessfullyPassingCourse(allMaterialsPassed, courseInProgress);
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }
        }
コード例 #5
0
        private void AddMaterialToCourse(int courseId)
        {
            string userChoice;

            do
            {
                Material materialDomain = ProgramBranch.SelectMaterialForAddToCourse();

                // check, material exist in course, or no
                if (!this.courseService.AddMaterialToCourse(courseId, materialDomain))
                {
                    Console.WriteLine("Material exist in course");
                }

                Console.WriteLine("Do you want to add more material (Enter YES)?");
                userChoice = Console.ReadLine();
            }while (userChoice.ToLower() == "yes");
        }
コード例 #6
0
        public static int GetIdFromUserToPassCourse()
        {
            int id;

            Console.WriteLine("Please, enter course to pass");

            try
            {
                return(id = Convert.ToInt32(Console.ReadLine()));
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Invalid data + {ex.Message}");
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }

            return(-1);
        }
コード例 #7
0
        internal static void ReturnMethod()
        {
            string userValue = string.Empty;

            do
            {
                Console.Write("Enter '..' to return: ");
                userValue = Console.ReadLine();

                if (userValue == "..")
                {
                    ProgramBranch.SelectFirstStepForAuthorizedUser();
                }
                else
                {
                    Console.WriteLine("Invalid value");
                }
            }while (userValue != "..");
        }
コード例 #8
0
        public void VerifyLoginAndPassword()
        {
            // get data from user
            string name     = GetDataHelper.GetNameFromUser();
            string password = GetDataHelper.GetPasswordFromUser();

            // verify user
            bool validUser = this.userService.VerifyUser(name, password);

            if (validUser)
            {
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }
            else
            {
                Console.WriteLine("User with such data does not exist");
                Thread.Sleep(4000);
                ProgramBranch.StartApplication();
            }
        }
コード例 #9
0
        public void ShowAllUserSkills()
        {
            Console.Clear();
            // get user skills from bll and mapping
            List <SkillViewModel> userSkills = Mapping.CreateListMap <Skill, SkillViewModel>(this.userService.GetAllUserSkills());

            if (userSkills == null)
            {
                Console.WriteLine("You don't have skills yet!");
                Thread.Sleep(4000);
                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }

            // show skills
            for (int i = 0; i < userSkills.Count; i++)
            {
                Console.WriteLine($"{i + 1}.{userSkills[i].Name}. Count of points - {userSkills[i].CountOfPoint}");
            }

            ProgramConsoleMessageHelper.ReturnMethod();
        }
コード例 #10
0
 private void ShowMessageIfCountOfCourseListIsZero(string message)
 {
     Console.WriteLine(message);
     Thread.Sleep(4000);
     ProgramBranch.SelectFirstStepForAuthorizedUser();
 }
コード例 #11
0
        static void Main()
        {
            ProgramBranch.StartApplication();

            Console.ReadLine();
        }
コード例 #12
0
        public void StartPassingCourseFromProgressList()
        {
            // Get all courses in progress
            List <CourseViewModel> coursesListInProgressVM = this.GetListOfCoursesFromServiceAfterMappingToVM(this.userService.GetListWithCoursesInProgress().ToList());

            // CHeck, we have courses in progress, or no
            if (coursesListInProgressVM.Count <= 0)
            {
                this.ShowMessageAndReturnToMainMenu("You have no unfinished courses!");
            }

            // Show all courses in progress
            this.ShowCoursesToPass(coursesListInProgressVM);

            // get course id from user to continue
            int courseInProgressIdToPass = GetIdFromUserToPassCourse();

            // checking valid course id
            if (!coursesListInProgressVM.Any(x => x.Id == courseInProgressIdToPass))
            {
                this.ShowMessageAndReturnToMainMenu("Invalid ID.");
            }

            // get course in progress
            var courseToProgressFromProcessList = this.userService.GetListWithCoursesInProgress().Where(x => x.Id == courseInProgressIdToPass).FirstOrDefault();

            // mapping to course domain to course view model
            CourseViewModel courseVMInProgress = Mapping.Mapping.CreateMapFromVMToDomainWithIncludeLsitType <Course, CourseViewModel, Material, MaterialViewModel, Skill, SkillViewModel>(courseToProgressFromProcessList);

            // mapping materials in progogress
            courseVMInProgress.Materials = this.materialController.GetAllMaterialVMAfterMappingFromMaterialDomain(this.userService.GetMaterialsFromCourseInProgress(courseVMInProgress.Id));

            // mapping skills
            courseVMInProgress.Skills = Mapping.Mapping.CreateListMap <Skill, SkillViewModel>(this.userService.GetSkillsFromCourseInProgress(courseVMInProgress.Id));

            if (courseVMInProgress != null)
            {
                Console.Clear();

                // List<MaterialViewModel> materials = materialController.GetAllMaterialVMAfterMappingFromMaterialDomain(courseToProgressFromProcessList.Materials.Select(x => x).Where(x => x.IsPassed == false).ToList());
                List <MaterialViewModel> materials = courseVMInProgress.Materials.Where(x => x.IsPassed == false).ToList();

                // Add to method course from processing list, and materials from this course, which do not passed
                this.PassingCourse(ref courseVMInProgress, materials);

                // checking if all materials have been worked out
                bool allMaterialsPassed = courseVMInProgress.Materials.All(x => x.IsPassed == true);

                if (allMaterialsPassed)
                {
                    // if all materials passed => add skills for user and add course to Passed list, delete course from processing list
                    this.WorkAfterSuccessfullyPassingCourse(allMaterialsPassed, courseVMInProgress);
                }
                else
                {
                    // update passed materials in course
                    this.userService.UpdateCourseInProgress(
                        courseToProgressFromProcessList.Id, Mapping.Mapping.CreateListMapFromVMToDomainWithIncludeMaterialType <MaterialViewModel, Material, VideoViewModel, Video, ArticleViewModel, Article, BookViewModel, Book>(courseVMInProgress.Materials));
                }

                ProgramBranch.SelectFirstStepForAuthorizedUser();
            }
        }