public bool PostTheoryForCourse(TheoryModel theoryModel) { if (theoryModel.NemeOfCourse != null && theoryModel.Topic != null) { theoryModel.NemeOfCourse = Regex.Replace(theoryModel.NemeOfCourse, Regex.Escape("%20"), " "); theoryModel.Topic = CreateLinkFromCustom(theoryModel.Topic); if (theoryModel.Description != null) { theoryModel.Description = CreateLinkFromCustom(theoryModel.Description); } var currentCourseInfoId = _coursesRepo.GetCourses().Where(res => res.Name == theoryModel.NemeOfCourse).Select(res => res.CourseInfoId).FirstOrDefault(); _coursesTheory.Create(new Theory { Topic = theoryModel.Topic, Details = theoryModel.Description, CourseInfoId = currentCourseInfoId }); var idOfTheory = _coursesTheory.Get().Where(res => res.CourseInfoId == currentCourseInfoId && res.Topic == theoryModel.Topic && res.Details == theoryModel.Description).Select(res => res.Id).FirstOrDefault(); var wwwroot = Path.Combine(Path.Combine(Path.Combine(_hostingEnviroment.WebRootPath, "theorys"), theoryModel.NemeOfCourse), theoryModel.Topic); if (!Directory.Exists(wwwroot)) { Directory.CreateDirectory(wwwroot); } foreach (var item in theoryModel.Files) { if (item != null) { Task task = new Task(() => { string uniqueFileName = Guid.NewGuid().ToString() + "_" + item.FileName; string filePath = Path.Combine(wwwroot, uniqueFileName); item.CopyTo(new FileStream(filePath, FileMode.Create)); _coursesTheoryFiles.Create(new TheoryFiles { filePath = uniqueFileName, TheoryId = idOfTheory }); }); task.Start(); } } return true; } return false; }
public IActionResult PostTheoryForCourse(TheoryModel theory) { theory.Files = HttpContext.Request.Form.Files; return(Json(_logic.PostTheoryForCourse(theory))); }