public HttpResponseMessage EditExam([FromBody] ExamInfo m) { if (m == null) { return(ResultHelper.Failed("类容不能为空")); } var eInfo = MongoDbHelper.FindOne <E_Info>(m.ID, DbName.E_Info); if (eInfo == null) { return(ResultHelper.Failed("未找到该次考试信息")); } eInfo.tet = m.TchEndTime; eInfo.set = m.StuEndTime; eInfo.enm = m.ExamName; if (Function.ConvertDateI(DateTime.Now) < eInfo.sst && Function.ConvertDateI(DateTime.Now) < eInfo.tst)//考试还没开始导入 { eInfo.sst = m.StuStartTime; eInfo.tst = m.TchStartTime; eInfo.stcfm = 0; eInfo.tchcfm = 0; eInfo.sbs = new List <Sb>(); eInfo.stps = new List <Stp>(); foreach (var item in m.subNames) { Sb sb = new Sb(); sb._id = item.Key; sb.sbnm = item.Value; sb.stct = 0; sb.tchct = 0; eInfo.sbs.Add(sb); } string[] stuType = m.stuTypes.Split(','); foreach (var item in stuType) { Stp sTp = new Stp() { _id = ObjectId.GenerateNewId(), tp = item }; eInfo.stps.Add(sTp); } } MongoDbHelper.ReplaceOne(m.ID, eInfo, DbName.E_Info); return(ResultHelper.OK()); }
public HttpResponseMessage AddExam([FromBody] ExamInfo m) { var hisExam = MongoDbHelper.QueryOne <E_Info>(DbName.E_Info, w => w.btstate == 0 && w.IsDel == 0); if (hisExam != null) { return(ResultHelper.Failed("已存在进行中的考试")); } if (m == null) { return(ResultHelper.Failed("类容不能为空")); } E_Info eInfo = new E_Info() { _id = ObjectId.GenerateNewId(), ppid = m.PublishID, pt = Function.ConvertDateI(DateTime.Now), enm = m.ExamName, sst = m.StuStartTime, set = m.StuEndTime, tst = m.TchStartTime, tet = m.TchEndTime, stcfm = 0, tchcfm = 0, btstate = 0, IsDel = 0 }; foreach (var item in m.subNames) { Sb sb = new Sb(); sb._id = item.Key; sb.sbnm = item.Value; sb.stct = 0; sb.tchct = 0; eInfo.sbs.Add(sb); } string[] stuType = m.stuTypes.Split(','); foreach (var item in stuType) { Stp sTp = new Stp() { _id = ObjectId.GenerateNewId(), tp = item }; eInfo.stps.Add(sTp); } MongoDbHelper.Insert(eInfo, DbName.E_Info); var allsch = MongoDbHelper.QueryBy <U_Info>(DbName.U_Info, w => w.tp == 1); List <Sch_Sc> ls = new List <Sch_Sc>(); for (int i = 0; i < allsch.Count; i++) { Sch_Sc sc = new Sch_Sc(); sc.eid = eInfo._id; sc.sid = allsch[i]._id; sc.state = 0; sc.snm = allsch[i].snm; sc.area = allsch[i].area; ls.Add(sc); } MongoDbHelper.Insert(ls, DbName.Sch_Sc); return(ResultHelper.OK()); }