|
|
|
@ -570,20 +570,14 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question WHERE QuestionType='{0}' AND CourseId='{1}' AND QuestionContent ='{2}' AND Id !='{3}' AND IsEnable =1"; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question WHERE QuestionType='{0}' AND CourseIds like'%{1}%' AND QuestionContent ='{2}' AND Id !='{3}' AND IsEnable =1"; |
|
|
|
|
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id); |
|
|
|
|
DataTable dt = Db.Ado.GetDataTable(sql); |
|
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
|
{ |
|
|
|
|
//var course = await _ghre_CourseServices.QueryById(courseID); |
|
|
|
|
//throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】"); |
|
|
|
|
throw new Exception($"题库中存在相同题目"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = await base.QueryById(Id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id); |
|
|
|
|
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>(); |
|
|
|
@ -593,6 +587,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
edit.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
edit.QuestionContent = questionType.detail.content; |
|
|
|
|
edit.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
edit.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); |
|
|
|
|
|
|
|
|
|
await base.Update(Id, edit); |
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
@ -627,42 +622,42 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
// continue; |
|
|
|
|
|
|
|
|
|
//var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); |
|
|
|
|
//var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
//insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
//insert.QuestionType = questionType.type; |
|
|
|
|
//insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
//insert.QuestionContent = questionType.detail.content; |
|
|
|
|
//insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
//insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
//var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) |
|
|
|
|
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); |
|
|
|
|
if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) |
|
|
|
|
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); |
|
|
|
|
|
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
//insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
//{ |
|
|
|
|
// QuestionNo = x.No, |
|
|
|
|
// AnswerContent = x.label, |
|
|
|
|
// ImageUrl = x.imageUrl, |
|
|
|
|
// ImageWidthPc = x.imgWidthPc, |
|
|
|
|
// ImageWidthApp = x.imgWidthApp, |
|
|
|
|
//}).ToList(); |
|
|
|
|
//i = 100; |
|
|
|
|
//insertAnswers.ForEach(x => |
|
|
|
|
//{ |
|
|
|
|
// x.TaxisNo = i; |
|
|
|
|
// x.QuestionId = id; |
|
|
|
|
// if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) |
|
|
|
|
// x.IsCorrect = true; |
|
|
|
|
// if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) |
|
|
|
|
// x.IsCorrect = true; |
|
|
|
|
// i = i + 100; |
|
|
|
|
//}); |
|
|
|
|
//if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) |
|
|
|
|
// throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); |
|
|
|
|
//if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) |
|
|
|
|
// throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); |
|
|
|
|
|
|
|
|
|
//await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
//} |
|
|
|
|
await Db.Ado.CommitTranAsync(); |
|
|
|
|
|
|
|
|
|