コード例 #1
0
ファイル: AggregationManager.cs プロジェクト: vcubefame/CSET
        /// <summary>
        /// Returns a list of assessments for the specified aggregation.
        /// The list is in ascending order of assessment date.
        /// </summary>
        /// <param name="aggregationId"></param>
        public AssessmentListResponse GetAssessmentsForAggregation(int aggregationId)
        {
            using (var db = new CSET_Context())
            {
                var ai   = db.AGGREGATION_INFORMATION.Where(x => x.AggregationID == aggregationId).FirstOrDefault();
                var resp = new AssessmentListResponse
                {
                    Aggregation = new Aggregation()
                    {
                        AggregationId   = ai.AggregationID,
                        AggregationName = ai.Aggregation_Name,
                        AggregationDate = ai.Aggregation_Date
                    }
                };


                var dbAaList = db.AGGREGATION_ASSESSMENT
                               .Where(x => x.Aggregation_Id == aggregationId)
                               .Include(x => x.Assessment_)
                               .ThenInclude(x => x.INFORMATION)
                               .OrderBy(x => x.Assessment_.Assessment_Date)
                               .ToList();

                var l = new List <AggregAssessment>();

                foreach (var dbAA in dbAaList)
                {
                    var aa = new AggregAssessment()
                    {
                        AssessmentId   = dbAA.Assessment_Id,
                        Alias          = dbAA.Alias,
                        AssessmentName = dbAA.Assessment_.INFORMATION.Assessment_Name,
                        AssessmentDate = dbAA.Assessment_.Assessment_Date
                    };

                    l.Add(aa);

                    if (string.IsNullOrEmpty(aa.Alias))
                    {
                        aa.Alias   = GetNextAvailableAlias(dbAaList.Select(x => x.Alias).ToList(), l.Select(x => x.Alias).ToList());
                        dbAA.Alias = aa.Alias;
                    }
                }

                // Make sure the aliases are persisted
                db.SaveChanges();

                resp.Assessments = l;

                IncludeStandards(ref resp);

                resp.Aggregation.QuestionsCompatibility    = CalcCompatibility("Q", resp.Assessments.Select(x => x.AssessmentId).ToList());
                resp.Aggregation.RequirementsCompatibility = CalcCompatibility("R", resp.Assessments.Select(x => x.AssessmentId).ToList());


                return(resp);
            }
        }
コード例 #2
0
ファイル: AggregationManager.cs プロジェクト: vcubefame/CSET
        /// <summary>
        ///
        /// </summary>
        public void IncludeStandards(ref AssessmentListResponse response)
        {
            // For each standard, list any assessments that use it.
            Dictionary <string, List <int> > selectedStandards = new Dictionary <string, List <int> >();
            DataTable dt = new DataTable();

            dt.Columns.Add("AssessmentName");
            dt.Columns.Add("AssessmentId", typeof(int));
            dt.Columns.Add("Alias");
            int startColumn = dt.Columns.Count;

            using (var db = new CSET_Context())
            {
                foreach (var a in response.Assessments)
                {
                    var info = db.INFORMATION.Where(x => x.Id == a.AssessmentId).FirstOrDefault();

                    DataRow rowAssess = dt.NewRow();
                    rowAssess["AssessmentId"]   = info.Id;
                    rowAssess["AssessmentName"] = info.Assessment_Name;
                    rowAssess["Alias"]          = a.Alias;
                    dt.Rows.Add(rowAssess);

                    List <AVAILABLE_STANDARDS> standards = db.AVAILABLE_STANDARDS
                                                           .Include(x => x.Set_NameNavigation)
                                                           .Where(x => x.Assessment_Id == a.AssessmentId && x.Selected).ToList();
                    foreach (var s in standards)
                    {
                        if (!dt.Columns.Contains(s.Set_NameNavigation.Short_Name))
                        {
                            dt.Columns.Add(s.Set_NameNavigation.Short_Name, typeof(bool));
                        }
                        rowAssess[s.Set_NameNavigation.Short_Name] = true;
                    }
                }

                // Build an alphabetical list of standards involved
                List <string> setNames = new List <string>();
                for (int i = startColumn; i < dt.Columns.Count; i++)
                {
                    setNames.Add(dt.Columns[i].ColumnName);
                }
                setNames.Sort();


                foreach (DataRow rowAssessment in dt.Rows)
                {
                    var assessment = response.Assessments.Where(x => x.AssessmentId == (int)rowAssessment["AssessmentId"]).FirstOrDefault();
                    if (assessment == null)
                    {
                        continue;
                    }

                    foreach (string setName in setNames)
                    {
                        var set = new SelectedStandards();
                        assessment.SelectedStandards.Add(new SelectedStandards()
                        {
                            StandardName = setName,
                            Selected     = rowAssessment[setName] == DBNull.Value ? false : (bool)rowAssessment[setName]
                        });
                    }
                }
            }
        }