Exemple #1
0
    /// <summary>
    /// Initialize all of the internal objects inside of the query definition
    /// </summary>
    /// <returns>A new instance of type QueryDefinition</returns>
    public static Profiles GetNewProfilesDefinition()
    {
        QueryDefinition qd       = new QueryDefinition();
        Profiles        profiles = new Profiles();

        Name name = new Name();

        name.FirstName = new FirstName();
        name.LastName  = new LastName();
        qd.Name        = name;


        OutputOptions oo = new OutputOptions();

        oo.SortType    = OutputOptionsSortType.QueryRelevance;
        oo.StartRecord = "0";

        Affiliation     affiliation = new Affiliation();
        AffiliationList affList     = new AffiliationList();

        //affiliations.AffiliationList = affList;
        affList.Affiliation = new List <Affiliation>();
        affList.Affiliation.Add(affiliation);


        FacultyRankList ftList = new FacultyRankList();

        ftList.FacultyRank = new List <string>();

        KeywordString kws = new KeywordString();
        Keywords      kw  = new Keywords();

        kw.KeywordString = new KeywordString();
        kw.KeywordString = kws;

        profiles.QueryDefinition = qd;
        profiles.QueryDefinition.AffiliationList = affList;
        profiles.QueryDefinition.Keywords        = kw;
        profiles.QueryDefinition.Name            = name;

        profiles.OutputOptions = oo;

        //its hard wired for 2 in this version.
        profiles.Version = 2;

        return(profiles);
    }
    /// <summary>
    /// Build the search request, submit the search and process the result.
    /// This is the handler for the main search using the full set of criteria
    /// </summary>
    private void ProcessProfileSearch()
    {
        Profiles searchReq = ProfileHelper.GetNewProfilesDefinition();

        string lastName  = this.HTMLEncode(txtLastName.Text.Trim());
        string firstName = this.HTMLEncode(txtFirstName.Text.Trim());

        Session["ProfileSearchRequestCriteriaList"] = new List <string>();
        Session["ProfileSearchRequestKeywordList"]  = new List <string>();

        // Reset current page number
        Session["ProfileSearchResultsPage"] = 0;

        grdSearchResults.DataSource = null;

        // Name
        if (lastName.Length > 0)
        {
            searchReq.QueryDefinition.Name.LastName.Text = lastName.Trim();
            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(lastName);
        }

        if (firstName.Length > 0)
        {
            searchReq.QueryDefinition.Name.FirstName.Text = firstName.Trim();
            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(firstName);
        }

        // Institution Selection
        if (ddlInstitution.SelectedIndex != 0)
        {
            AffiliationInstitutionName affilInstname = new AffiliationInstitutionName();
            affilInstname.Text = ddlInstitution.SelectedItem.Text;
            searchReq.QueryDefinition.AffiliationList.Affiliation[0].InstitutionName = affilInstname;

            // Set the appropriate message on the right
            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(chkInstitution.Checked == true ? "All except " + affilInstname.Text : affilInstname.Text);

            searchReq.QueryDefinition.AffiliationList.Affiliation[0].InstitutionName.Exclude = chkInstitution.Checked;
        }

        // Division Selection
        if (ddlDivision.SelectedIndex != 0)
        {
            AffiliationDivisionName affilDivname = new AffiliationDivisionName();
            affilDivname.Text = ddlDivision.SelectedItem.Text;
            searchReq.QueryDefinition.AffiliationList.Affiliation[0].DivisionName = affilDivname;

            // Set the appropriate message on the right
            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(chkInstitution.Checked == true ? "All except " + affilDivname.Text : affilDivname.Text);

            searchReq.QueryDefinition.AffiliationList.Affiliation[0].DivisionName.Exclude = chkDivision.Checked;
        }


        // Department Selection
        if (ddlDepartment.SelectedIndex != 0)
        {
            AffiliationDepartmentName affilDeptname = new AffiliationDepartmentName();
            affilDeptname.Text = ddlDepartment.SelectedItem.Text;
            searchReq.QueryDefinition.AffiliationList.Affiliation[0].DepartmentName = affilDeptname;

            // Set the appropriate message on the right
            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(chkDepartment.Checked == true ? "All except " + affilDeptname.Text : affilDeptname.Text);

            searchReq.QueryDefinition.AffiliationList.Affiliation[0].DepartmentName.Exclude = chkDepartment.Checked;
        }

        // Faculty Selection
        if (ddlFacultyRank.SelectedIndex != 0)
        {
            FacultyRankList ftList = new FacultyRankList();

            searchReq.QueryDefinition.FacultyRankList             = new FacultyRankList();
            searchReq.QueryDefinition.FacultyRankList.FacultyRank = new List <string>();

            searchReq.QueryDefinition.FacultyRankList.FacultyRank.Add(ddlFacultyRank.SelectedItem.Value.ToString());

            ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(ddlFacultyRank.SelectedItem.Text);
        }

        // Person Filter Section
        HiddenField  hdnSelectedText = ((HiddenField)ctcFirst.FindControl("hdnSelectedText"));
        PersonFilter pf;

        searchReq.QueryDefinition.PersonFilterList = new PersonFilterList();

        if ((hdnSelectedText.Value.Length > 0) && (hdnSelectedText.Value != "--Select--"))
        {
            string[] pfArray = hdnSelectedText.Value.Split(',');

            for (int i = 0; i < pfArray.Length; i++)
            {
                pf      = new PersonFilter();
                pf.Text = pfArray[i];

                searchReq.QueryDefinition.PersonFilterList.Add(pf);

                ((List <string>)Session["ProfileSearchRequestCriteriaList"]).Add(pfArray[i]);
            }
        }

        // Keywords
        if (txtKeyword.Text.Trim().Length > 0)
        {
            string keywordString;

            if (chkKeyword.Checked == true)
            {
                keywordString = this.HTMLEncode(txtKeyword.Text.Trim().Replace("\"", ""));

                searchReq.QueryDefinition.Keywords.KeywordString.Text      = keywordString;
                searchReq.QueryDefinition.Keywords.KeywordString.MatchType = KeywordMatchType.exact;
                ((List <string>)Session["ProfileSearchRequestKeywordList"]).Add(keywordString);
            }
            else
            {
                keywordString = this.HTMLEncode(txtKeyword.Text.Trim());

                searchReq.QueryDefinition.Keywords.KeywordString.Text = keywordString;


                ((List <string>)Session["ProfileSearchRequestKeywordList"]).Add(keywordString);
            }
        }

        searchReq.Version = 2;

        // Save the search request into a session object so that the
        // object data source can use it during the Select event


        Session["ProfileSearchRequest"] = searchReq;

        Session["MeshSearch"]      = 0;
        Session["SearchPageIndex"] = 0;
        Session["WasSearchRun"]    = "Y";

        // Get results bound to grid
        BindSearchResults(0);

        SetBackPageURL();
    }
