代码优化

master
xiaochanghai 1 year ago
parent 8d9350b1d3
commit c5ad146e9a
  1. 76
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -1,22 +1,16 @@
 
using Tiobon.Core.IServices;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.Model;
using System.Dynamic;
using Newtonsoft.Json.Linq;
using AgileObjects.AgileMapper;
using Mysqlx.Crud;
using AgileObjects.AgileMapper.Extensions;
using System.Data; using System.Data;
using AgileObjects.AgileMapper;
using Tiobon.Core.Common; using Tiobon.Core.Common;
using Tiobon.Core.Common.DB.Dapper; using Tiobon.Core.Common.DB.Dapper;
using MySqlX.XDevAPI.Common; using Tiobon.Core.IRepository.Base;
using System.Collections.Generic; using Tiobon.Core.IServices;
using Tiobon.Core.Model;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
namespace Tiobon.Core.Services;
namespace Tiobon.Core.Services
{
/// <summary> /// <summary>
/// 题目 (服务) /// 题目 (服务)
/// </summary> /// </summary>
@ -54,17 +48,7 @@ namespace Tiobon.Core.Services
x.DifficultyLevel = "普通"; x.DifficultyLevel = "普通";
else if (x.DifficultyLevel == "Hard") else if (x.DifficultyLevel == "Hard")
x.DifficultyLevel = "困难"; x.DifficultyLevel = "困难";
x.QuestionType = ConvertQuestionType(x.QuestionType);
if (x.QuestionType == "Single")
x.QuestionType = "单选题";
else if (x.QuestionType == "Multiple")
x.QuestionType = "多选题";
else if (x.QuestionType == "TrueOrFalse")
x.QuestionType = "判断题";
else if (x.QuestionType == "Completion")
x.QuestionType = "填空题";
else if (x.QuestionType == "ShortAnswer")
x.QuestionType = "简答题";
if (x.CourseId != null) if (x.CourseId != null)
{ {
@ -75,10 +59,7 @@ namespace Tiobon.Core.Services
} }
}); });
return new ServicePageResult<Ghre_QuestionDto>(body.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data); return new ServicePageResult<Ghre_QuestionDto>(body.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data);
} }
/// <summary> /// <summary>
@ -229,17 +210,7 @@ namespace Tiobon.Core.Services
public async Task<ServiceResult> InsertFrom(FromGhre_QuestionPageData insertModel) public async Task<ServiceResult> InsertFrom(FromGhre_QuestionPageData insertModel)
{ {
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
string questionTypeName = string.Empty; string questionTypeName = ConvertQuestionType(questionType.type);
if (questionType.type == "Single")
questionTypeName = "单选题";
else if (questionType.type == "Multiple")
questionTypeName = "多选题";
else if (questionType.type == "TrueOrFalse")
questionTypeName = "判断题";
else if (questionType.type == "Completion")
questionTypeName = "填空题";
else if (questionType.type == "ShortAnswer")
questionTypeName = "简答题";
#region 判断是否重复 #region 判断是否重复
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) for (int j = 0; j < insertModel.baseData.courseID.Count; j++)
@ -296,17 +267,7 @@ namespace Tiobon.Core.Services
public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel) public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel)
{ {
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault();
string questionTypeName = string.Empty; string questionTypeName = ConvertQuestionType(questionType.type);
if (questionType.type == "Single")
questionTypeName = "单选题";
else if (questionType.type == "Multiple")
questionTypeName = "多选题";
else if (questionType.type == "TrueOrFalse")
questionTypeName = "判断题";
else if (questionType.type == "Completion")
questionTypeName = "填空题";
else if (questionType.type == "ShortAnswer")
questionTypeName = "简答题";
#region 判断是否重复 #region 判断是否重复
for (int j = 0; j < editModel.baseData.courseID.Count; j++) for (int j = 0; j < editModel.baseData.courseID.Count; j++)
@ -454,5 +415,20 @@ namespace Tiobon.Core.Services
} }
catch (Exception) { throw; } catch (Exception) { throw; }
} }
public static string ConvertQuestionType(string type)
{
string questionTypeName = string.Empty;
if (type == "Single")
questionTypeName = "单选题";
else if (type == "Multiple")
questionTypeName = "多选题";
else if (type == "TrueOrFalse")
questionTypeName = "判断题";
else if (type == "Completion")
questionTypeName = "填空题";
else if (type == "ShortAnswer")
questionTypeName = "简答题";
return questionTypeName;
} }
} }
Loading…
Cancel
Save