ComplianceServer/oldcode/BLL/Exam/EXAM_PAPER_BL.cs

46 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using WX.CRM.IBLL.Exam;
using WX.CRM.Model.Entity;
namespace WX.CRM.BLL.Exam
{
public class EXAM_PAPER_BL : DbContextRepository<EXAM_PAPER>, IEXAM_PAPER
{
public bool HandExamPaper(decimal eid, decimal paperId, Dictionary<decimal, string> answerList)
{
using (var db = new crmContext())
{
var paper = db.EXAM_PAPER.FirstOrDefault(p => p.EID == eid && p.ID == paperId);
if (paper == null)
{
return false;
}
//如果已经交过卷,直接返回
if (paper.HANDTIME.HasValue)
return true;
paper.HANDTIME = DateTime.Now;
paper.USETIME = (paper.HANDTIME - paper.STARTTIME).Value.Seconds;
var paperSubject = db.EXAM_PAPERSUBJECT.Where(p => p.PAPERID == paper.ID);
var score = 0;
foreach (var item in paperSubject)
{
var answer = answerList.FirstOrDefault(p => p.Key == item.ID).Value;
if (item.RIGHTANSWER == answer)
{
score++;
}
item.ANSWER = answer;
}
paper.SCORE = score;
db.SaveChanges();
return true;
}
}
}
}