コード例 #1
0
        public ActionResult Search(string keyWords)
        {
            // Replace keyword with a "<span>" so that it can be highlighted.
            var replacedKeyWords = "<span class=\"keyWord\">" + keyWords + "</span>";

            CompanyIntroductionViewModel thisModel = new CompanyIntroductionViewModel();

            // Select the companies with the keywords we need.
            var targetedCompanies = db.Companies.Where(c => c.CompanyIntroduction.Contains(keyWords) || c.CompanyLocation.Contains(keyWords) || c.CompanyName.Contains(keyWords) || c.InternIntroduction.Contains(keyWords) || c.PersonInCharge.Contains(keyWords) || c.ContactNumber.Contains(keyWords)).ToList();

            // Replace keywords with the "replacedKeyWords".
            targetedCompanies.ForEach(c =>
            {
                c.CompanyIntroduction = c.CompanyIntroduction.Replace(keyWords, replacedKeyWords);
                c.CompanyLocation     = c.CompanyLocation.Replace(keyWords, replacedKeyWords);
                c.CompanyName         = c.CompanyName.Replace(keyWords, replacedKeyWords);
                c.InternIntroduction  = c.InternIntroduction.Replace(keyWords, replacedKeyWords);
                c.PersonInCharge      = c.PersonInCharge.Replace(keyWords, replacedKeyWords);
                c.ContactNumber       = c.ContactNumber.Replace(keyWords, replacedKeyWords);
            }
                                      );
            thisModel.targetedCompanies = targetedCompanies;
            thisModel.companies         = db.Companies.ToList().Except(targetedCompanies).ToList();
            thisModel.keyWords          = keyWords;
            return(View("CompanyIntroduction", thisModel));
        }
コード例 #2
0
        public ActionResult CompanyIntroduction()
        {
            CompanyIntroductionViewModel thisModel = new CompanyIntroductionViewModel();

            thisModel.companies         = db.Companies.ToList();
            thisModel.targetedCompanies = new List <Company>();
            return(View(thisModel));
        }