public async Task <IActionResult> AddFile([FromForm] FileForAddDto fileForAddDto) { var file = fileForAddDto.File; fileForAddDto.TypeId = 2; var fileToCreate = _mapper.Map <File>(fileForAddDto); _repo.Add(fileToCreate); await _repo.SaveAll(); int idOfFileAdded = _repo.GetFileMaxID(); if (file != null) { string newFileName = idOfFileAdded + "_" + file.FileName; string path = Path.Combine(_hostingEnv.ContentRootPath, "Upload/File", newFileName); using (var stream = new FileStream(path, FileMode.Create)) { file.CopyTo(stream); fileForAddDto.Url = newFileName; fileToCreate.Url = fileForAddDto.Url; //_data.Entry(fileForAddDto).Property(x => x.Image).IsModified = true; var fileFromRepo1 = await _repo.GetFile(idOfFileAdded); _mapper.Map(fileToCreate, fileFromRepo1); await _repo.SaveAll(); } } fileToCreate.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + fileForAddDto.Url; return(CreatedAtRoute("GetFile", new { id = idOfFileAdded }, fileToCreate)); }
public async Task <IActionResult> GetCourseNew() { var courses = await _repo.GetCoursesNew(); foreach (var course in courses) { if (course.Image != null) { course.Image = BaseURL.GetBaseUrl(Request) + "/Upload/" + course.Image; } } var coursesToReturn = _mapper.Map <IEnumerable <CourseForListDto> >(courses); return(Ok(coursesToReturn)); }
public async Task <IActionResult> GetMyCourse(int courseId, int userId) { var courses = await _repo.GetMyCourse(courseId, userId); if (courses.Image != null) { courses.Image = BaseURL.GetBaseUrl(Request) + "/Upload/" + courses.Image; } var courseToReturn = _mapper.Map <CourseForDetailedDto>(courses); return(Ok(courseToReturn)); }
public async Task <IActionResult> GetFile(int id) { var item = await _repo.GetFile(id); if (item.TypeId == 1) { item.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Video/" + item.Url; } if (item.TypeId == 2) { item.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + item.Url; } var photo = _mapper.Map <FileForDetailedDto>(item); return(Ok(photo)); }
public async Task <IActionResult> GetItem(int id) { var Items = await _repo.GetItem(id); if (Items.Files.TypeId == 1) { Items.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Video/" + Items.Files.Url; } if (Items.Files.TypeId == 2) { Items.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + Items.Files.Url; } var ItemsToReturn = _mapper.Map <ItemForDetailedDto>(Items); return(Ok(ItemsToReturn)); }
public async Task <IActionResult> GetFiles() { var files = await _repo.GetFiles(); foreach (var item in files) { if (item.TypeId == 1) { item.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Video/" + item.Url; } if (item.TypeId == 2) { item.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + item.Url; } } var filesToReturn = _mapper.Map <IEnumerable <FileForListDto> >(files); return(Ok(filesToReturn)); }
public async Task <IActionResult> GetItemOfLesson(int id) { var Items = await _repo.GetItemOfLesson(id); foreach (var item in Items) { if (item.Files.TypeId == 1) { item.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Video/" + item.Files.Url; } if (item.Files.TypeId == 2) { item.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + item.Files.Url; } } var ItemsToReturn = _mapper.Map <IEnumerable <ItemForListDto> >(Items); return(Ok(ItemsToReturn)); }
public async Task <IActionResult> GetLessonByCourse(int id) { var Lessons = await _repo.GetLessonByIdCourse(id); foreach (var lesson in Lessons) { foreach (var item in lesson.Items) { if (item.Files.TypeId == 1) { item.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Video/" + item.Files.Url; } if (item.Files.TypeId == 2) { item.Files.Url = BaseURL.GetBaseUrl(Request) + "/Upload/File/" + item.Files.Url; } } } var LessonsToReturn = _mapper.Map <IEnumerable <LessonForListDto> >(Lessons); return(Ok(LessonsToReturn)); }
public async Task <IActionResult> AddAudio([FromForm] FileForAddDto fileForAddDto) { var file = fileForAddDto.File; fileForAddDto.TypeId = 1; var fileToCreate = _mapper.Map <File>(fileForAddDto); _repo.Add(fileToCreate); await _repo.SaveAll(); if (file != null) { string newFileName = fileToCreate.Id + "_" + file.FileName; string path = Path.Combine(_hostingEnv.ContentRootPath, "Upload/Audio", newFileName); using (var stream = new FileStream(path, FileMode.Create)) { file.CopyTo(stream); fileForAddDto.Url = newFileName; fileToCreate.Url = fileForAddDto.Url; //_data.Entry(fileForAddDto).Property(x => x.Image).IsModified = true; var fileFromRepo1 = await _repo.GetFile(fileToCreate.Id); _mapper.Map(fileToCreate, fileFromRepo1); await _repo.SaveAll(); } } fileToCreate.Url = BaseURL.GetBaseUrl(Request) + "/Upload/Audio/" + fileForAddDto.Url; // var uploadResult = new VideoUploadResult(); // if (file.Length > 0) // { // using (var stream = file.OpenReadStream()) // { // var uploadParams = new VideoUploadParams() // { // File = new FileDescription(file.Name, stream), // }; // uploadResult = _cloudinary.Upload(uploadParams); // } // } // fileForAddDto.Url = uploadResult.Uri.ToString(); // fileForAddDto.PublicId = uploadResult.PublicId; // fileForAddDto.Duration = uploadResult.Duration; // fileForAddDto.ItemId = 1; // var data = _mapper.Map<File>(fileForAddDto); // _repo.Add(data); // if (await _repo.SaveAll()) // { // var photoToReturn = _mapper.Map<File>(data); // return CreatedAtRoute("GetFile", new { id = data.Id }, photoToReturn); // } // return BadRequest("Could not add the photo"); return(CreatedAtRoute("GetFile", new { id = fileToCreate.Id }, fileToCreate)); }