using CRM.Core.Common.Layui; using System; using System.Collections.Generic; using WX.CRM.Common; namespace ZXDService { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“ExamService”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 ExamService.svc 或 ExamService.svc.cs,然后开始调试。 public class ExamService : IExamService { private readonly CRM.Core.BLL.Application.Exam.ExamService examService = new CRM.Core.BLL.Application.Exam.ExamService(); public ExamService() { //if (WebOperationContext.Current != null) //{ // WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); // WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); //} } public ExamResult Gen(int type, string appid, string appuserid) { try { if (string.IsNullOrEmpty(appid) || string.IsNullOrEmpty(appuserid)) { return null; } var data = examService.GenerateExam(type, appid, appuserid); var result = new ExamResult { isNew = data.isNew, paper = data.paper, singleSubject = data.singleSubject, composeSubject = data.composeSubject }; return result; } catch (Exception ex) { LogHelper.Error(ex.ToString()); return null; } } public JsonResult Save(CRM.Core.BLL.Application.Exam.AnswerDto dto) { try { //LogHelper.Info(dto.ToJson()); var result = examService.Save(dto); //var result = true; return new JsonResult() { result = result, retcode = 200, retmsg = result.ToString() }; } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new JsonResult() { result = false, retcode = 500, retmsg = "保存失败!" }; } } public PageResult> List(string appid, string appuserid, int type, DateTime sTime, DateTime eTime, int page, int limit) { try { var pager = new Laypage() { page = page > 0 ? page : 1, limit = limit > 0 ? limit : 10 }; var data = examService.List(ref pager, appid, appuserid, type > 0 ? type : (int?)null, sTime == DateTime.MinValue ? (DateTime?)null : sTime, eTime == DateTime.MinValue ? (DateTime?)null : eTime); var list = new List(); foreach (var item in data) { var info = new ExamPaperView() { ID = item.ID, TITLE = item.TITLE, TYPE = item.TYPE, TYPENAME = item.TYPENAME, TOTALSCORE = item.TOTALSCORE, SCORE = item.SCORE, STARTTIME = item.STARTTIME.ToString(), ENDTIME = item.ENDTIME.ToString(), TIMELENGTH = item.TIMELENGTH, HANDTIME = item.HANDTIME.ToString(), USETIME = item.USETIME, APPID = item.APPID, APPUSERID = item.APPUSERID }; list.Add(info); } return new PageResult>() { pageindex = pager.page, pagecount = pager.count, data = list }; } catch (Exception ex) { LogHelper.Error(ex.ToString()); return new PageResult>() { pageindex = 1, pagecount = 0, data = null }; } } public ExamResult Show(int paperId) { try { var data = examService.Show(paperId); var result = new ExamResult { isNew = data.isNew, paper = data.paper, singleSubject = data.singleSubject, composeSubject = data.composeSubject }; return result; } catch (Exception ex) { LogHelper.Error(ex.ToString()); return null; } } } public class ExamPaperView { public int ID { get; set; } /// /// 试卷名 /// public string TITLE { get; set; } /// /// 试卷类型 /// public int TYPE { get; set; } /// /// 试卷类型名称 /// public string TYPENAME { get; set; } /// /// 试卷总分 /// public decimal TOTALSCORE { get; set; } /// /// 得分 /// public decimal? SCORE { get; set; } /// /// 考试开始时间 /// public string STARTTIME { get; set; } /// /// 考试结束时间 /// public string ENDTIME { get; set; } /// /// 考试时长 /// public int TIMELENGTH { get; set; } /// /// 交卷时间 /// public string HANDTIME { get; set; } /// /// 用时 /// public int? USETIME { get; set; } public string APPID { get; set; } public string APPUSERID { get; set; } } }