Exemple #3
0
        private void match(String facultyName, List <Preference> preferences, Student student)
        {
            //add student as rejected in the db at first
            FacultyRankList rejected = new FacultyRankList()
            {
                EGN           = student.EGN,
                ProgrammeName = CONST_REJECTED + ' ' + facultyName,
                TotalGrade    = 0
            };

            context.FacultyRankLists.Add(rejected);
            context.SaveChanges();
            try
            {
                foreach (Preference preference in preferences)
                {
                    int quota = queryManager.getQuota(preference.ProgrammeName, (bool)student.Gender);
                    List <FacultyRankList> rankList = queryManager.getRankListData(preference.ProgrammeName, (bool)student.Gender);
                    double minimalGrade             = 0;
                    double studentCount             = rankList.Count;

                    if (rankList.Count != 0)
                    {
                        minimalGrade = rankList.Min(list => list.TotalGrade);
                    }


                    if (preference.TotalGrade > minimalGrade &&
                        studentCount >= quota &&
                        ((quota >= 2 &&
                          rankList[quota - 2].TotalGrade > minimalGrade) ||
                         (quota == 1 &&
                          rankList[quota - 1].TotalGrade > minimalGrade)
                        ))
                    {
                        var entries = rankList.Where(entry => entry.TotalGrade == minimalGrade);

                        foreach (FacultyRankList entry in entries)
                        {
                            context.FacultyRankLists.Attach(entry);
                            context.FacultyRankLists.Remove(entry);
                        }
                        context.SaveChanges();
                    }

                    if ((preference.TotalGrade > 0 &&
                         preference.TotalGrade >= minimalGrade) ||
                        (preference.TotalGrade < minimalGrade &&
                         studentCount < quota))
                    {
                        FacultyRankList entry = new FacultyRankList()
                        {
                            EGN           = preference.EGN,
                            ProgrammeName = preference.ProgrammeName,
                            TotalGrade    = preference.TotalGrade
                        };

                        context.FacultyRankLists.Add(entry);
                        context.FacultyRankLists.Attach(rejected);
                        context.FacultyRankLists.Remove(rejected);
                        context.SaveChanges();

                        break;
                    }
                }
            }
            catch (Exception e)
            {
                context.FacultyRankLists.Attach(rejected);
                context.FacultyRankLists.Remove(rejected);
                context.SaveChanges();
                throw e;
            }
        }
