public ActionResult Edit(int id) { if (BellongToCurrentUser(id, this.User.Identity.GetUserId())) { var answer = this.closeAnswerService.GetById(id); var model = new UpdateCloseAnswerViewModel { AnswerId = answer.Id, Content = answer.Content, Correct = answer.Correct, QuestionId = answer.QuestionId }; return(PartialView("Edit", model)); } return(Redirect("/")); }
public ActionResult Edit(UpdateCloseAnswerViewModel model) { int correctAnswers = 0; foreach (var item in this.closeQuestionService.GetById(model.QuestionId).Answers) { if (item.Id != model.AnswerId && item.Correct) { correctAnswers++; } } if (model.Correct) { correctAnswers++; } if (model.Content != null && OtherFunctions.IsHasJS(model.Content)) { TempData["EditErrors"] = Common.FieldAnsDanger; return(Redirect("/CloseQuestion/Question/" + model.QuestionId)); } if (correctAnswers == 0) { TempData["EditErrors"] = Common.OneCorrectAns; return(Redirect("/CloseQuestion/Question/" + model.QuestionId)); } if (!ModelState.IsValid) { if (model.Content == null) { TempData["EditErrors"] = Common.FieldAnsRequired + " <br/>"; } return(Redirect("/CloseQuestion/Question/" + model.QuestionId)); } this.closeAnswerService.Update(new CloseAnswer { Content = model.Content, Id = model.AnswerId, Correct = model.Correct, }); return(Redirect("/CloseQuestion/Question/" + model.QuestionId)); }