public async Task AddCourse() { string xml = File.ReadAllText(@"C:\Users\kalub\OneDrive\CIS\COMP466\ElearnerProject\ElearnerApi\wwwroot\assets\SampleCourse.xml"); Course entity = XmlParser.FromXml <Course>(xml); ICourseRepository courseRepository = new CourseRepository( ); await courseRepository.CreateCourse(entity); }
public async Task <IActionResult> UploadCourse(string xmlTextInput, List <IFormFile> files) { try { Course course; if (files.Count > 0) { IFormFile file = Request.Form.Files[0]; var allowedExtensions = new[] { ".xml", ".txt" }; if (!allowedExtensions.Contains(Path.GetExtension(file.FileName).ToLower( ))) { TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Danger, "Only .xml and .txt files accepted"); return(View( )); } string textContent = string.Empty; using (var reader = new StreamReader(file.OpenReadStream( ))) { textContent = reader.ReadToEnd( ); } course = XmlParser.FromXml <Course>(textContent); } else { course = XmlParser.FromXml <Course>(xmlTextInput); } var courseRepository = new CourseRepository( ); await courseRepository.CreateCourse(course); TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Success, "Course created successfully;"); } catch (Exception ex) { TempData["CustomResponseAlert"] = CustomResponseAlert.GetStringResponse(ResponseStatusEnum.Danger, ex.Message); } return(View( )); }
public async Task <IActionResult> Create(CreateCourseViewModel courseVM) { if (ModelState.IsValid) { var helper = await _manager.GetUserAsync(User); var user = _userRepository.GetUserWithLessonsListAndCreatedCourses(helper.Id); user.IsTeacher = true; user.CreatedCourses.Add(new CString() { value = courseVM.Course.Title }); await _manager.UpdateAsync(user); await _courseRepository.CreateCourse(courseVM, user); return(RedirectToAction(nameof(Index))); } return(View(courseVM.Course)); }
public string Create(Course course, string token) { try { if (ModelState.IsValid) { course.CreatedBy = _userStatistics.UserId; if (objRep.CreateCourse(course)) { SaveFiles(token, this.GetType().Name, course.CourseId); return(Convert.ToString(true)); } return(Convert.ToString(false)); } return(Convert.ToString(false)); } catch (Exception ex) { return(ex.Message.ToString()); } }