public List<BatchReport> BatchReport(long tid, DateTime? fr, DateTime? to, long tenantid) { var TR = new List<BatchReport>(); // var cutoff = _db.T_Settings.FirstOrDefault(s => s.SettingsName == "CUT_OFF_MARK").SettingsValue; int countP = 0; var countF = 0; if (tid > 0 && fr == null && to == null) { TR.AddRange(_db.BatchResult(tid,tenantid).Select(s => new BatchReport { BatchName = s.BATCH_NAME, username = s.Username, FirstName = s.FIrst_Name, LastName = s.Last_Name, TotalCorrect = s.Correct.ToString(), TotalWrong = s.Wrong.ToString(), TotalUnanswered = s.Unanswered.ToString(), TotalQuestions = s.TotalQuestion.ToString(), Percentage = s.Percentage.ToString(), DateMarked = s.DateLogged.Value.ToString("dd/MM/yyy"), TotalPartial = s.Partial.ToString(), Cutoff = s.CutOff.ToString(), Passed = s.Percentage >= s.CutOff ? 1 : 0, Failed = s.Percentage < s.CutOff ? 1 : 0 })); } else if (tid > 0 && fr != null && to == null) { TR.AddRange(_db.BatchResultByBatchNTime(tid, fr.Value, DateTime.Now, tenantid).Select(s => new BatchReport { BatchName = s.BATCH_NAME, username = s.Username, FirstName = s.FIrst_Name, LastName = s.Last_Name, TotalCorrect = s.Correct.ToString(), TotalWrong = s.Wrong.ToString(), TotalUnanswered = s.Unanswered.ToString(), TotalQuestions = s.TotalQuestion.ToString(), Percentage = s.Percentage.ToString(), DateMarked = s.DateLogged.Value.ToString("dd/MM/yyyy"), TotalPartial = s.Partial.ToString(), Cutoff = s.CutOff.ToString(), Passed = s.Percentage >= s.CutOff ? 1 : 0, Failed = s.Percentage < s.CutOff ? 1 : 0 })); } else if (tid > 0 && fr == null && to != null) { TR.AddRange(_db.BatchResultByBatchNTime(tid, DateTime.Now, to.Value, tenantid).Select(s => new BatchReport { BatchName = s.BATCH_NAME, username = s.Username, FirstName = s.FIrst_Name, LastName = s.Last_Name, TotalCorrect = s.Correct.ToString(), TotalWrong = s.Wrong.ToString(), TotalUnanswered = s.Unanswered.ToString(), TotalQuestions = s.TotalQuestion.ToString(), Percentage = s.Percentage.ToString(), DateMarked = s.DateLogged.Value.ToString("dd/MM/yyyy"), TotalPartial = s.Partial.ToString(), Cutoff = s.CutOff.ToString(), Passed = s.Percentage >= s.CutOff ? 1 : 0, Failed = s.Percentage < s.CutOff ? 1 : 0 })); } else if (tid > 0 && fr != null && to != null) { TR.AddRange(_db.BatchResultByBatchNTime(tid, fr.Value, to.Value, tenantid).Select(s => new BatchReport { BatchName = s.BATCH_NAME, username = s.Username, FirstName = s.FIrst_Name, LastName = s.Last_Name, TotalCorrect = s.Correct.ToString(), TotalWrong = s.Wrong.ToString(), TotalUnanswered = s.Unanswered.ToString(), TotalQuestions = s.TotalQuestion.ToString(), Percentage = s.Percentage.ToString(), DateMarked = s.DateLogged.Value.ToString("dd/MM/yyyy"), TotalPartial = s.Partial.ToString(), Cutoff = s.CutOff.ToString(), Passed = s.Percentage >= s.CutOff ? 1 : 0, Failed = s.Percentage < s.CutOff ? 1 : 0 })); } else { TR.AddRange(_db.BatchResultByTime(fr.Value, to.Value, tenantid).Select(s => new BatchReport { BatchName = s.BATCH_NAME, username = s.Username, FirstName = s.FIrst_Name, LastName = s.Last_Name, TotalCorrect = s.Correct.ToString(), TotalWrong = s.Wrong.ToString(), TotalUnanswered = s.Unanswered.ToString(), TotalQuestions = s.TotalQuestion.ToString(), Percentage = s.Percentage.ToString(), DateMarked = s.DateLogged.Value.ToString("dd/MM/yyyy"), TotalPartial = s.Partial.ToString(), Cutoff = s.CutOff.ToString(), Passed = s.Percentage >= s.CutOff ? 1 : 0, Failed = s.Percentage < s.CutOff ? 1 : 0 })); } return TR; }