public string SkillInfoInput() { if (session.IsAuthorised) { skillService.ShowSkills(); string name = string.Empty; int points = 0; name = InfoUnit.GetInfoUnit(name, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 1, "Enter skill name", @"Error! Skill name is invalid!").ToString(); points = Convert.ToInt32(InfoUnit.GetInfoUnit(points, x => !string.IsNullOrEmpty(x.ToString()), "Enter points", @"Error! points is invalid!")); skillService.Add(name, points); return(name); } else { Console.WriteLine("You need to authorize"); return(null); } }
private MaterialDTO BasicInfoInput() { string name = string.Empty; string link = string.Empty; string skills = string.Empty; name = InfoUnit.GetInfoUnit(name, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 1, "Enter material name", @"Error! Enter the material name!").ToString(); link = InfoUnit.GetInfoUnit(link, x => !string.IsNullOrEmpty(x.ToString()) && Regex.IsMatch(x.ToString(), urlRegex, RegexOptions.IgnoreCase), "Enter material link!", @"Error! Enter the correct link!").ToString(); skillService.ShowSkills(); List <Skill> skillList = new List <Skill>(); while (true) { string command = string.Empty; command = InfoUnit.GetInfoUnit(command, x => !string.IsNullOrEmpty(x.ToString()) && new List <string> { "0", "1", "2" }.Contains(x.ToString()), "Wanna add new skill(1) or existing one(2) PRESS 0 TO EXIT SKILL ADDING MODE?", @"Error! Enter the correct command!").ToString(); if (command == "0") { break; } if (command == "1") { var skillName = skillInputService.SkillInfoInput(); var skill = skillService.Get(skillName); skillList.Add(skill); } else { string skillName = string.Empty; skillName = InfoUnit.GetInfoUnit(skillName, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 1, "Enter skill name", @"Error! skill name invalid!").ToString(); skillList.Add(skillService.Get(skillName.TrimStart())); } } return(new MaterialDTO(name, link, skillList)); }
public User UserInfoInput() { string firstName = string.Empty; string lastName = string.Empty; string login = string.Empty; string email = string.Empty; string password = string.Empty; firstName = InfoUnit.GetInfoUnit ( firstName, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 3, "Enter your name!", @"Error! Enter the correct name!" ).ToString(); lastName = InfoUnit.GetInfoUnit ( lastName, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 3, "Enter your last name!", @"Error! Enter the correct last name!" ).ToString(); login = InfoUnit.GetInfoUnit ( login, x => !string.IsNullOrEmpty(x.ToString()) && x.ToString().Length > 1, "Enter your login!", @"Error! Enter the correct login" ).ToString(); email = InfoUnit.GetInfoUnit ( email, x => Regex.IsMatch(x.ToString(), emailRegex, RegexOptions.IgnoreCase), "Enter your Email!", @"Error! Enter the correct email!" ).ToString(); password = InfoUnit.GetInfoUnit ( password, x => Regex.IsMatch(x.ToString(), passwordRegex, RegexOptions.IgnoreCase), "Enter your password", @"Error! Enter the correct password!" ).ToString(); return(new User(firstName, lastName, login, email, password)); }
public void CompleteCourse() { if (session.IsAuthorised) { var courses = userService.Get(session.User.Email).UserCourse.Where(uc => uc.IsCompleted == false); if (courses.Any()) { foreach (var item in courses) { Console.WriteLine(item.Course); } string courseName = string.Empty; courseName = InfoUnit.GetInfoUnit( courseName, x => !(string.IsNullOrEmpty(x.ToString())), "Enter course name", "Error! Course name is invalid" ).ToString(); var course = courses.FirstOrDefault(c => c.Course.Name == courseName).Course; if (course != null) { if (course.UserCourse.FirstOrDefault(uc => uc.CourseId == course.Id).IsCompleted) { Console.WriteLine("already completed"); } else { //courseService.CompleteCourse(courseName); } } else { Console.WriteLine("course not found"); } } else { Console.WriteLine("No courses to complete"); } } }
public void StartCourse() { if (session.IsAuthorised) { var courses = courseService.Get().Where(c => !c.UserCourse.Where(uc => uc.Course.Id == c.Id).Any()); if (!courses.Any()) { Console.WriteLine("no courses found"); } else { foreach (var c in courses) { Console.WriteLine(c); } } string courseName = string.Empty; courseName = InfoUnit.GetInfoUnit( courseName, x => !(string.IsNullOrEmpty(x.ToString())), "Enter course name", "Error! Course name is invalid" ).ToString(); var course = courseService.Get().FirstOrDefault(c => c.Name == courseName).UserCourse. FirstOrDefault(uc => uc.CourseId == courseService.Get().FirstOrDefault(c => c.Name == courseName).Id); if (course != null && course.IsCompleted == false) { Console.WriteLine("already started"); } else { //courseService.StartCourse(courseName); } } else { Console.WriteLine("You need to authorize"); } }
public InfoUnit GetDownloadUrls(string link) { if (link == string.Empty) { return(null); } InfoUnit infoUnit = new InfoUnit(); IEnumerable <YoutubeExtractor.VideoInfo> infoList = DownloadUrlResolver.GetDownloadUrls(link); foreach (var item in infoList.Where(p => p.Resolution >= 144 && p.AudioExtension != null)) { if (item.RequiresDecryption) { DownloadUrlResolver.DecryptDownloadUrl(item); } infoUnit.VideoInfoList.Add( new Types.VideoInfo { Title = item.Title, Format = item.VideoExtension.ToString(), Resolution = item.Resolution, DownloadURL = item.DownloadUrl + "&title=" + item.Title } ); } var audioMaxBitrate = infoList.Where(p => p.CanExtractAudio).OrderByDescending(p => p.AudioBitrate).FirstOrDefault(); if (audioMaxBitrate != null) { if (audioMaxBitrate.RequiresDecryption) { DownloadUrlResolver.DecryptDownloadUrl(audioMaxBitrate); } infoUnit.AudioInfo = new AudioInfo { Title = audioMaxBitrate.Title, Format = audioMaxBitrate.AudioType.ToString(), BitRate = audioMaxBitrate.AudioBitrate, DownloadURL = audioMaxBitrate.DownloadUrl }; } return(infoUnit); }
public UserDTO UserDTOInfoInput() { string email = string.Empty; string password = string.Empty; email = InfoUnit.GetInfoUnit ( email, x => !string.IsNullOrEmpty(x.ToString()), "Enter your email!", @"Error! Enter the correct email!" ).ToString(); password = InfoUnit.GetInfoUnit ( password, x => !string.IsNullOrEmpty(x.ToString()), "Enter your password!", @"Error! Enter the correct password!" ).ToString(); return(new UserDTO(email, password)); }
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"); } } } }
public void CourseinfoInput() { if (session.IsAuthorised) { var courses = courseService.Get(); if (!courses.Any()) { Console.WriteLine("no courses found"); } else { foreach (var course in courses) { Console.WriteLine(course); } } string name = string.Empty; string description = string.Empty; name = InfoUnit.GetInfoUnit( name, x => !(string.IsNullOrEmpty(x.ToString())), "Enter course name", "Error! Name is invalid" ).ToString(); description = InfoUnit.GetInfoUnit( description, x => !(string.IsNullOrEmpty(x.ToString())), "Enter course description", "Error! discription is invalid" ).ToString(); Console.WriteLine("Wanna add some materials?\n 1.Yes\n 2.No"); while (true) { var command = Console.ReadLine(); if (command == "1" || command == "Yes") { while (true) { Console.WriteLine("Add new(1) or existing(2)? PRESS 0 TO EXIT MATERIAL ADDING MODE"); var materials = new List <Material>(); var innerCommand = Console.ReadLine(); if (innerCommand == "0") { break; } if (innerCommand == "1") { var materialName = materialInputService.MaterialInfoInput(); var material = materialService.Get(materialName); materials.Add(material); } if (innerCommand == "2") { materialService.ShowMaterials(); string materialName = string.Empty; materialName = InfoUnit.GetInfoUnit( materialName, x => !(string.IsNullOrEmpty(x.ToString())), "Enter material name", "Error! Invalid material name" ).ToString(); var material = materialService.Get(materialName); materials.Add(material); } //courseService.CreateCourse(name, description, materials); } break; } else { //courseService.CreateCourse(name, description, null); break; } } } else { Console.WriteLine("You need to authorize"); } }
public void MaterialInfoUpdate() { if (session.IsAuthorised) { materialService.ShowMaterials(); string name = string.Empty; name = InfoUnit.GetInfoUnit( name, x => !(string.IsNullOrEmpty(x.ToString())), "Enter name of the material you want to edit", "Error! Name is invalid" ).ToString(); var material = materialService.Get(name); 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.Link \n 3.Skills", "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(); materialService.Update(material.Name, newName, null); } if (field == "2") { var newLink = string.Empty; newLink = InfoUnit.GetInfoUnit( newLink, x => !(string.IsNullOrEmpty(x.ToString())), "Enter new description", "Error! Description is invalid" ).ToString(); materialService.Update(material.Name, null, newLink); } if (field == "3") { Console.WriteLine(material); var command = string.Empty; command = InfoUnit.GetInfoUnit( command, x => !(string.IsNullOrEmpty(x.ToString())) && new List <string> { "1", "2" }.Contains(x.ToString()), "Wanna add new skills(1), add existing(2) or delete some (3)", "Error! command is invalid" ).ToString(); if (command == "1") { var skillName = skillInputService.SkillInfoInput(); var skill = skillService.Get(skillName); materialService.AddSkillToMaterial(material.Name, skill); } if (command == "2") { skillService.ShowSkills(); var skillName = string.Empty; skillName = InfoUnit.GetInfoUnit( skillName, x => !(string.IsNullOrEmpty(x.ToString())), "Enter skill name", "Error! Skill name is invalid" ).ToString(); var skill = skillService.Get(skillName); materialService.AddSkillToMaterial(material.Name, skill); } if (command == "3") { var skillName = string.Empty; skillName = InfoUnit.GetInfoUnit( skillName, x => !(string.IsNullOrEmpty(x.ToString())), "Enter material name", "Error! Material name is invalid" ).ToString(); var skill = skillService.Get(skillName); //skillService.Delete(material.Id); } } else { Console.WriteLine("You need to authorize"); } } }
public string MaterialInfoInput() { if (session.IsAuthorised) { materialService.ShowMaterials(); string name = string.Empty; string link = string.Empty; Console.WriteLine("Enter material type:\n 1. Video\n 2.Article\n 3.Book"); while (true) { var materialType = Console.ReadLine(); if (string.IsNullOrEmpty(materialType)) { Console.WriteLine(@"Error! {0}", "Enter the material type!"); } if (materialType == "1" || materialType == "Video") { string length = string.Empty; string quality = string.Empty; var materialDTO = BasicInfoInput(); length = InfoUnit.GetInfoUnit(length, x => !string.IsNullOrEmpty(x.ToString()), "Enter video length!", @"Error! Enter the correct length!").ToString(); quality = InfoUnit.GetInfoUnit(quality, x => !string.IsNullOrEmpty(x.ToString()), "Enter video quality!", @"Error! Enter the correct quality!").ToString(); materialService.CreateVideo(materialDTO.Name, materialDTO.Link, length, quality, materialDTO.Skills); return(materialDTO.Name); } if (materialType == "2" || materialType == "Article") { string publishDate = string.Empty; var materialDTO = BasicInfoInput(); publishDate = InfoUnit.GetInfoUnit(publishDate, x => !string.IsNullOrEmpty(x.ToString()), "Enter publish date!", @"Error! Enter the correct publish date!").ToString(); materialService.CreateArticle(materialDTO.Name, materialDTO.Link, publishDate, materialDTO.Skills); return(materialDTO.Name); } if (materialType == "3" || materialType == "Book") { string author = string.Empty; int pageNumber = 0; string format = string.Empty; string year = string.Empty; var materialDTO = BasicInfoInput(); author = InfoUnit.GetInfoUnit(author, x => !string.IsNullOrEmpty(x.ToString()), "Enter author name!", @"Error! Enter the correct author!").ToString(); pageNumber = Convert.ToInt32 ( InfoUnit.GetInfoUnit ( pageNumber, x => !string.IsNullOrEmpty(x.ToString()), "Enter page number!", @"Error! Enter the correct page number!" ) ); format = InfoUnit.GetInfoUnit(format, x => !string.IsNullOrEmpty(x.ToString()), "Enter format!", @"Error! Enter the correct format!").ToString(); year = InfoUnit.GetInfoUnit(year, x => !string.IsNullOrEmpty(x.ToString()), "Enter year!", @"Error! Enter the correct year!").ToString(); materialService.CreateBook(materialDTO.Name, materialDTO.Link, author, pageNumber, format, year, materialDTO.Skills); return(materialDTO.Name); } } } else { Console.WriteLine("You need to authorize"); return(null); } }