示例#1
0
        public IQueryable<vw_PQT_AccidentHeader> Query(BasicSearchParameters sp)
        {
            var query = db.vw_PQT_AccidentHeader.Where(x => x.REPORTNUMBER != null);
            if (!string.IsNullOrEmpty(sp.StartDate))
            {
                var startDate = Convert.ToDateTime(sp.StartDate);
                query = from a in query
                        where a.ACCIDENTDATE >= startDate
                        select a;
            }

            if (!string.IsNullOrEmpty(sp.EndDate))
            {
                var endDate = Convert.ToDateTime(sp.EndDate);
                query = from a in query
                        where a.ACCIDENTDATE <= endDate
                        select a;
            }

            if (sp.CityCode != null && sp.CityCode.Count > 0)
            {
                query = from a in query
                        where a.VCSG_CITYTOWN != null && sp.CityCode.Contains(a.VCSG_CITYTOWN)
                        select a;
            }

            if (sp.CountyCode != null && sp.CountyCode.Count > 0)
            {
                query = from a in query
                        where sp.CountyCode.Contains(a.VCSG_CITYTOWN.Substring(0, 2))
                        select a;
            }

            if (sp.CrashType != null && sp.CrashType.Count > 0)
            {
                query = from a in query
                        where sp.CrashType.Any(ct => ct == a.CRASHTYPEid)
                        select a;
            }

            if (sp.ReportingAgency != null && sp.ReportingAgency.Count > 0)
            {
                query = from a in query
                        where sp.ReportingAgency.Contains(a.REPORTINGAGENCYid)
                        select a;
            }

            if (sp.Route != null && sp.Route.Count > 0)
            {
                query = from a in query
                        where sp.Route.Contains(a.VCSG_AOTROUTE)
                        select a;
            }

            return query;
        }
示例#2
0
 public List<vw_PQT_AccidentHeader> SearchBasic(BasicSearchParameters sp)
 {
     return Query(sp).ToList();
 }
示例#3
0
 public int Count(BasicSearchParameters sp)
 {
     return Query(sp).Count();
 }
示例#4
0
        public List<AccidentModel.Accident> Search(BasicSearchParameters sp)
        {
            int MaxSearchResults = Convert.ToInt32(WebConfigurationManager.AppSettings.Get("MaxSearchResults"));

            List<AccidentModel.Accident> accidents = new List<AccidentModel.Accident>();

            IQueryable<vw_PQT_AccidentHeader> query = Query(sp);

            IEnumerable<vw_PQT_AccidentHeader> results = query.AsEnumerable();
            if (MaxSearchResults > 0)
            {
                if (results.Count() > MaxSearchResults)
                {
                    throw new HttpResponseException(HttpStatusCode.RequestedRangeNotSatisfiable);
                    //var response = Request.CreateErrorResponse(HttpStatusCode.RequestedRangeNotSatisfiable, new HttpException(416, "The search returned to many records."));
                }
                results = results.Take(MaxSearchResults);
            }

            foreach (vw_PQT_AccidentHeader a in results)
            {
                accidents.Add(new AccidentModel.Accident(a));
            }
            return accidents;
        }