public static PriorExposures GetExposures(MedSimDbContext context, Guid courseId, Guid userId)
        {
            //to do - check authorization
            var course = (from c in context.Courses.Include(co => co.CourseParticipants).Include(co => co.CourseFormat)
                          where c.Id == courseId
                          select c).First();
            //only interested in faculty
            var participantIds = (from cp in course.CourseParticipants
                                  where !cp.IsFaculty
                                  select cp.ParticipantId).ToList();
            //however, if they have been faculty for a scenario or activity, we want to know that
            var otherCourses = (from c in context.Courses.Include(co => co.CourseSlotActivities).Include(co => co.CourseParticipants)
                                where c.Id != courseId && c.CourseFormat.CourseTypeId == course.CourseFormat.CourseTypeId && !c.Cancelled && c.CourseParticipants.Any(cp => participantIds.Contains(cp.ParticipantId))
                                select c).ToList();
            var returnVar = new PriorExposures
            {
                ScenarioParticipants = new Dictionary<Guid, HashSet<Guid>>(),
                ActivityParticipants = new Dictionary<Guid, HashSet<Guid>>(),
                BookedManikins = GetBookedManikins(context, course)
            };

            foreach (var oc in otherCourses)
            {
                var participants = (from cp in oc.CourseParticipants
                                    select cp.ParticipantId).Intersect(participantIds).ToList();
                foreach (var csa in oc.CourseSlotActivities)
                {
                    if (csa.ActivityId.HasValue)
                    {
                        returnVar.ActivityParticipants.AddRangeOrCreate(csa.ActivityId.Value, participants);
                    }
                    else
                    {
                        returnVar.ScenarioParticipants.AddRangeOrCreate(csa.ScenarioId.Value, participants);
                    }
                }
            }
            return returnVar;
        }
Example #2
0
        public static PriorExposures GetExposures(MedSimDbContext context, Guid courseId)
        {
            //to do - check authorization
            var course = (from c in context.Courses.Include(co => co.CourseParticipants).Include(co => co.CourseFormat)
                          where c.Id == courseId
                          select c).First();
            //only interested in faculty
            var participantIds = (from cp in course.CourseParticipants
                                  where !cp.IsFaculty
                                  select cp.ParticipantId).ToList();
            //however, if they have been faculty for a scenario or activity, we want to know that
            var otherCourses = (from c in context.Courses.Include(co => co.CourseSlotActivities).Include(co => co.CourseParticipants)
                                where c.Id != courseId && c.CourseFormat.CourseTypeId == course.CourseFormat.CourseTypeId && !c.Cancelled && c.CourseParticipants.Any(cp => participantIds.Contains(cp.ParticipantId))
                                select c).ToList();
            var returnVar = new PriorExposures
            {
                ScenarioParticipants = new Dictionary <Guid, HashSet <Guid> >(),
                ActivityParticipants = new Dictionary <Guid, HashSet <Guid> >(),
            };

            foreach (var oc in otherCourses)
            {
                var participants = (from cp in oc.CourseParticipants
                                    select cp.ParticipantId).Intersect(participantIds).ToList();
                foreach (var csa in oc.CourseSlotActivities)
                {
                    if (csa.ActivityId.HasValue)
                    {
                        returnVar.ActivityParticipants.AddRangeOrCreate(csa.ActivityId.Value, participants);
                    }
                    else
                    {
                        returnVar.ScenarioParticipants.AddRangeOrCreate(csa.ScenarioId.Value, participants);
                    }
                }
            }
            return(returnVar);
        }