public async Task CreateLecture(LectureCreateModel lectureCreateModel) { _repository.CreateLecture(Lecture.CreateLecture( lectureCreateModel.Title, lectureCreateModel.Description) ); var currentLecture = GetLectureInfoByDetails(lectureCreateModel.Title, lectureCreateModel.Description); if (lectureCreateModel.File != null) { foreach (var file in lectureCreateModel.File) { if (file.Length > 0) { string path = Path.Combine(_env.WebRootPath, "Lectures/" + currentLecture.Id); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // string extension = lectureCreateModel.Title + "." + Path.GetExtension(file.FileName).Substring(1); using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } } } }