Commit 28f73626 authored by 黄奎's avatar 黄奎

新增验证

parent 0c4f1611
...@@ -154,7 +154,14 @@ namespace Edu.Module.Question ...@@ -154,7 +154,14 @@ namespace Edu.Module.Question
break; break;
//共用选择题 //共用选择题
case "sharing-choose": case "sharing-choose":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(data); if (!string.IsNullOrEmpty(data))
{
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(data);
}
else
{
obj = null;
}
break; break;
//其它题 //其它题
case "other": case "other":
......
...@@ -163,7 +163,6 @@ namespace Edu.Module.Question ...@@ -163,7 +163,6 @@ namespace Edu.Module.Question
var extModel = questionRepository.GetEntity<RB_Question_ViewModel>(QuestionId); var extModel = questionRepository.GetEntity<RB_Question_ViewModel>(QuestionId);
if (extModel != null) if (extModel != null)
{ {
extModel.QuestionContentObj = ParsingQuestionModule(extModel.QuestionTypeKey, extModel.QuestionContent); extModel.QuestionContentObj = ParsingQuestionModule(extModel.QuestionTypeKey, extModel.QuestionContent);
if (!string.IsNullOrEmpty(extModel.Knowledge)) if (!string.IsNullOrEmpty(extModel.Knowledge))
{ {
......
...@@ -64,7 +64,6 @@ namespace Edu.WebApi.Controllers.Course ...@@ -64,7 +64,6 @@ namespace Edu.WebApi.Controllers.Course
} }
catch catch
{ {
} }
try try
{ {
...@@ -76,7 +75,6 @@ namespace Edu.WebApi.Controllers.Course ...@@ -76,7 +75,6 @@ namespace Edu.WebApi.Controllers.Course
} }
catch catch
{ {
} }
var list = questionModule.GetQuestionPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query); var list = questionModule.GetQuestionPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
List<object> resultList = new List<object>(); List<object> resultList = new List<object>();
...@@ -171,179 +169,248 @@ namespace Edu.WebApi.Controllers.Course ...@@ -171,179 +169,248 @@ namespace Edu.WebApi.Controllers.Course
return ApiResult.Failed(message: "请填写问题题干!"); return ApiResult.Failed(message: "请填写问题题干!");
} }
if (extModel.QuestionTypeKey == "single" || extModel.QuestionTypeKey == "multiple") //单选、多选、单选(数字)题
if (extModel.QuestionTypeKey == "single" || extModel.QuestionTypeKey == "multiple" || extModel.QuestionTypeKey == "single-number")
{ {
var optionItems = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(extModel.QuestionContent); var optionItems = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(extModel.QuestionContent);
if (optionItems != null && optionItems.Count > 0) string message = CheckChoose(optionItems);
if (!string.IsNullOrEmpty(message))
{ {
if (optionItems.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0) return ApiResult.Failed(message: message);
{ }
return ApiResult.Failed(message: "选项不能为空!"); }
} //填空题
//判断选项是否重复 else if (extModel.QuestionTypeKey == "fill-in")
if (optionItems.GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0) {
var fillInList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
string fillMessage = CheckFillIn(fillInList);
if (!string.IsNullOrEmpty(fillMessage))
{
return ApiResult.Failed(message: fillMessage);
}
}
//简答题
else if (extModel.QuestionTypeKey == "short-answer")
{
string shortMessage = CheckShortAnswer(extModel.Answer);
if (!string.IsNullOrEmpty(shortMessage))
{
return ApiResult.Failed(message: shortMessage);
}
}
//名词解释
else if (extModel.QuestionTypeKey == "noun-explanation")
{
if (string.IsNullOrEmpty(extModel.Answer))
{
return ApiResult.Failed(message: "请填写名词解释答案!");
}
}
//论述题
else if (extModel.QuestionTypeKey == "essay-question")
{
if (string.IsNullOrEmpty(extModel.Answer))
{
return ApiResult.Failed(message: "请填写论述题答案!");
}
}
//计算题
else if (extModel.QuestionTypeKey == "calculation")
{
if (string.IsNullOrEmpty(extModel.Answer))
{
return ApiResult.Failed(message: "请填写计算题答案!");
}
}
//分录题、资料题
else if (extModel.QuestionTypeKey == "entry-problem" || extModel.QuestionTypeKey == "data-question")
{
var entryList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
if (entryList != null && entryList.Count > 0)
{
if (entryList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{ {
return ApiResult.Failed(message: "选项不能相同!"); return ApiResult.Failed(message: "请输入答案!");
} }
if (string.IsNullOrEmpty(extModel.Answer)) }
else
{
return ApiResult.Failed(message: "请添加答案!");
}
}
//排序题
else if (extModel.QuestionTypeKey == "sorting-problem")
{
var sortList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
if (sortList != null && sortList.Count > 0)
{
if (sortList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{ {
return ApiResult.Failed(message: "请设置正确的选项!"); return ApiResult.Failed(message: "请输入选项内容!");
} }
} }
else else
{ {
return ApiResult.Failed(message: "请添加选择题选项!"); return ApiResult.Failed(message: "请添加选项!");
} }
} }
else if (extModel.QuestionTypeKey == "fill-in") //连线题
else if (extModel.QuestionTypeKey == "matching")
{ {
var fillInList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent); var matchList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
if (fillInList != null && fillInList.Count > 0) if (matchList != null && matchList.Count > 0)
{ {
if (fillInList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0) if (matchList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{ {
return ApiResult.Failed(message: "请输入答案!"); return ApiResult.Failed(message: "第一组选项内容不能为空!");
}
if (matchList[1].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{
return ApiResult.Failed(message: "第二组选项内容不能为空!");
} }
} }
else else
{ {
return ApiResult.Failed(message: "请添加答案!"); return ApiResult.Failed(message: "请添加选项!");
} }
} }
//完型填空
var obj = new object(); else if (extModel.QuestionTypeKey == "cloze")
switch (extModel.QuestionTypeKey)
{ {
var clozeList = Common.Plugin.JsonHelper.DeserializeObject<List<List<optionItem>>>(extModel.QuestionContent);
//填空题 if (clozeList != null && clozeList.Count > 0)
case "fill-in": {
int index = 1;
break; foreach (var subList in clozeList)
//判断题
case "judge":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(extModel.QuestionContent);
break;
//简答题
case "short-answer":
obj = extModel.QuestionContent;
break;
//名词解释
case "noun-explanation":
obj = extModel.QuestionContent;
break;
//论述题
case "essay-question":
obj = extModel.QuestionContent;
break;
//计算题
case "calculation":
obj = extModel.QuestionContent;
break;
//分录题
case "entry-problem":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
break;
//资料题
case "data-question":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
break;
//连线题
case "matching":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
break;
//排序题
case "sorting-problem":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
break;
//完型填空
case "cloze":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<optionItem>>>(extModel.QuestionContent);
break;
//阅读理解
case "reading-comprehensio":
var readingList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(extModel.QuestionContent);
if (readingList != null && readingList.Count > 0)
{ {
foreach (var item in readingList) if (subList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{ {
switch (item.QuestionKey) return ApiResult.Failed(message: string.Format("第{0}小题选项内容不能为空!", index));
{
//单选题
case "single":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
break;
//多选题
case "multiple":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
break;
//填空题
case "fill-in":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
break;
//判断题
case "judge":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
break;
//简答题
case "short-answer":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
break;
}
} }
if (!(subList.Where(qitem => qitem.IsAnswer == true).Count() > 0))
{
return ApiResult.Failed(message: string.Format("请设置第{0}小题选项的正确答案!", index));
}
index++;
} }
obj = readingList; }
break; else
//口语题 {
case "spoken": return ApiResult.Failed(message: "请添加小题!");
obj = extModel.QuestionContent; }
break; }
//听力题 //口语题
case "listening": else if (extModel.QuestionTypeKey == "spoken")
var listenList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(extModel.QuestionContent); {
if (listenList != null && listenList.Count > 0) if (string.IsNullOrEmpty(extModel.Answer))
{
return ApiResult.Failed(message: "请填写口语题答案!");
}
}
//其它题
else if (extModel.QuestionTypeKey == "other")
{
if (string.IsNullOrEmpty(extModel.Answer))
{
return ApiResult.Failed(message: "请填写其它题答案!");
}
}
//阅读理解和听力题
else if (extModel.QuestionTypeKey == "reading-comprehensio" || extModel.QuestionTypeKey == "listening")
{
var readingList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(extModel.QuestionContent);
if (readingList != null && readingList.Count > 0)
{
foreach (var item in readingList)
{ {
foreach (var item in listenList) if (string.IsNullOrEmpty(item.SubTitle))
{ {
switch (item.QuestionKey) return ApiResult.Failed(message: "请填写题干!");
{ }
//单选题 switch (item.QuestionKey)
case "single": {
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString()); //单选题
break; case "single":
//多选题 var singleAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
case "multiple": string singleMessage = CheckChoose(singleAnwser);
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString()); if (!string.IsNullOrEmpty(singleMessage))
break; {
//填空题 return ApiResult.Failed(message: singleMessage);
case "fill-in": }
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString()); break;
break; //多选题
//判断题 case "multiple":
case "judge": var multipleAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString()); string multipleMessage = CheckChoose(multipleAnwser);
break; if (!string.IsNullOrEmpty(multipleMessage))
//简答题 {
case "short-answer": return ApiResult.Failed(message: multipleMessage);
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString()); }
break; break;
} //填空题
case "fill-in":
var r_fillInList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
string r_fillMessage = CheckFillIn(r_fillInList);
if (!string.IsNullOrEmpty(r_fillMessage))
{
return ApiResult.Failed(message: r_fillMessage);
}
break;
//判断题
case "judge":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
break;
//简答题
case "short-answer":
var shortAnswer = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
string r_shortMessage = CheckShortAnswer(shortAnswer[0].Content);
if (!string.IsNullOrEmpty(r_shortMessage))
{
return ApiResult.Failed(message: r_shortMessage);
}
break;
} }
} }
obj = listenList; }
break; else
//共用选择题 {
case "sharing-choose": return ApiResult.Failed(message: "请添加小题!");
obj = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent); }
break; }
//其它题 //共用选择题
case "other": else if (extModel.QuestionTypeKey == "sharing-choose")
obj = extModel.QuestionContent; {
break; var shareList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
//单选题(数字) if (shareList != null && shareList.Count ==2)
case "single-number": {
obj = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(extModel.QuestionContent); if (shareList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
break; {
return ApiResult.Failed(message: string.Format("选项内容不能为空!"));
}
//判断选项是否重复
if (shareList[0].GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
{
return ApiResult.Failed(message: string.Format("选项内容不能相同!"));
}
if (shareList[1].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{
return ApiResult.Failed(message: string.Format("题干不能为空!"));
}
//判断题干是否重复
if (shareList[1].GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
{
return ApiResult.Failed(message: string.Format("题干不能相同!"));
}
//判断题干是否设置正确选项
if (shareList[1].Where(qitem => string.IsNullOrEmpty(qitem.Name)).Count() > 0)
{
return ApiResult.Failed(message: string.Format("请设置题干的正确选项!"));
}
}
else
{
return ApiResult.Failed(message: "请添加选项!");
}
} }
extModel.CreateTime = DateTime.Now; extModel.CreateTime = DateTime.Now;
extModel.CreateBy = base.UserInfo.Id; extModel.CreateBy = base.UserInfo.Id;
...@@ -354,19 +421,71 @@ namespace Edu.WebApi.Controllers.Course ...@@ -354,19 +421,71 @@ namespace Edu.WebApi.Controllers.Course
} }
/// <summary> /// <summary>
/// 批量添加修改问题 /// 选择题验证
/// </summary> /// </summary>
/// <param name="optionItems"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] private string CheckChoose(List<optionItem> optionItems)
public ApiResult SetQuestionBeatch()
{ {
bool flag=false; string message = "";
var list = Common.Plugin.JsonHelper.DeserializeObject<List<RB_Question_ViewModel>>(RequestParm.Msg.ToString()); if (optionItems != null && optionItems.Count > 0)
if (list != null && list.Count > 0)
{ {
flag = questionModule.SetQuestionBatchModule(list); if (optionItems.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{
message = "选项不能为空!";
}
//判断选项是否重复
if (optionItems.GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
{
message = "选项不能相同!";
}
if (!(optionItems.Where(qitem => qitem.IsAnswer == true).Count() > 0))
{
message = "请设置正确的选项!";
}
} }
return flag ? ApiResult.Success() : ApiResult.Failed(); else
{
message = "请添加选择题选项!";
}
return message;
}
/// <summary>
/// 验证填空题
/// </summary>
/// <param name="fillInList"></param>
/// <returns></returns>
private string CheckFillIn(List<fillInItem> fillInList)
{
string message = "";
if (fillInList != null && fillInList.Count > 0)
{
if (fillInList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
{
message = "请输入答案!";
}
}
else
{
message = "请添加答案!";
}
return message;
}
/// <summary>
/// 验证简答题
/// </summary>
/// <param name="answer"></param>
/// <returns></returns>
private string CheckShortAnswer(string answer)
{
string message = "";
if (string.IsNullOrEmpty(answer))
{
message= "请填写简答题答案!";
}
return message;
} }
/// <summary> /// <summary>
...@@ -381,6 +500,24 @@ namespace Edu.WebApi.Controllers.Course ...@@ -381,6 +500,24 @@ namespace Edu.WebApi.Controllers.Course
return ApiResult.Success(data: extModel); return ApiResult.Success(data: extModel);
} }
/// <summary>
/// 批量添加修改问题
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetQuestionBeatch()
{
bool flag=false;
var list = Common.Plugin.JsonHelper.DeserializeObject<List<RB_Question_ViewModel>>(RequestParm.Msg.ToString());
if (list != null && list.Count > 0)
{
flag = questionModule.SetQuestionBatchModule(list);
}
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary> /// <summary>
/// 删除课程问题 /// 删除课程问题
/// </summary> /// </summary>
...@@ -486,6 +623,7 @@ namespace Edu.WebApi.Controllers.Course ...@@ -486,6 +623,7 @@ namespace Edu.WebApi.Controllers.Course
} }
#endregion #endregion
#region 问题导入
/// <summary> /// <summary>
/// 导入Excel问题 /// 导入Excel问题
/// </summary> /// </summary>
...@@ -1067,5 +1205,7 @@ namespace Edu.WebApi.Controllers.Course ...@@ -1067,5 +1205,7 @@ namespace Edu.WebApi.Controllers.Course
model.QuestionTypeKey = tempModel?.Key ?? ""; model.QuestionTypeKey = tempModel?.Key ?? "";
} }
} }
#endregion
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment