public string CalculateMarkSection(LOT_Exam exam, LOT_ExamQuestion_Section section, sp_GetCandidateListByExamResult candidate, ref double totalMark, ref double totalMaxMark, ref bool isNan) { List<sp_GetCandidateAnswerListResult> listAnswer = candidateAnswerDAO.GetCandidateAnswer(candidate.ID, section.ID); List<sp_GetCandidateAnswerListResult> correctAnswers = listAnswer.Where(c => c.IsCorrect == true).ToList<sp_GetCandidateAnswerListResult>(); double mark = (((double)section.MaxMark) / listAnswer.Count) * correctAnswers.Count; string result=string.Empty; if (!double.IsNaN(mark)) { result = Math.Round(mark) + "/" + section.MaxMark; totalMaxMark += (double)section.MaxMark; totalMark += mark; } else { totalMaxMark += 0; totalMark += 0; isNan = false; } return result; }
/// <summary> /// Check update date whether is valid /// </summary> /// <param name="objUI"></param> /// <param name="objDb"></param> /// <param name="msg"></param> /// <returns></returns> private bool IsValidExamUpdateDate(LOT_Exam objUI, LOT_Exam objDb, out Message msg) { bool isValid = false; msg = null; try { if ((objUI != null) && (objUI.UpdateDate != null)) { if (objDb != null) { if (objDb.UpdateDate.ToString().Equals(objUI.UpdateDate.ToString())) { isValid = true; } else { msg = new Message(MessageConstants.E0025, MessageType.Error, "Exam '" + objDb.Title + "'"); } } } } catch { throw; } return isValid; }
/// <summary> /// Update /// </summary> /// <param name="objUI"></param> /// <returns></returns> public Message Update(LOT_Exam objUI) { Message msg = null; try { if (objUI != null) { LOT_Exam objDB = GetByID(objUI.ID); if (IsValidExamUpdateDate(objUI, objDB,out msg)) { objDB.Title = objUI.Title; objDB.ExamQuestionID = objUI.ExamQuestionID; objDB.ExamDate = objUI.ExamDate; objDB.ExamType = objUI.ExamType; // Set more info objDB.UpdateDate = DateTime.Now; objDB.UpdatedBy = objUI.UpdatedBy; dbContext.SubmitChanges(); msg = new Message(MessageConstants.I0001, MessageType.Info, "Exam '" + objUI.Title + "'", "updated"); } } } catch (Exception) { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }
/// <summary> /// Delete by set DeleteFlag = true /// </summary> /// <param name="objUI"></param> private Message Delete(LOT_Exam objUI) { Message msg = null; try { if (objUI != null) { LOT_Exam objDb = GetByID(objUI.ID); if (objDb != null) { // Set delete info objDb.DeleteFlag = true; objDb.UpdateDate = DateTime.Now; objDb.UpdatedBy = objUI.UpdatedBy; } // Submit changes to dbContext msg = new Message(MessageConstants.I0001, MessageType.Info, "Exam", "deleted"); dbContext.SubmitChanges(); } } catch { msg = new Message(MessageConstants.E0006, MessageType.Error, "delete", "it"); } return msg; }
/// <summary> /// Insert to database /// </summary> /// <param name="objUI"></param> /// <returns></returns> public Message Insert(LOT_Exam objUI) { Message msg = null; try { if (objUI != null) { // Set more info objUI.DeleteFlag = false; objUI.CreateDate = DateTime.Now; objUI.UpdateDate = DateTime.Now; dbContext.LOT_Exams.InsertOnSubmit(objUI); dbContext.SubmitChanges(); msg = new Message(MessageConstants.I0001, MessageType.Info, "Exam '" + objUI.Title + "'", "added"); } } catch (Exception) { // Show system error msg = new Message(MessageConstants.E0007, MessageType.Error); } return msg; }