public async Task <IActionResult> EditVideo(int?kursId, int?videoId, KursVideo video, IFormFile PhotoUrl) { if (kursId != null) { var thisVideo = db.KursVideos.FirstOrDefault(x => x.Id == videoId); if (PhotoUrl == null || PhotoUrl.Length == 0) { video.PhotoUrl = thisVideo.PhotoUrl; } else { var imgname = DateTime.Now.ToString("MMddHHmmss") + PhotoUrl.FileName; string path_Root = env.WebRootPath; string path_to_Images = path_Root + "/kursvideo/" + imgname; using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await PhotoUrl.CopyToAsync(stream); } video.PhotoUrl = imgname; } thisVideo.Free = video.Free; thisVideo.VideoName = video.VideoName; thisVideo.Info = video.Info; thisVideo.VideoUrl = video.VideoUrl; thisVideo.PhotoUrl = video.PhotoUrl; thisVideo.KursId = (int)kursId; thisVideo.WorkUrl = video.WorkUrl; await db.SaveChangesAsync(); return(RedirectToAction("KursEdit", new { Id = video.KursId })); } else { return(RedirectToAction("KursList", "Admin")); } }
public async Task <IActionResult> AddVideo(int kursId, string VideoName, string Info, string VideoUrl, IFormFile PhotoUrl, bool Free, string WorkUrl) { if (kursId != 0) { KursVideo kv = new KursVideo { KursId = kursId, VideoName = VideoName, Info = Info, VideoUrl = VideoUrl, WorkUrl = WorkUrl }; if (Free == true) { kv.Free = true; } if (PhotoUrl == null || PhotoUrl.Length == 0) { kv.PhotoUrl = "default.jpg"; } else { var imgname = DateTime.Now.ToString("MMddHHmmss") + PhotoUrl.FileName; string path_Root = env.WebRootPath; string path_to_Images = path_Root + "/kursvideo/" + imgname; using (var stream = new FileStream(path_to_Images, FileMode.Create)) { await PhotoUrl.CopyToAsync(stream); } kv.PhotoUrl = imgname; } db.KursVideos.Add(kv); await db.SaveChangesAsync(); return(RedirectToAction("KursEdit", new { Id = kv.KursId })); } else { return(RedirectToAction("KursList", "Admin")); } }