NewGaoKaoApi/New_College.Services/Test_QuestionInfoServices.cs

95 lines
3.5 KiB
C#

using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
using New_College.Model.ViewModels;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using New_College.IRepository;
using System.Linq;
namespace New_College.Services
{
public class Test_QuestionInfoServices : BaseServices<Test_QuestionInfo>, ITest_QuestionInfoServices
{
private readonly IBaseRepository<Test_QuestionInfo> _dal;
private readonly ITest_QuestionTypeInfoRepository _QuestionTypeInfoRepository;
public Test_QuestionInfoServices(IBaseRepository<Test_QuestionInfo> dal
, ITest_QuestionTypeInfoRepository ITest_QuestionTypeInfoRepository)
{
this._dal = dal;
_QuestionTypeInfoRepository = ITest_QuestionTypeInfoRepository;
base.BaseDal = dal;
}
/// <summary>
/// 获取问题
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public async Task<List<appQuestionResult>> GetQuestion(appQuestionQuery query)
{
var info = await _dal.Query(x => x.IsDelete == false && x.CategoryId == query.CategoryId);
if (info == null)
return new List<appQuestionResult>() { };
List<appQuestionResult> list = new List<appQuestionResult>() { };
if (query.CategoryId == 20)
{
List<string> subject = new List<string>() { "物理", "化学", "生物", "政治", "历史", "地理" };
int sort = 1;
foreach (var x in subject)
{
foreach (var item in info)
{
list.Add(new appQuestionResult()
{
Id = item.Id,
IsAddScore = item.IsAddScore,
QuestionSort = sort++,// item.OrderSort,
QuestionTag = x,
QuestionTitle = "对于" + x + "," + item.QuestionTitle,
QuestionType = item.QuestionType,
QuestionTypeId = item.QuestionTypeId
});
}
}
return list;
}
foreach (var item in info)
{
list.Add(new appQuestionResult()
{
Id = item.Id,
IsAddScore = item.IsAddScore,
QuestionSort = item.OrderSort,
QuestionTag = item.QuestionTag,
QuestionTitle = item.QuestionTitle,
QuestionType = item.QuestionType,
QuestionTypeId = item.QuestionTypeId
});
}
return list;
}
/// <summary>
/// 获取mbti试题
/// </summary>
/// <returns></returns>
public async Task<List<QuestionMBTI>> GetQuestionMBTI()
{
var info = await _dal.Query(x => x.IsDelete == false && x.CategoryId == 19);
if (info == null)
return new List<QuestionMBTI>() { };
return info.Select(s => new QuestionMBTI()
{
Answers = JsonConvert.DeserializeObject<List<MBTIProperty>>(s.QuestionTag),
QuestionSort = s.OrderSort,
QuestionTitle = s.QuestionTitle
}).ToList();
}
}
}