Exemple #1
0
        ///<summary>Efficiently queries DB to fill all in memory lists for all jobs passed in.</summary>
        public static void FillInMemoryLists(List <Job> listJobsAll)
        {
            //No need for remoting call here.
            List <long> jobNums = listJobsAll.Select(x => x.JobNum).ToList();
            Dictionary <long, List <JobLink> >   listJobLinksAll   = JobLinks.GetJobLinksForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            Dictionary <long, List <JobNote> >   listJobNotesAll   = JobNotes.GetJobNotesForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            Dictionary <long, List <JobReview> > listJobReviewsAll = JobReviews.GetJobReviewsForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            Dictionary <long, List <JobQuote> >  listJobQuotesAll  = JobQuotes.GetJobQuotesForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            Dictionary <long, List <JobLog> >    listJobLogsAll    = JobLogs.GetJobLogsForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());

            for (int i = 0; i < listJobsAll.Count; i++)
            {
                Job job = listJobsAll[i];
                if (!listJobLinksAll.TryGetValue(job.JobNum, out job.ListJobLinks))
                {
                    job.ListJobLinks = new List <JobLink>();                 //empty list if not found
                }
                if (!listJobNotesAll.TryGetValue(job.JobNum, out job.ListJobNotes))
                {
                    job.ListJobNotes = new List <JobNote>();                 //empty list if not found
                }
                if (!listJobReviewsAll.TryGetValue(job.JobNum, out job.ListJobReviews))
                {
                    job.ListJobReviews = new List <JobReview>();                 //empty list if not found
                }
                if (!listJobQuotesAll.TryGetValue(job.JobNum, out job.ListJobQuotes))
                {
                    job.ListJobQuotes = new List <JobQuote>();                 //empty list if not found
                }
                if (!listJobLogsAll.TryGetValue(job.JobNum, out job.ListJobLogs))
                {
                    job.ListJobLogs = new List <JobLog>();                 //empty list if not found
                }
            }
        }
Exemple #2
0
        ///<summary>Removes invalid jobs from the list of jobs passed in and then queries the DB to fill corresponding in-memory lists for remaining jobs.
        ///Set isForSearch true in order to only fill in-memory lists that are required for the Job Search window.</summary>
        public static void FillInMemoryLists(List <Job> listJobsAll, bool isForSearch = false)
        {
            //No need for remoting call here.
            listJobsAll.RemoveAll(x => x == null || x.JobNum == 0);
            List <long> jobNums = listJobsAll.Select(x => x.JobNum).ToList();
            Dictionary <long, List <JobLink> >         dictJobLinksAll         = new Dictionary <long, List <JobLink> >();
            Dictionary <long, List <JobNote> >         dictJobNotesAll         = new Dictionary <long, List <JobNote> >();
            Dictionary <long, List <JobReview> >       dictJobReviewsAll       = new Dictionary <long, List <JobReview> >();
            Dictionary <long, List <JobReview> >       dictJobTimeLogsAll      = new Dictionary <long, List <JobReview> >();
            Dictionary <long, List <JobQuote> >        dictJobQuotesAll        = new Dictionary <long, List <JobQuote> >();
            Dictionary <long, List <JobLog> >          dictJobLogsAll          = new Dictionary <long, List <JobLog> >();
            Dictionary <long, List <JobNotification> > dictJobNotificationsAll = new Dictionary <long, List <JobNotification> >();
            Dictionary <long, List <JobActiveLink> >   dictJobActiveLinksAll   = new Dictionary <long, List <JobActiveLink> >();

            //The job search only needs ListJobLinks and ListJobReviews to be filled.
            dictJobLinksAll   = JobLinks.GetJobLinksForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            dictJobReviewsAll = JobReviews.GetReviewsForJobs(jobNums.ToArray()).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            //Fill all other dictionaries when not filling in-memory lists for job search results (saves db calls and memory usage).
            if (!isForSearch)
            {
                dictJobNotesAll         = JobNotes.GetJobNotesForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
                dictJobTimeLogsAll      = JobReviews.GetTimeLogsForJobs(jobNums.ToArray()).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
                dictJobQuotesAll        = JobQuotes.GetJobQuotesForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
                dictJobLogsAll          = JobLogs.GetJobLogsForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
                dictJobNotificationsAll = JobNotifications.GetNotificationsForJobs(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
                dictJobActiveLinksAll   = JobActiveLinks.GetJobActiveLinksForJobNums(jobNums).GroupBy(x => x.JobNum).ToDictionary(x => x.Key, x => x.ToList());
            }
            foreach (Job job in listJobsAll)
            {
                if (!dictJobLinksAll.TryGetValue(job.JobNum, out job.ListJobLinks))
                {
                    job.ListJobLinks = new List <JobLink>();                 //empty list if not found
                }
                if (!dictJobNotesAll.TryGetValue(job.JobNum, out job.ListJobNotes))
                {
                    job.ListJobNotes = new List <JobNote>();                 //empty list if not found
                }
                if (!dictJobReviewsAll.TryGetValue(job.JobNum, out job.ListJobReviews))
                {
                    job.ListJobReviews = new List <JobReview>();                 //empty list if not found
                }
                if (!dictJobTimeLogsAll.TryGetValue(job.JobNum, out job.ListJobTimeLogs))
                {
                    job.ListJobTimeLogs = new List <JobReview>();                 //empty list if not found
                }
                if (!dictJobQuotesAll.TryGetValue(job.JobNum, out job.ListJobQuotes))
                {
                    job.ListJobQuotes = new List <JobQuote>();                 //empty list if not found
                }
                if (!dictJobLogsAll.TryGetValue(job.JobNum, out job.ListJobLogs))
                {
                    job.ListJobLogs = new List <JobLog>();                 //empty list if not found
                }
                if (!dictJobNotificationsAll.TryGetValue(job.JobNum, out job.ListJobNotifications))
                {
                    job.ListJobNotifications = new List <JobNotification>();                 //empty list if not found
                }
                if (!dictJobActiveLinksAll.TryGetValue(job.JobNum, out job.ListJobActiveLinks))
                {
                    job.ListJobActiveLinks = new List <JobActiveLink>();                 //empty list if not found
                }
            }
        }