123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMISOnline.DataLogic.Repositories;
- using System.Linq.Expressions;
- using EMISOnline.Entities;
- using System.Data;
- using EMISOnline.DataLogic.ExamSetting;
- using EMISOnline.ViewModel.Coursework;
- using EMISOnline.ViewModel.ExamView;
- using System.Xml.Linq;
- namespace EMISOnline.DataLogic.CourseworkMgr
- {
- public class CourseworkDAL : SqlHelper
- {
- public CourseworkRepository CourseworkRepository { get; set; }
- public CourseworkResultRepository ResultRepository { get; set; }
- public CourseworkAnswerRepository AnswerRepository { get; set; }
- public paper_question_setRepository question_setRepository { get; set; }
- public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
- public EducationMissionRepository EducationMissionRepository { get; set; }
- public ExecutablePlanRepository ExecutablePlanRepository { get; set; }
- public CoursematerialRepository CoursematerialRepository { get; set; }
- public GrademajorRepository GrademajorRepository { get; set; }
- public SchoolyearRepository SchoolyearRepository { get; set; }
- public IQueryable<CourseworkAddView> GetCourseworkList(Expression<Func<Coursework, bool>> testExpression)
- {
- var query = from q in CourseworkRepository.Entities.Where(testExpression)
- join emc in EducationMissionClassRepository.Entities on q.EducationMissionClassID equals emc.EducationMissionClassID
- join em in EducationMissionRepository.Entities on emc.EducationMissionID equals em.EducationMissionID
- join cm in CoursematerialRepository.Entities on emc.CoursematerialID equals cm.CoursematerialID
- join sy in SchoolyearRepository.Entities on em.SchoolyearID equals sy.SchoolyearID
- select new CourseworkAddView()
- {
- test_paper_name = q.test_paper.PaperName,
- WorkName = q.WorkName,
- id = q.ID,
- test_begin_date = q.BeginTime,
- test_end_date = q.EndTime,
- CoursematerialName=cm.CourseName
- };
- return query.AsQueryable();
- }
- public IQueryable<CourseworkReviewView> GetReviewList(Expression<Func<CourseworkResult, bool>> testExpression)
- {
- var query = from r in ResultRepository.Entities.Where(testExpression)
- join c in CourseworkRepository.Entities on r.workid equals c.ID
- select new CourseworkReviewView()
- {
- ResultID = r.ID,
- user_id = r.user_id,
- username = r.username,
- test_end_date = r.test_end_date,
- score = r.score,
- state = r.state,
- WorkName = c.WorkName,
- PaperName = c.test_paper.PaperName
- };
- return query.AsQueryable();
- }
- /// <summary>
- /// 修改分配的试卷ID
- /// </summary>
- /// <param name="test_id"></param>
- /// <param name="userid"></param>
- /// <param name="paperID"></param>
- /// <returns></returns>
- public bool UpdatePaperID(decimal workid, string userid, decimal paperID)
- {
- //删除原试卷数据
- var paper = from p in PaperRepository.Entities
- join t in CourseworkRepository.Entities on p.test_paper_parent_id equals t.PaperID
- where t.ID == workid
- select p;
- if (paper != null && paper.Count() > 0)
- {
- var paperid = paper.ToArray()[0].test_paper_id;
- Expression<Func<test_paper_question_set, bool>> whereExpression = (q => q.test_paper_id == paperid);
- question_setRepository.UnitOfWork.Delete(whereExpression);
- //context.test_paper_question_set_fortest.Delete(q => q.test_paper_id == paperid);
- Expression<Func<test_paper, bool>> paperExpression = (q => q.test_paper_id == paperid);
- PaperRepository.UnitOfWork.Delete(paperExpression);
- question_setRepository.UnitOfWork.Commit();
- }
- var result = ResultRepository.Entities.Where(q => q.workid == workid && q.user_id == userid).FirstOrDefault();
- if (result != null)
- {
- result.test_paper_id = paperID;
- question_setRepository.UnitOfWork.Commit();
- return true;
- }
- return false;
- }
- public DataSet PaperBuilder(decimal workid, decimal paper_id)
- {
- var ds = Query("dbo.sp_coursework_paper",
- new KeyValuePair<string, object>("@workid", workid),
- new KeyValuePair<string, object>("@test_paper_id", paper_id));
- return (ds);
- }
- public List<AnswerXml> ExamineeAnswers(decimal workid)
- {
- var paperset = AnswerRepository.GetSingle(q => q.workid == workid);
- XElement xml = XElement.Parse(paperset.resultXml);
- var question_set = from c in xml.Descendants("AnswerXml")
- select new AnswerXml
- {
- test_question_Id = decimal.Parse(c.Element("test_question_Id").Value),
- answers = c.Element("answers").Value,
- src_score = decimal.Parse(c.Element("src_score").Value),
- act_score = decimal.Parse(c.Element("act_score").Value),
- };
- return question_set.ToList();
- }
-
- }
- }
|