public OPTRow(string Division, DateTime start, DateTime end) { switch (Division) { case "CA": division = "Child Abduction"; var allCAs = db.ChildAbductions; issued = allCAs.Where(x => x.createdOn >= start && x.createdOn <= end).Count(); pending = allCAs.Where(x => x.createdOn <= end).Where(x => x.resultID == null || x.DateExecuted > end).Count(); var closedCAs = allCAs.Where(x => x.DateExecuted >= start && x.DateExecuted <= end); System.Diagnostics.Debug.Print(allCAs.Count().ToString()); System.Diagnostics.Debug.Print(closedCAs.Count().ToString()); executed = closedCAs.Where(x => x.result.Detail == "Executed").Count(); suspendedDischarged = closedCAs.Where(x => x.result.Detail == "Suspended" || x.result.Detail == "Discharged").Count(); expired = closedCAs.Where(x => x.result.Detail == "Expired").Count(); toPrison = closedCAs.Sum(x => x.prisonCount) ?? 0; break; default: //get Warrant data division = Division; //var divisions = db.Warrants.Where(x => x.division.Detail==Division); using (TipstaffDB rpt = new TipstaffDB()){ issued = rpt.Warrants.Where(x => x.division.Detail == division && x.createdOn >= start && x.createdOn <= end).Count(); }; using (TipstaffDB rpt = new TipstaffDB()){ pending = rpt.Warrants.Where(x => x.division.Detail == Division && x.createdOn <= end).Where(x => x.resultID == null || x.DateExecuted > end).Count(); }; using (TipstaffDB rpt = new TipstaffDB()){ executed = rpt.Warrants.Where(x => x.division.Detail == Division).Where(x => x.resultID != null && x.DateExecuted >= start && x.DateExecuted <= end && x.result.Detail == "Executed").Count(); }; using (TipstaffDB rpt = new TipstaffDB()){ suspendedDischarged = rpt.Warrants.Where(x => x.division.Detail == Division).Where(x => x.resultID != null && x.DateExecuted >= start && x.DateExecuted <= end).Where(x => x.result.Detail == "Suspended" || x.result.Detail == "Discharged").Count(); }; using (TipstaffDB rpt = new TipstaffDB()){ expired = rpt.Warrants.Where(x => x.division.Detail == Division).Where(x => x.resultID != null && x.DateExecuted >= start && x.DateExecuted <= end && x.result.Detail == "Expired").Count(); }; using (TipstaffDB rpt = new TipstaffDB()){ toPrison = rpt.Warrants.Where(x => x.division.Detail == Division).Where(x => x.resultID != null && x.DateExecuted >= start && x.DateExecuted <= end).Sum(x => x.prisonCount) ?? 0; }; break; } }
public SearchModel(string searchRecord) { searchSource = searchRecord; try { DateTime output = DateTime.Parse(searchSource); searchType = SearchType.DateOfBirth; //if (output.ToString("d/M/yy") == searchSource.ToString()) if (searchSource.Count(c => c == '/') == 2) { searchResults = SearchResults.getMatches(output); } else { searchResults = SearchResults.getMatches(output.Month, output.Day); } isValid = true; return; } catch { isValid = false; searchType = null; } try { if (rxText.IsMatch(searchSource)) { searchType = SearchType.Name; isValid = true; searchResults = SearchResults.getMatches(searchSource); return; } } catch { isValid = false; } try { if (rxNumeric.IsMatch(searchSource)) { search = Int32.Parse(searchSource); searchType = SearchType.RecordNumber; isValid = true; } } catch { errorMessage = string.Format("Your search text '{0}' could not be converted into the TRxxxxxx format", searchSource); isValid = false; searchType = null; return; } using (TipstaffDB db = new TipstaffDB()) { tipstaffRecord = db.TipstaffRecord.Find(search); } if (tipstaffRecord == null && search > 0) { errorMessage = string.Format("No record could be found that matched '{0}' ", string.Format("TR{0}", search.ToString("D6"))); isValid = false; searchType = null; return; } try { RecordType = genericFunctions.TypeOfTipstaffRecord(tipstaffRecord); } catch { errorMessage = string.Format("Type of record could not be determined"); isValid = false; searchType = null; return; } }