Ejemplo n.º 1
0
        /// <summary>
        /// Gets a query of the people completing the program.
        /// </summary>
        /// <returns></returns>
        public IQueryable <PersonStepProgramViewModel> GetPersonCompletingProgramQuery(int stepProgramId)
        {
            var stepProgram = StepProgramCache.Get(stepProgramId);

            if (stepProgram == null)
            {
                return(null);
            }

            var rockContext = Context as RockContext;
            var stepProgramCompletionService = new StepProgramCompletionService(rockContext);

            // Start with all the completed steps to try to narrow the set
            var completedStepQuery = stepProgramCompletionService.Queryable()
                                     .AsNoTracking()
                                     .Where(s =>
                                            s.StepProgramId == stepProgram.Id);

            var personQuery = completedStepQuery
                              .Select(g => new PersonStepProgramViewModel
            {
                PersonId          = g.PersonAlias.PersonId,
                StartedDateTime   = g.StartDateTime,
                CompletedDateTime = g.EndDateTime
            });

            return(personQuery);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the step set with step program completion
        /// </summary>
        public static void UpdateStepProgramCompletion(List <Step> stepSet, int personAliasId, int stepProgramId, RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var campusId      = stepSet.Where(a => a.CampusId.HasValue).Select(a => a.CampusId).FirstOrDefault();
            var startDateTime = stepSet.Select(a => a.StartDateTime ?? a.CreatedDateTime).OrderBy(a => a).FirstOrDefault();
            var endDateTime   = stepSet.Select(a => a.CompletedDateTime ?? a.EndDateTime).OrderByDescending(a => a).FirstOrDefault();

            var stepProgramCompletionService = new StepProgramCompletionService(rockContext);
            var stepService = new StepService(rockContext);

            var stepProgramCompletion = new StepProgramCompletion
            {
                StepProgramId = stepProgramId,
                PersonAliasId = personAliasId,
                CampusId      = campusId,
                StartDateTime = startDateTime.Value,
                EndDateTime   = endDateTime
            };

            stepProgramCompletionService.Add(stepProgramCompletion);
            rockContext.SaveChanges();

            var stepIds = stepSet.Select(b => b.Id);
            var stepQry = stepService.Queryable().Where(a => stepIds.Contains(a.Id));

            rockContext.BulkUpdate(stepQry, a => new Step {
                StepProgramCompletionId = stepProgramCompletion.Id
            });
        }