Ejemplo n.º 1
0
        public async Task Edit(Guid id, Lecture lectureEdited, LectureEditModel lectureModel)
        {
            _repository.EditLecture(lectureEdited);

            //var searchedPath = Path.Combine(_env.WebRootPath, "Lectures/" + id);

            //if (Directory.Exists(searchedPath) && oldTitle.Equals(lectureModel.Title) == false)
            //{
            //    Directory.Delete(searchedPath, true);
            //}

            if (lectureModel.File != null)
            {
                foreach (var file in lectureModel.File)
                {
                    if (file.Length > 0)
                    {
                        var path = Path.Combine(_env.WebRootPath, "Lectures/" + id);

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        // string extension = lectureModel.Title + "." + Path.GetExtension(file.FileName).Substring(1);

                        using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                    }
                }
            }
        }