public Int32 GetNewId(String tableName, String prefix) { Int32 id, timeout; String sql; sql = "SELECT COUNT(" + prefix + "AutoId) FROM " + tableName; id = Convert.ToInt32(olsDbo.ExecuteSqlScalar(sql)); if (0 != id) { sql = "SELECT TOP 1 " + prefix + "AutoId FROM " + tableName + " ORDER BY " + prefix + "AutoId DESC"; id = Convert.ToInt32(olsDbo.ExecuteSqlScalar(sql)); } // 避免 Id重复 timeout = 0; do { id += 1; sql = "SELECT " + prefix + "Id FROM " + tableName + " WHERE " + prefix + "Id = " + id; timeout += 1; if (timeout == 100) { StaticHelper.RecordSystemLog(SystemLogType.Error, "获取编号时超出循环限制次数", sql); throw new Exception("获取编号时超出循环限制次数"); } } while (null != olsDbo.ExecuteSqlScalar(sql)); return(id); }
public VMExaminationTaskPersonalStatistic GetPersonalStatistic(Int32 uId) { try { String sql; SqlParameter sp; DataTable dataTable; List <VMExaminationTaskPersonalStatistic> etpss; sql = "SELECT * FROM ExaminationTaskPersonalStatistic WHERE ETPS_UserId = @uId"; sp = new SqlParameter("@uId", uId); dataTable = olsDbo.GetDataTable(sql, sp); etpss = (List <VMExaminationTaskPersonalStatistic>) ModelConvert <VMExaminationTaskPersonalStatistic> .ConvertToModel(dataTable); if (etpss.Count == 0) { return(null); } return(etpss[0]); } catch (Exception ex) { StaticHelper.GetExceptionMessageAndRecord(ex); return(null); } }
public Boolean CheckOldPassword(Int32 uId, String oldPassword) { try { User model; model = olsEni.Users.SingleOrDefault(m => m.U_Id == uId && m.U_Status == (Byte)Status.Available); if (null == model) { return(false); } oldPassword = EncryptPassword(oldPassword); if (oldPassword == model.U_Password) { return(true); } return(false); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
private Int32 HandleRepeat(Double sort) { try { Int32 count; User sortRepeatUser; count = 0; sortRepeatUser = olsEni.Users.SingleOrDefault(m => m.U_Sort == sort); while (sortRepeatUser != null) { sort = Math.Round(sort + 0.00001, 5, MidpointRounding.AwayFromZero); sortRepeatUser.U_Sort = sort; if (0 == olsEni.SaveChanges()) { return(-2); } count += 1; sortRepeatUser = olsEni.Users.SingleOrDefault(m => m.U_Id != sortRepeatUser.U_Id && m.U_Sort == sort); } return(count); } catch (Exception ex) { StaticHelper.GetExceptionMessageAndRecord(ex); return(-1); } }
public Boolean Edit(PermissionCategory model) { try { DateTime now; now = DateTime.Now; if (null == model.PC_Level) { model.PC_Level = String.Format("{0:D4}", model.PC_Id); } olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); UpdatePermission(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public ResponseJson Create(Duty model) { ResponseJson resJson; resJson = new ResponseJson(ResponseStatus.Success, now); try { Int32 id; id = GetDuId(); model.Du_Id = id; model.Du_Sort = id; olsEni.Duties.Add(model); olsEni.SaveChanges(); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); } return(resJson); }
public Boolean Create(PermissionCategory model) { try { DateTime now; Int32 id; now = DateTime.Now; id = GetPCId(); model.PC_Id = id; if (null == model.PC_Level) { model.PC_Level = String.Format("{0:D4}", model.PC_Id); } olsEni.PermissionCategories.Add(model); olsEni.SaveChanges(); UpdatePermission(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public ResponseJson SetStatus(Int32 id, Status status) { ResponseJson resJson; resJson = new ResponseJson(); try { PermissionCategory model; model = olsEni.PermissionCategories.SingleOrDefault(m => m.PC_Id == id); if (null == model) { resJson.message = "数据不存在!"; return(resJson); } model.PC_Status = (Byte)status; olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public ResponseJson SetStatus(Int32 id, Status status) { ResponseJson resJson; resJson = new ResponseJson(); try { Question q; q = olsEni.Questions.SingleOrDefault(m => m.Q_Id == id); if (null == q) { resJson.message = "数据不存在!"; return(resJson); } ResumeClassify(q.QC_Id, status); q.Q_Status = (Byte)status; olsEni.Entry(q).State = EntityState.Modified; olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public ResponseJson SetScore(int id, int score) { ResponseJson resJson; resJson = new ResponseJson(); try { Question model; model = olsEni.Questions.SingleOrDefault(m => m.Q_Id == id); if (null == model) { resJson.message = "数据不存在!"; return(resJson); } model.Q_Score = score; olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public ResponseJson SetStatus(Int32 id, Status status) { throw new NotImplementedException(); ResponseJson resJson; resJson = new ResponseJson(); try { ExaminationPaperTemplate model; model = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.EPT_Id == id); if (null == model) { resJson.message = "数据不存在!"; return(resJson); } model.EPT_Status = (Byte)status; olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public Boolean Edit(ExaminationPaperTemplate model) { throw new NotImplementedException(); try { // 已过考试开始时间/已经手动开始,不可修改模板 if (model.EPT_PaperTemplateStatus >= 2) { return(false); } olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); AddQuestionTemplate(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public Boolean Create(Department model) { try { Int32 id; id = GetDId(); model.D_Id = id; model.D_Sort = id; if (null == model.D_Level) { model.D_Level = String.Format("{0:D4}", model.D_Id); } olsEni.Departments.Add(model); olsEni.SaveChanges(); UpdateDepartmentRole(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public String Edit(ExaminationTask model) { using (TransactionScope scope = new TransactionScope()) { try { ExaminationTask et; et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == model.ET_Id); // 已开始/已结束的手动任务不允许编辑 if (et.ET_Mode == 0 && et.ET_Enabled != 0) { return("不允许修改进行中或已结束的手动任务。"); } // 已开始的自动任务不允许编辑 else if (et.ET_Mode == 1 && et.ET_Enabled == 1) { return("不允许修改进行中自动任务。"); } // 已开始/已结束的预定任务不允许编辑 else if (et.ET_Mode == 2 && et.ET_Enabled != 0) { return("不允许修改进行中或已结束的预定任务。"); } olsEni.Entry(et).State = EntityState.Detached; olsEni.Entry(model).State = EntityState.Modified; if (0 == olsEni.SaveChanges()) { throw new Exception(ResponseMessage.SaveChangesError); } try { // 删除试卷模板与试题模板 DeletePaperTemplateAndQuestionTemplate(model); // 添加试卷模板与试题模板 AddPaperTemplateAndQuestionTemplate(model); // 添加参与人员 AddAttendees(model); } catch (Exception ex1) { throw ex1; } scope.Complete(); return(null); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(ex.Message); } } }
public ResponseJson ModifyPassword(Int32 uId, String oldPassword, String newPassword) { ResponseJson resJson; resJson = new ResponseJson(); try { User model; model = olsEni.Users.SingleOrDefault(m => m.U_Id == uId && m.U_Status == (Byte)Status.Available); if (null == model) { resJson.status = ResponseStatus.Error; resJson.message = "用户不存在。"; return(resJson); } oldPassword = EncryptPassword(oldPassword); if (oldPassword != model.U_Password) { resJson.status = ResponseStatus.Error; resJson.message = "旧密码不正确。"; return(resJson); } // 不允许将密码设置为“**********” if (newPassword == "**********") { resJson.status = ResponseStatus.Error; resJson.message = "新密码无效。"; return(resJson); } newPassword = EncryptPassword(newPassword); model.U_Password = newPassword; if (olsEni.SaveChanges() == 0) { resJson.status = ResponseStatus.Error; resJson.message = "密码修改失败。"; return(resJson); } resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
internal ResponseJson CacheClear() { ResponseJson resJson; resJson = new ResponseJson(); try { List <Question> qs; List <QuestionClassify> qcs; qs = olsEni.Questions.Where(m => m.Q_Status == (Byte)Status.Cache).ToList(); foreach (var q in qs) { olsEni.Entry(q).State = EntityState.Deleted; } if (olsEni.SaveChanges() == 0) { resJson.status = ResponseStatus.Error; resJson.message = "缓存清除失败。"; return(resJson); } // 获取状态为“缓存”的分类 // 状态为“缓存”的分类中没有“正常”的试题,所以,如果其中仍存在试题,状态只可能是“回收”和“删除”两种类型 qcs = olsEni.QuestionClassifies.Where(m => m.QC_Status == (Byte)Status.Cache).ToList(); foreach (var qc in qcs) { if (olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id).Count() == 0) { olsEni.Entry(qc).State = EntityState.Deleted; } // 如果所有试题状态为“删除”,则将分类状态也设为“删除” else if (olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id).Count() == olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id && m.Q_Status == (Byte)Status.Delete).Count()) { qc.QC_Status = (Byte)Status.Delete; } // 否则设为“回收” else { qc.QC_Status = (Byte)Status.Recycle; } } olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
/*public ResponseJson GetQuestions(Int32 id, Int32 uId) * { * * ResponseJson resJson; * * resJson = new ResponseJson(); * * try * { * * Int32 epId; * ExaminationPaper ep; * List<ExaminationPaperQuestion> epqs; * List<ExaminationPaperTemplateQuestion> eptqs; * * ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EPT_Id == id && m.EP_UserId == uId); * * if (null == ep) * { * resJson.status = ResponseStatus.Error; * resJson.message = "未考试"; * return resJson; * } * * if (ep.EP_PaperStatus != (Byte)PaperStatus.Done) * { * resJson.status = ResponseStatus.Error; * resJson.message = "考试未结束"; * return resJson; * } * * epId = ep.EP_Id; * * eptqs = * olsEni * .ExaminationPaperTemplateQuestions * .Where(m => * m.EPT_Id == id * && m.EPTQ_Status == (Byte)Status.Available) * .ToList(); * epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == epId).ToList(); * * resJson.status = ResponseStatus.Success; * resJson.data = JsonConvert.SerializeObject(new Object[] { eptqs, epqs, epId }); * return resJson; * } * catch (Exception ex) * { * resJson.status = ResponseStatus.Error; * resJson.message = ex.Message; * resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); * return resJson; * } * }*/ public ResponseJson GetQuestions(Int32 id, Int32 epId, Int32 uId) { ResponseJson resJson; resJson = new ResponseJson(); try { ExaminationPaper ep; List <ExaminationPaperQuestion> epqs; List <ExaminationPaperTemplateQuestion> eptqs; ExaminationPaperTemplate ept; ExaminationTask et; ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == epId && m.EP_UserId == uId); if (null == ep) { resJson.status = ResponseStatus.Error; resJson.message = "未考试"; return(resJson); } if (ep.EP_PaperStatus != (Byte)PaperStatus.Done) { resJson.status = ResponseStatus.Error; resJson.message = "考试未结束"; return(resJson); } eptqs = olsEni .ExaminationPaperTemplateQuestions .Where(m => m.EPT_Id == id && m.EPTQ_Status == (Byte)Status.Available) .ToList(); epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == epId).ToList(); ept = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == id); et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ept.ET_Id); resJson.status = ResponseStatus.Success; resJson.data = JsonConvert.SerializeObject(new Object[] { eptqs, epqs, epId }); resJson.addition = et; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
/// <summary> /// 终止考试 /// </summary> /// <param name="id"></param> /// <returns></returns> public ResponseJson Terminate(Int32 id) { ResponseJson resJson; resJson = new ResponseJson(); try { ExaminationPaperTemplate model; ExaminationTask et; List <ExaminationPaper> eps; model = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == id); // 终止“手动”试卷模板时,应同时结束任务 et = olsEni.ExaminationTasks.Single(m => m.ET_Id == model.ET_Id); if ((Byte)AutoType.Manual == et.ET_AutoType) { et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled; } model.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done; olsEni.Entry(model).State = EntityState.Modified; eps = olsEni.ExaminationPapers .Where(m => m.EPT_Id == id && m.EP_Status == (Byte)Status.Available) .ToList(); foreach (var ep in eps) { ep.EP_PaperStatus = (Byte)PaperStatus.Done; GradePaper(ep); } if (0 == olsEni.SaveChanges()) { resJson.status = ResponseStatus.Error; resJson.message = ResponseMessage.SaveChangesError; return(resJson); } resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public Boolean Edit(QuestionClassify model) { try { olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
/// <summary> /// 去除比例值为 0 的元素,并重新调整比例 /// </summary> /// <param name="ratios"></param> /// <returns></returns> private List <AutoRatio> AdjustRatios(List <AutoRatio> ratios) { Decimal totalRatio, tmpRatio; List <AutoRatio> tmpRatios; totalRatio = 0; tmpRatios = new List <AutoRatio>(); foreach (var r in ratios) { if (0 != r.percent) { tmpRatios.Add(r); totalRatio += r.percent; } } if (tmpRatios.Count == 0) { throw new Exception("未设置出题比例。"); } else if ((Double)totalRatio < 0.5) { throw new Exception("出题比例小于 50% 。"); } else if (totalRatio > 1) { throw new Exception("出题比例大于 100% 。"); } tmpRatio = 0; ratios = tmpRatios; foreach (var r in ratios) { // 重新计算比例,且舍为较小的数 r.percent = StaticHelper.MathRound((Double)r.percent / (Double)totalRatio, 2); tmpRatio += r.percent; } // 当调整后的百分比仍小于 1 时,将差值累加至最后一个元素 if (tmpRatio < 1) { ratios[ratios.Count - 1].percent += 1 - tmpRatio; } return(ratios); }
public void ChangeCustomTaskEnabled() { Boolean changed; List <ExaminationTask> ets; try { changed = false; ets = olsEni .ExaminationTasks .Where(m => (m.ET_Type == (Byte)ExaminationTaskType.Exercise || (m.ET_Type == (Byte)ExaminationTaskType.Examination && m.ET_AutoType == (Byte)AutoType.Custom)) && m.ET_Enabled != (Byte)ExaminationTaskStatus.Disabled && m.ET_Status == (Byte)Status.Available) .ToList(); foreach (var et in ets) { if (et.ET_Enabled == (Byte)ExaminationTaskStatus.Unset && et.ET_StartTime < now && et.ET_EndTime > now) { et.ET_Enabled = (Byte)ExaminationTaskStatus.Enabled; changed = true; } else if (et.ET_Enabled == (Byte)ExaminationTaskStatus.Enabled && et.ET_EndTime < now) { et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled; changed = true; } } if (changed) { olsEni.SaveChanges(); } } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); } }
public Boolean Edit(Role model) { try { olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); UpdateRolePermission(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public ResponseJson Sort(Int32 originId, Byte sortFlag) { ResponseJson resJson; resJson = new ResponseJson(); try { Int32 departmentId; User originUser; User_Department ud; originUser = olsEni.Users.Single(m => m.U_Id == originId); ud = olsEni.User_Department.Single(m => m.U_Id == originUser.U_Id); departmentId = ud.D_Id; if (sortFlag == 1) // 置顶 { resJson = SetSortTop(departmentId, originId); return(resJson); } else if (sortFlag == 2) // 上移 { resJson = SetSortUp(departmentId, originId); return(resJson); } else if (sortFlag == 3) // 下移 { resJson = SetSortDown(departmentId, originId); return(resJson); } else //if (sortFlag != 1 && sortFlag != 2 && sortFlag != 3) { resJson.status = ResponseStatus.Error; resJson.message = "未设置排序类型。"; return(resJson); } } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public Boolean Create(VMUser vmModel) { try { Int32 uId; User model; // 不允许将密码设置为“**********” if (vmModel.U_Password == "**********") { return(false); } uId = GetUId(); model = new User { U_Id = uId, Du_Id = vmModel.Du_Id, U_IdCardNumber = vmModel.U_IdCardNumber, U_Name = vmModel.U_Name, U_LoginName = "LoginName" + uId, //[TOKEN_20160815_1559] //U_LoginName = vmModel.Du_Name, //[TOKEN_20160815_1559] U_Password = EncryptPassword(vmModel.U_Password), U_Departments = vmModel.U_Departments, U_Roles = vmModel.U_Roles, U_Remark = vmModel.U_Remark, U_AddTime = vmModel.U_AddTime, U_Status = vmModel.U_Status, U_Sort = uId }; olsEni.Users.Add(model); olsEni.SaveChanges(); UpdateUserDepartment(model); UpdateUserRole(model); return(true); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(false); } }
public ResponseJson EnterExercise(Int32 etId, Int32 uId) { ExaminationTask et; ExaminationTaskAttendee eta; GeneratePaperTemplate generator; List <Question> readyQs; Int32 eptId; ExaminationPaperTemplate ept; try { et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == etId); if (null == et) { return(new ResponseJson(ResponseStatus.Error, "任务不存在。")); } if (et.ET_Enabled != (Byte)ExaminationTaskStatus.Enabled) { return(new ResponseJson(ResponseStatus.Error, "任务已关闭。")); } eta = olsEni.ExaminationTaskAttendees.SingleOrDefault(m => m.ET_Id == et.ET_Id && m.U_Id == uId); if (null == eta) { return(new ResponseJson(ResponseStatus.Error, "您不在此练习的参与人员列表中。")); } generator = new GeneratePaperTemplate(uId); readyQs = generator.GenerateWithNumber(et); eptId = generator.CreatePaperTemplateOfExercise(et, readyQs); ept = Get(eptId); ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done; SaveChanges(); return(addExaminationPaper(ept, uId)); } catch (Exception ex) { StaticHelper.RecordSystemLog(ex); return(new ResponseJson(ResponseStatus.Error, ex.Message)); } }
internal ResponseJson HandIn(Int32 id, Int32 uId) { ResponseJson resJson; resJson = new ResponseJson(); try { ExaminationPaper ep; UExaminationPaperTemplate uept; ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId); if (ep == null) { resJson.status = ResponseStatus.Error; resJson.message = "试卷不存在"; return(resJson); } ep.EP_PaperStatus = (Byte)PaperStatus.Done; if (0 == olsEni.SaveChanges()) { resJson.status = ResponseStatus.Error; resJson.message = ResponseMessage.SaveChangesError; return(resJson); } uept = new UExaminationPaperTemplate(); resJson.data = uept.GradePaper(ep); uept.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
internal ResponseJson GetUndoNumber(Int32 id, Int32 uId) { ResponseJson resJson; resJson = new ResponseJson(); try { Int32 undoNumber; String sql; ExaminationPaper ep; List <SqlParameter> sps; ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId); if (ep == null) { resJson.status = ResponseStatus.Error; resJson.message = "试卷不存在"; return(resJson); } sql = "SELECT COUNT(EPQ_Id) " + "FROM ExaminationPaperQuestions " + "WHERE EP_Id = @epId " + " AND (CAST(EPQ_Answer AS NVARCHAR(5)) = '' " + " OR CAST(EPQ_Answer AS NVARCHAR(5)) = '[]')"; sps = new List <SqlParameter>(); sps.Add(new SqlParameter("@epId", id)); undoNumber = Convert.ToInt32(olsDbo.ExecuteSqlScalar(sql, sps)); resJson.data = undoNumber; resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public ResponseJson SetStatus(Int32 id, Status status) { ResponseJson resJson; resJson = new ResponseJson(); try { Duty model; List <User> us; model = olsEni.Duties.SingleOrDefault(m => m.Du_Id == id); if (null == model) { resJson.message = "数据不存在!"; return(resJson); } // 处理职务中的用户状态 if (status != Status.Available) { us = olsEni.Users.Where(m => m.Du_Id == model.Du_Id).ToList(); foreach (var u in us) { u.U_Status = (Byte)status; } } model.Du_Status = (Byte)status; olsEni.Entry(model).State = EntityState.Modified; olsEni.SaveChanges(); resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
internal ResponseJson RefreshTime(User u) { ResponseJson resJson; resJson = new ResponseJson(ResponseStatus.Error, now); try { UserOnline uo; uo = olsEni.UserOnlines.SingleOrDefault(m => m.U_Id == u.U_Id); if (uo == null) { uo = new UserOnline { U_Id = u.U_Id, UO_Name = u.U_Name, UO_IdCardNumber = u.U_IdCardNumber, UO_RefreshTime = now }; olsEni.Entry(uo).State = EntityState.Added; } else { uo.UO_RefreshTime = now; } if (0 == olsEni.SaveChanges()) { resJson.message = ResponseMessage.SaveChangesError; return(resJson); } resJson.status = ResponseStatus.Success; return(resJson); } catch (Exception ex) { resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } }
public ResponseJson Create(ExaminationTask model) { using (TransactionScope scope = new TransactionScope()) { Int32 id; ResponseJson resJson; resJson = new ResponseJson(ResponseStatus.Success, now); id = GetETId(); try { model.ET_Id = id; olsEni.ExaminationTasks.Add(model); olsEni.SaveChanges(); try { // 添加参与人员 AddAttendees(model); // 添加试卷模板与试题模板 AddPaperTemplateAndQuestionTemplate(model); } catch (Exception ex1) { throw ex1; } scope.Complete(); return(resJson); } catch (Exception ex) { resJson.status = ResponseStatus.Error; resJson.message = ex.Message; resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex); return(resJson); } } }