Exemple #4
0
        public ActionResult Index(String faculty, String programmeName)
        {
            //генериране на combobox
            List <String> l = programmes.Keys.ToList <string>();

            l.Insert(0, "Please Select");
            SelectList faculties = new SelectList(l);

            ViewData["faculties"] = faculties;

            //проверка дали е настъпила дата за обявяване на класиране

            RankingContext db  = new RankingContext();
            QueryManager   mng = new QueryManager(db);

            // класиране първи етап - дати
            DateTime first = Convert.ToDateTime(mng.getCampaignDates().FirstRankingDate);

            ViewData["isFirstRankingDate"] = false;
            if (DateTime.Today >= first)
            {
                ViewData["isFirstRankingDate"] = true;
            }

            ViewData["isFirstRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isFirstRankListPublished"] = true;
            }


            // класиране втори етап - дати
            DateTime second = Convert.ToDateTime(mng.getCampaignDates().SecondRankingDate);

            ViewData["isSecondRankingDate"] = false;
            if (DateTime.Today >= second)
            {
                ViewData["isSecondRankingDate"] = true;
            }

            ViewData["isSecondRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isSecondRankListPublished"] = true;
            }

            // класиране трети етап - дати
            DateTime third = Convert.ToDateTime(mng.getCampaignDates().ThirdRankingDate);

            ViewData["isThirdRankingDate"] = false;
            if (DateTime.Today >= third)
            {
                ViewData["isThirdRankingDate"] = true;
            }

            ViewData["isThirdRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isThirdRankListPublished"] = true;
            }



            //вземане на потребителското име на потребителя
            String user = User.Identity.Name;

            ViewData["userName"] = user;

            //проверка кой администратор е влязъл
            ViewData["mainAdmin"] = false;
            if (user == "Admin")
            {
                ViewData["mainAdmin"] = true;
            }

            QueryManager queryManager = new QueryManager(db);

            List <FacultyRankList> rankList = queryManager.getRankList(programmeName);

            foreach (var item in rankList)
            {
                FacultyRankList rank = new FacultyRankList
                {
                    ProgrammeName = programmeName,
                    EGN           = item.EGN,
                    TotalGrade    = item.TotalGrade
                };
                model.Add(rank);
            }

            //FacultyRankList f = new FacultyRankList
            //{
            //    EGN = "12345678",
            //    ProgrammeName = programmeName,
            //    TotalGrade = 4.5
            //};
            //model.Add(f);

            ViewData["result"] = model;

            return(PartialView("_ProgrammeRankListTable", model));
        }