public async Task <IActionResult> EditAnswer(Guid id, IFormCollection collection, AnswerEditViewModel answer, Guid QuizId, Guid QuestionId, string FotoURL) { try { answer.FotoURL = FotoURL; // TODO: Add update logic here Answer answerUpdate = new Answer { Id = answer.Id, Description = answer.Description, QuestionId = answer.QuestionId, FotoURL = answer.FotoURL }; string uniqueFileName = null; if (answer.Foto != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + answer.Foto.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); answer.Foto.CopyTo(new FileStream(filePath, FileMode.Create)); answerUpdate.FotoURL = uniqueFileName; } if (answer.Correct.ToString() == "True") { answerUpdate.Correct = Answer.IsCorrect.True; } else { answerUpdate.Correct = Answer.IsCorrect.False; } var result = await quizRepo.UpdateAnswer(answerUpdate); if (result == null) { return(RedirectToAction(nameof(Quizzes), new { exc = "Failed to update answer..." })); } Quiz quiz = await quizRepo.GetQuizForIdAsync(QuizId); if (quiz == null || QuizId == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong QuizId" })); } Question question = await quizRepo.GetQuestionForIdAsync(QuestionId); if (question == null || QuestionId == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong QuestionId" })); } return(RedirectToAction(nameof(QuestionAnswers), new { id = QuestionId, QuizId = QuizId, QuestionName = question.Description })); } catch (Exception exc) { return(RedirectToAction(nameof(Quizzes), new { exc = exc.Message })); } }