Ejemplo n.º 1
0
        /// <summary>
        /// GetTemplate returns an object of type AssessmentTemplatetakes.  It can be called with an optional argument to specify a
        /// template version.  If omitted, the newest default template is returned.
        /// </summary>
        /// <param name="templateVersion">Optional, Integer - specifies template version to return</param>
        /// <returns></returns>
        public AssessmentTemplate GetTemplate(int templateVersion = 0)
        {
            var result = new AssessmentTemplate();

            if (templateVersion == 0)
            {
                templateVersion = GetDefaultTemplateVersion();
            }

            try
            {
                result = context.AssessmentTemplates.Fill()
                         .Where(a => a.TemplateVersion == templateVersion).FirstOrDefault();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw new ApplicationException("Error: OwaspSAMMRepository.GetTemplate", ex);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// CreateAssessment - uses the specified template to generate a new assessment and assign the owner to the identity provided
        /// </summary>
        /// <param name="userID">Int - UserID of Owner</param>
        /// <param name="templateVersion">Int - version number of template to use when generating assessment</param>
        /// <param name="orgName">string - Organization Name to assign to the Assessment</param>
        /// <param name="appName">string - Product Name to assign to the Assessment</param>
        /// <param name="createID">int - UserID of Creator</param>
        /// <param name="industryID">int = IndustryID that will be associated to the assessment.  Currently defaulting to first industry.</param>
        /// <returns></returns>
        public async Task <int> CreateAssessment(int ownerID, int templateVersion, string buName, string orgName, string appName, int createID, int industryID)
        {
            int results = 0;

            var categoryData = new CategoryData();
            var sectionData  = new SectionData();
            var groupData    = new GroupData();
            var questionData = new QuestionData();

            // Retrieve the template
            AssessmentTemplate template = GetTemplate(templateVersion);

            // Create a new Assessment and set the UserID as the owner, last update and creator.
            UserData ud = context.UserDatas.Find(ownerID);

            try
            {
                var newAssessment = new Assessment();

                newAssessment.TemplateVersion  = templateVersion;
                newAssessment.OwnerID          = ownerID;
                newAssessment.OrganizationName = orgName;
                newAssessment.BusinessUnit     = buName;
                newAssessment.ApplicationName  = appName;
                newAssessment.LastUpdated      = DateTime.Now;
                newAssessment.CreateDate       = DateTime.Now;
                newAssessment.LastUpdateBy     = createID;
                newAssessment.CreateBy         = createID;
                newAssessment.IndustryID       = industryID;
                newAssessment.Finalized        = false;

                ud.Assessments.Add(newAssessment);

                // Spin through the template and create the assessment
                foreach (var j in template.TemplateCategories)
                {
                    categoryData               = new CategoryData();
                    categoryData.CategoryID    = j.CategoryID;
                    categoryData.CategoryOrder = j.CategoryOrder;

                    newAssessment.CategoryDatas.Add(categoryData);

                    foreach (var k in j.TemplateSections)
                    {
                        sectionData                     = new SectionData();
                        sectionData.SectionID           = k.SectionID;
                        sectionData.SectionOrder        = k.SectionOrder;
                        sectionData.SectionScore        = 0;
                        sectionData.SectionScorePartial = 0;

                        categoryData.SectionDatas.Add(sectionData);

                        foreach (var l in k.TemplateGroups)
                        {
                            groupData            = new GroupData();
                            groupData.GroupID    = l.GroupID;
                            groupData.GroupOrder = l.GroupOrder;
                            groupData.GroupScore = 0;

                            sectionData.GroupDatas.Add(groupData);

                            foreach (var m in l.TemplateQuestions)
                            {
                                questionData               = new QuestionData();
                                questionData.Answer        = false;
                                questionData.QuestionID    = m.QuestionID;
                                questionData.QuestionOrder = m.QuestionOrder;

                                groupData.QuestionDatas.Add(questionData);
                            }
                        }
                    }
                }

                await context.SaveChangesAsync();

                results = newAssessment.AssessmentID;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error: OwaspSAMMRepository.CreateAssessment", ex);
            }

            return(results);
        }