public virtual void Create(Assessment item)
        {
            var openStatus = _container.Lookups.OfType<Data.AssessmentStatus>().Where(i=>i.Value == "Open").First();
            item.Status = openStatus;

            _container.Assessments.Add(item);
        }
        public virtual void CloseAssessment(Assessment assessment)
        {
            if (assessment.Status.Value == "Open")
            {
                throw new ApplicationException("You cannot close an assessment before it has been moderated.");
            }

            if (assessment.Status.Value == "Closed")
            {
                throw new ApplicationException("This assesment is already closed.");
            }

            assessment.Status = _container.Lookups.OfType<Data.AssessmentStatus>().Where(i => i.Value == "Closed").First();
        }
        public void UpdateCapabilityForAssessment(Assessment assessment, IEnumerable <AssessmentItem> assessmentItems)
        {
            if (assessment.Status.Value == "Moderating" || assessment.Status.Value == "Closed")
            {
                throw new ApplicationException("You can only update capabilites for open assessments.");
            }

            foreach (var item in assessmentItems)
            {
                if (assessment.AssessmentItems.Any(i => i.CapabiltyId == item.CapabiltyId))
                {
                    var assessmentItem = assessment.AssessmentItems.First(i => i.CapabiltyId == item.CapabiltyId);
                    assessmentItem.CapabilityAchieved = item.CapabilityAchieved;
                }
                else
                {
                    assessment.AssessmentItems.Add(item);
                }
            }
        }
        public void UpdateModerationResultForAssessment(Assessment assessment, IEnumerable <AssessmentResult> assessmentResults)
        {
            if (assessment.Status.Value == "Closed" || assessment.Status.Value == "Open")
            {
                throw new ApplicationException("You can only add Assesssment Results when the assessment is in moderation.");
            }

            foreach (var result in assessmentResults)
            {
                if (assessment.AssessmentResults.Any(i => i.DimensionId == result.DimensionId))
                {
                    var currentResult = assessment.AssessmentResults.First(i => i.DimensionId == result.DimensionId);
                    currentResult.Rating = result.Rating;
                }
                else
                {
                    assessment.AssessmentResults.Add(result);
                }
            }
        }
 public virtual void StartModeration(Assessment assessment)
 {
     assessment.Status = _container.Lookups.OfType <Data.AssessmentStatus>().Where(i => i.Value == "Moderating").First();
 }
        public void UpdateModerationResultForAssessment(Assessment assessment, IEnumerable<AssessmentResult> assessmentResults)
        {
            if (assessment.Status.Value == "Closed" || assessment.Status.Value == "Open")
            {
                throw new ApplicationException("You can only add Assesssment Results when the assessment is in moderation.");
            }

            foreach (var result in assessmentResults)
            {
                if(assessment.AssessmentResults.Any(i=>i.DimensionId == result.DimensionId))
                {
                    var currentResult = assessment.AssessmentResults.First(i => i.DimensionId == result.DimensionId);
                    currentResult.Rating = result.Rating;
                }
                else
                {
                    assessment.AssessmentResults.Add(result);
                }
            }
        }
        public void UpdateCapabilityForAssessment(Assessment assessment, IEnumerable<AssessmentItem> assessmentItems)
        {
            if (assessment.Status.Value == "Moderating" || assessment.Status.Value == "Closed")
            {
                throw new ApplicationException("You can only update capabilites for open assessments.");
            }

            foreach (var item in assessmentItems)
            {
                if (assessment.AssessmentItems.Any(i => i.CapabiltyId == item.CapabiltyId))
                {
                    var assessmentItem = assessment.AssessmentItems.First(i => i.CapabiltyId == item.CapabiltyId);
                    assessmentItem.CapabilityAchieved = item.CapabilityAchieved;
                }
                else
                {
                    assessment.AssessmentItems.Add(item);
                }
            }
        }
 public virtual void StartModeration(Assessment assessment)
 {
     assessment.Status = _container.Lookups.OfType<Data.AssessmentStatus>().Where(i => i.Value == "Moderating").First();
 }
        public virtual void ReopenAssessment(Assessment assessment)
        {
            if (assessment.Status.Value != "Moderating")
            {
                throw new ApplicationException("You cannot reopen a Closed assessment..");
            }

            assessment.Status = _container.Lookups.OfType<Data.AssessmentStatus>().Where(i => i.Value == "Open").First();
        }
 private void RemoveAssessmentResult(Assessment assessment)
 {
     var assessmentResults = _container.AssessmentResults.Where(i => i.AssessmentId == assessment.Id);
     foreach (var assessmentResult in assessmentResults)
     {
         _container.AssessmentResults.Remove(assessmentResult);
     }
 }
 private void RemoveAssessmentItems(Assessment assessment)
 {
     var assessmentItems = _container.AssessmentItems.Where(i => i.AssessmentId == assessment.Id);
     foreach (var assessmentItem in assessmentItems)
     {
         _container.AssessmentItems.Remove(assessmentItem);
     }
 }