public ActionResult CreateClosedQuestion(ExamTestQuestion question, IEnumerable<HttpPostedFileBase> fileUpload, string variantText) { JournalContext.ExamTestQuestions.InsertOnSubmit(question); JournalContext.SubmitChanges(); var tVariant = new ExamTestVariant() { ExamTestQuestionID = question.ExamTestQuestionID, IsCorrect = true, VariantText = variantText, }; JournalContext.ExamTestVariants.InsertOnSubmit(tVariant); UploadFiles(fileUpload, question); JournalContext.SubmitChanges(); return RedirectToAction("Index"); }
partial void DeleteExamTestVariant(ExamTestVariant instance);
partial void UpdateExamTestVariant(ExamTestVariant instance);
partial void InsertExamTestVariant(ExamTestVariant instance);
private void detach_ExamTestVariants(ExamTestVariant entity) { this.SendPropertyChanging(); entity.ExamTestQuestion = null; }
public ActionResult CreateOpenQuestion(ExamTestQuestion question, IEnumerable<HttpPostedFileBase> fileUpload, IEnumerable<string> variants, IEnumerable<int> corrected) { var correctedCount = corrected.Count(); if (corrected == null) RedirectToAction("Index"); // ошибка - не выбрано ни одного правильного ответа if (correctedCount == 0) RedirectToAction("Index"); // вопрос должен имеять хотя бы один правильный ответ question.AllowMultiAnswer = correctedCount > 1 ? true : false; //question.ExamTestID = int.Parse(ExamTestID.ToString()); JournalContext.ExamTestQuestions.InsertOnSubmit(question); JournalContext.SubmitChanges(); //question = JournalContext.ExamTestQuestions.First(q => q.ExamTestQuestionID == question.ExamTestQuestionID); var variantsList = variants.ToList(); for (int i = 0; i < variantsList.Count; ++i) { if (string.IsNullOrEmpty(variantsList[i])) continue; //var nextVariantId = JournalContext.ExamTestVariants.Max(x => x.ExamTestVariantID) + 1; var tVariant = new ExamTestVariant() { ExamTestQuestionID = question.ExamTestQuestionID, //ExamTestVariantID = nextVariantId, IsCorrect = corrected.Contains(i), VariantText = variantsList[i], }; JournalContext.ExamTestVariants.InsertOnSubmit(tVariant); } UploadFiles(fileUpload, question); JournalContext.SubmitChanges(); return RedirectToAction("Index"); }