Пример #1
0
        public Wizard GetProgress(ProgressRequest request)
        {
            var wizardId = request.PlanningWizardID;
            var userId   = request.UserID;
            var wizard   = _planningRepository.FindBy <Wizard>(w => w.PlanningWizardID == wizardId)
                           .Include("Phases")
                           .Include("Phases.Steps")
                           .Include("Phases.Steps.ActionItems")
                           .FirstOrDefault();

            if (wizard == null)
            {
                throw new Exception("Invalid Planning Wizard Id: " + wizardId);
            }

            var progress = _planningRepository.FindBy <Progress>(p => p.UserID == userId && p.PlanningWizardID == wizardId).FirstOrDefault();

            if (progress == null)
            {
                progress = new Progress()
                {
                    PlanningWizardID             = wizardId,
                    UserID                       = userId,
                    CreateDate                   = DateTime.Now,
                    CreateDateUtc                = DateTime.UtcNow,
                    ModifyDate                   = DateTime.Now,
                    ModifyDateUtc                = DateTime.UtcNow,
                    CreateUserID                 = userId,
                    ModifyUserID                 = userId,
                    CurrentPlanningWizardPhaseID = wizard.Phases.First().PlanningWizardPhaseID,
                    PercentComplete              = 0,
                    ProgressXml                  = wizard.Phases.ToXml()
                };

                _planningRepository.Add(progress);
                _planningRepository.Save();
            }

            // Re-hydrate
            progress.Phases = progress.ProgressXml.FromXml <List <Phase> >();

            // Set progress as property
            wizard.Progress = progress;

            // Merge with Wizard data
            foreach (var progressPhase in progress.Phases)
            {
                var phase = wizard.Phases.First(p => p.PlanningWizardPhaseID == progressPhase.PlanningWizardPhaseID);

                phase.IsSelected = phase.PlanningWizardPhaseID.Equals(progress.CurrentPlanningWizardPhaseID);

                foreach (var progressStep in progressPhase.Steps)
                {
                    var step = phase.Steps.First(s => s.PlanningWizardStepID == progressStep.PlanningWizardStepID);

                    step.Notes      = progressStep.Notes;
                    step.IsSelected = progressStep.IsSelected;

                    foreach (var progressActionItem in progressStep.ActionItems)
                    {
                        var actionItem = step.ActionItems.First(a => a.PlanningWizardActionItemID == progressActionItem.PlanningWizardActionItemID);

                        actionItem.IsComplete      = progressActionItem.IsComplete;
                        actionItem.CompleteDate    = progressActionItem.CompleteDate;
                        actionItem.CompleteDateUtc = progressActionItem.CompleteDateUtc;
                    }
                }
            }

            return(wizard);
        }