public IActionResult ChangeVideoName(EditPresentation model) { Video video = repository.Videos.FirstOrDefault(v => v.Id == model.VideoId); if (model.VideoTitle != null && model.VideoTitle.Trim() != "" && model.VideoTitle.Trim() != video.Title) { video.Title = model.VideoTitle; repository.SaveVideo(video); } return(RedirectToAction("EditPresentation", new { id = model.UserId, presentationId = model.PresentationId, courseId = model.CourseId })); }
public IActionResult EditPresentation(EditPresentation model) { Presentation presentation = repository.Presentations.FirstOrDefault(p => p.PresentationId == model.PresentationId); if (model.Title != null) { if (model.Title.Trim() != "" && model.Title.Trim() != presentation.Title) { presentation.Title = model.Title; repository.SavePresentation(presentation); } } if (model.Part != presentation.Part && model.Part > 0) { presentation.Part = model.Part; repository.SavePresentation(presentation); } if (model.Description != null && presentation.Description != null) { if (model.Description.Trim() != "" && model.Description.Trim() != presentation.Description) { presentation.Description = model.Description; repository.SavePresentation(presentation); } } else if (model.Description != null && presentation.Description == null) { if (model.Description.Trim() != "") { presentation.Description = model.Description; repository.SavePresentation(presentation); } } return(RedirectToAction("EditPresentation", new { id = model.UserId, presentationId = model.PresentationId, courseId = model.CourseId })); }
public IActionResult UploadNewFile(EditPresentation model) { if (model.NewFile != null) { AppUser user = userManager.Users.FirstOrDefault(u => u.Id == model.UserId); Presentation presentation = repository.Presentations .FirstOrDefault(p => p.PresentationId == model.PresentationId); int filePart = repository.PresentationFiles .Where(f => f.PresentationId == model.PresentationId).Count() + 1; //Create user directory string dirPath = Path.Combine(hostingEnvironment.WebRootPath, $@"UsersData\{user.Id}\Presentations\"); System.IO.Directory.CreateDirectory(dirPath); PresentationFiles file = repository.PresentationFiles.FirstOrDefault(f => f.FileId == model.NewFileId); //file exists if (file != null) { repository.SaveFile(file); } else { string fileName = ""; if (model.NewFileTitle == null) { fileName = presentation.Title + "_File_Part_" + filePart; } else { fileName = (model.NewFileTitle.Trim() == "") ? presentation.Title + "_File_Part_" + filePart : model.NewFileTitle; } //save presentation file file = new PresentationFiles { Title = fileName, CreatedById = user.Id, Part = model.NewFilePart, PresentationId = presentation.PresentationId, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; repository.SaveFile(file); file.FilePath = $@"/UsersData/{user.Id}/Presentations/{file.FileId}.pdf"; repository.SaveFile(file); } string filePath = Path.Combine(dirPath, file.FileId.ToString() + ".pdf"); using (var stream = new FileStream(filePath, FileMode.Create)) { model.NewFile.CopyTo(stream); } } return(RedirectToAction("EditPresentation", new { id = model.UserId, presentationId = model.PresentationId, courseId = model.CourseId })); }