Exemplo n.º 1
0
        internal void Functionality()
        {
            IRepository <User> userRepository = new UserRepository(context);
            var interactionCommands           = new InteractionCommands();


            this.MenuInfo();
            while (true)
            {
                Console.WriteLine("Select a number and press enter!");
                var command = Console.ReadLine();
                if (command == "0")
                {
                    break;
                }

                switch (command)
                {
                case "1":
                    registrationService.Register();
                    break;

                case "2":
                    if (!session.IsAuthorised)
                    {
                        authorizationService.SignIn(userRepository);
                    }
                    else
                    {
                        Console.WriteLine("Already authorised");
                    }
                    break;

                case "3":
                    if (session.IsAuthorised)
                    {
                        authorizationService.SignOut();
                    }
                    else
                    {
                        Console.WriteLine("Already unauthorised");
                    }
                    break;

                case "4":
                    Console.WriteLine(session.IsAuthorised ? "Yes" : "No");
                    break;

                case "5":
                    interactionCommands.Show(userRepository);
                    break;

                case "6":
                    Console.WriteLine("Enter the email you want to delete.");
                    interactionCommands.Delete(userRepository);
                    break;

                case "7":
                    Console.Clear();
                    MenuInfo();
                    break;

                case "8":
                    materialInputService.MaterialInfoInput();
                    break;

                case "9":
                    materialService.ShowMaterials();
                    break;

                case "10":
                    courseInputService.CourseinfoInput();
                    break;

                //case "11":
                //    var courses = courseService.GetCourses();
                //    if (!courses.Any())
                //    {
                //        Console.WriteLine("no courses found");
                //    }
                //    else
                //    {
                //        foreach (var course in courses)
                //        {
                //            Console.WriteLine(course);
                //        }
                //    }
                //    break;
                case "12":
                    courseInputService.CourseInfoUpdate();
                    break;

                case "13":
                    skillInputService.SkillInfoInput();
                    break;

                case "14":
                    userInfoInputService.PrintSessionUser();
                    break;

                case "15":
                    courseInputService.StartCourse();
                    break;

                case "16":
                    if (session.IsAuthorised)
                    {
                        courseService.GetStartedCourses(session.User.Email).ForEach(c => Console.WriteLine(c));
                    }
                    else
                    {
                        Console.WriteLine("You need to authorise");
                    }
                    break;

                case "17":
                    if (session.IsAuthorised)
                    {
                        courseInputService.CompleteCourse();
                    }
                    else
                    {
                        Console.WriteLine("You need to authorise");
                    }
                    break;

                case "18":
                    if (session.IsAuthorised)
                    {
                        courseService.GetCompletedCourses(session.User.Email).ForEach(c => Console.WriteLine(c));
                    }
                    else
                    {
                        Console.WriteLine("You need to authorise");
                    }
                    break;

                default:
                    Console.WriteLine("Command not found!");
                    break;
                }
            }
        }
        public void CourseInfoUpdate()
        {
            if (session.IsAuthorised)
            {
                var courses = courseService.Get().Where(c => c.Owner.Id == session.User.Id);
                if (!courses.Any())
                {
                    Console.WriteLine("no courses found");
                }
                else
                {
                    foreach (var c in courses)
                    {
                        Console.WriteLine(c);
                    }
                }

                string name = string.Empty;
                name = InfoUnit.GetInfoUnit(
                    name,
                    x => !(string.IsNullOrEmpty(x.ToString())),
                    "Enter name of the course you want to edit",
                    "Error! Name is invalid"
                    ).ToString();

                var course = courseService.Get().FirstOrDefault(c => c.Name == name);

                if (course.Owner.Id != session.User.Id)
                {
                    Console.WriteLine("Not allowed");
                }
                else
                {
                    string field = string.Empty;
                    field = InfoUnit.GetInfoUnit(
                        field,
                        x => !(string.IsNullOrEmpty(x.ToString()) &&
                               new List <string> {
                        "1", "2", "3"
                    }.Contains(x.ToString())),
                        "Enter name of the field you want to edit: \n 1.Name \n 2.Description \n 3.Materials",
                        "Error! Field is invalid"
                        ).ToString();

                    if (field == "1")
                    {
                        var newName = string.Empty;
                        newName = InfoUnit.GetInfoUnit(
                            newName,
                            x => !(string.IsNullOrEmpty(x.ToString())),
                            "Enter new name",
                            "Error! Name is invalid"
                            ).ToString();

                        //courseService.Update(course.Name, newName, null);
                    }
                    if (field == "2")
                    {
                        var newDescription = string.Empty;
                        newDescription = InfoUnit.GetInfoUnit(
                            field,
                            x => !(string.IsNullOrEmpty(x.ToString())),
                            "Enter new description",
                            "Error! Description is invalid"
                            ).ToString();

                        //courseService.Update(course.Name, null, newDescription);
                    }
                    if (field == "3")
                    {
                        Console.WriteLine(course);

                        var command = string.Empty;
                        command = InfoUnit.GetInfoUnit(
                            command,
                            x => !(string.IsNullOrEmpty(x.ToString())) &&
                            new List <string> {
                            "1", "2"
                        }.Contains(x.ToString()),
                            "Wanna add new material(1), add existing material(2) or delete some (3)",
                            "Error! command is invalid"
                            ).ToString();
                        if (command == "1")
                        {
                            var materialName = materialInputService.MaterialInfoInput();
                            var material     = materialService.Get(materialName);
                            //courseService.AddMaterialToCourse(course.Name, material);
                        }
                        if (command == "2")
                        {
                            materialService.ShowMaterials();

                            var materialName = string.Empty;
                            materialName = InfoUnit.GetInfoUnit(
                                materialName,
                                x => !(string.IsNullOrEmpty(x.ToString())),
                                "Enter material name",
                                "Error! Material name is invalid"
                                ).ToString();

                            var material = materialService.Get(materialName);
                            //courseService.AddMaterialToCourse(course.Name, material);
                        }
                        if (command == "3")
                        {
                            var materialName = string.Empty;
                            materialName = InfoUnit.GetInfoUnit(
                                materialName,
                                x => !(string.IsNullOrEmpty(x.ToString())),
                                "Enter material name",
                                "Error! Material name is invalid"
                                ).ToString();

                            var material = materialService.Get(materialName);
                            //materialService.Delete(material.Id);
                        }
                    }
                    else
                    {
                        Console.WriteLine("You need to authorize");
                    }
                }
            }
        }