public IActionResult Attempt(AttemptAchievementViewModel viewModel) { if (viewModel.Video == null) return this.View("Error",new ErrorViewModel {Message = "Invalid file" }); try { var uploadDir = Path.Combine(_environment.WebRootPath, "Videos"); var filePath = Path.Combine(uploadDir, viewModel.Video.FileName); using (var stream = new FileStream(filePath, FileMode.Create)) { viewModel.Video.CopyTo(stream); } var uploadedVideoId = _videoService.UploadVideoToYotuube(filePath); Task.Run(() => System.IO.File.Delete(filePath)); var achievementUserDto = _achivementsViewService.GetAchievementUserDto(this.User.Identity.Name, uploadedVideoId, viewModel.Id); _achievementService.CreateAchievementUser(achievementUserDto); return Redirect("/Achievements/Index"); } catch (InvalidOperationException ex) { return this.View("Error", new ErrorViewModel { Message = ex.Message }); } }