public IndexSchoolProfilesController(IGenericRepository2nd rpGeneric2nd)
 {
     this.rpGeneric2nd = rpGeneric2nd; //connect to accdatastore database in MySQL
     this.vmIndexPrimarySchoolProfilesModel   = new IndexPrimarySchoolProfilesViewModel();
     this.vmIndexSecondarySchoolProfilesModel = new IndexSecondarySchoolProfilesViewModel();
     this.vmIndexSpecialSchoolProfilesModel   = new IndexSecondarySchoolProfilesViewModel();
 }
        public ActionResult GetSecondaryProfileData(string sSchoolType)
        {
            List <string>              templistSelectedSchoolname = new List <string>();
            List <StudentObj>          listAllPupils          = new List <StudentObj>();
            List <School>              listSelectedSchoolname = new List <School>();
            List <AaeAttendanceObj>    listAaeAttendancelists = new List <AaeAttendanceObj>();
            List <ExclusionStudentObj> listExclusionPupils    = new List <ExclusionStudentObj>();

            bool schoolIsSelected = false;
            bool yesrIsSelected   = false;
            Year selectedYear     = null;

            vmIndexSecondarySchoolProfilesModel = Session["vmIndexSecondarySchoolProfilesModel"] as IndexSecondarySchoolProfilesViewModel;
            List <School> templistSchoolname = vmIndexSecondarySchoolProfilesModel.listSchoolname;
            List <Year>   templistYears      = vmIndexSecondarySchoolProfilesModel.listYears;

            if (Request["listSelectedSchoolname"] != null)
            {
                schoolIsSelected = true;
                //get CostCentreKey from dropdownlist in UI
                templistSelectedSchoolname = Request["listSelectedSchoolname"].Split(',').ToList();
                //select selected CostCentre from dropdownlist in UI
                listSelectedSchoolname = templistSchoolname.Where(x => templistSelectedSchoolname.Any(y => y.Contains(x.seedcode))).ToList();
            }

            if (Request["stringYear"] != null)
            {
                yesrIsSelected = true;
                string year = Request["stringYear"].ToString();
                vmIndexSecondarySchoolProfilesModel.stringYear = year;
                selectedYear = templistYears.Where(x => x.year.Contains(year)).FirstOrDefault();
            }

            if (schoolIsSelected && yesrIsSelected)
            {
                listAllPupils          = GetListAllPupils(rpGeneric2nd, selectedYear, sSchoolType);
                listAaeAttendancelists = GetAaeAttendanceLists(rpGeneric2nd, sSchoolType, selectedYear, listSelectedSchoolname, listAllPupils);
                listExclusionPupils    = GetListExclusionPupils(rpGeneric2nd, selectedYear, sSchoolType);
            }

            //create profiletitle
            string tempProfiletitle = null;

            foreach (var item in listSelectedSchoolname)
            {
                if (String.IsNullOrEmpty(tempProfiletitle))
                {
                    tempProfiletitle = item.name;
                }
                else
                {
                    tempProfiletitle = tempProfiletitle + " / " + item.name;
                }
            }



            vmIndexSecondarySchoolProfilesModel.profiletitle = tempProfiletitle;

            //store selected school into view model
            vmIndexSecondarySchoolProfilesModel.listSelectedSchoolname = listSelectedSchoolname;
            vmIndexSecondarySchoolProfilesModel.selectedYear           = selectedYear;
            vmIndexSecondarySchoolProfilesModel.listAllPupils          = listAllPupils;
            //setting english data and table
            List <DataSeries> temp = GetDataSeries("englishlevel", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);

            vmIndexSecondarySchoolProfilesModel.listDataSeriesEnglishLevel = temp;
            //vmIndexPrimarySchoolProfilesModel.englishLevelDataTable = GenerateTransposedTable(CreateDataTale(temp, vmIndexPrimarySchoolProfilesModel.DicEnglishLevel, "Level of English"));
            vmIndexSecondarySchoolProfilesModel.dataTableEnglishLevel = GenerateTransposedTable(CreateDataTable(temp, vmIndexSecondarySchoolProfilesModel.DicEnglishLevel, "Level of English", "percentage"));
            //setting ethnic data and table
            temp = GetDataSeries("ethnicity", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesEthnicBackground = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableEthnicBackground      = GenerateTransposedTable(CreateDataTable(temp, vmIndexSecondarySchoolProfilesModel.DicEthnicBG, "Ethnicity", "percentage"));
            //setting Nationality data and table
            temp = GetDataSeries("nationality", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesNationality = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableNationality      = GenerateTransposedTable(CreateDataTable(temp, vmIndexSecondarySchoolProfilesModel.DicNationalIdentity, "Nationality", "percentage"));
            //setting Stage data and table
            temp = GetDataSeries("stage", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesStage = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableStage      = CreateDataTaleWithTotal(temp, vmIndexSecondarySchoolProfilesModel.DicStage, "Stage", "number");
            //setting FreeSchoolMeal data and table
            temp = GetDataSeries("freemeal", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesFreeMeal  = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableFreeSchoolMeal = GenerateTransposedTable(CreateDataTable(temp, vmIndexSecondarySchoolProfilesModel.DicFreeMeal, "Free School Meal Entitlement", "percentage"));

            //setting LookAfter data and table
            temp = GetDataSeries("lookafter", listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesLookedAfter = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableLookedAfter      = GenerateTransposedTable(CreateDataTaleWithTotal(temp, vmIndexSecondarySchoolProfilesModel.DicLookedAfter, "Looked After Children", "no+%"));
            //Attendance
            vmIndexSecondarySchoolProfilesModel.showTableAttendance = listAaeAttendancelists.Count == 0 ? false : true;
            temp = listAaeAttendancelists.Count == 0 ? new List <DataSeries>() : GetAaeAttendanceDataSeries("attendance", listAaeAttendancelists, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesAttendance = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableAttendance      = temp.Count == 0 ? null : GenerateTransposedTable(CreateDataTable(temp, "School Attendance", "percentage"));

            //Exclusion
            vmIndexSecondarySchoolProfilesModel.showTableExclusion = listExclusionPupils.Count == 0 ? false : true;
            temp = listExclusionPupils.Count == 0 ? new List <DataSeries>() : GetExclusionDataSeries("exclusion", listExclusionPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesExclusion = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableExclusion      = temp.Count == 0 ? null : GenerateTransposedTable(CreateDataTable(temp, "Exclusions-Annual", "number"));

            //Budget
            temp = GetBudgetDataSeries(templistSchoolname, listSelectedSchoolname);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesBudget = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableBudget      = GenerateTransposedTable(CreatePIPSDataTable(temp, "School Cost"));
            //schoolRoll
            temp = GetSchoolRollDataSeries(listAllPupils, listSelectedSchoolname, selectedYear, sSchoolType);
            vmIndexSecondarySchoolProfilesModel.listDataSeriesSchoolRoll = temp;
            vmIndexSecondarySchoolProfilesModel.dataTableSchoolRoll      = GenerateTransposedTable(CreatePIPSDataTable(temp, "School Roll"));


            Session["vmIndexSecondarySchoolProfilesModel"] = vmIndexSecondarySchoolProfilesModel;
            return(View("IndexSecondarySchool", vmIndexSecondarySchoolProfilesModel));
        }