コード例 #1
0
        public ActionResult Index(CompaniesSearchView c)
        {
            if (c.searchType == "All")
            {
                c.companies = dbNew.Companies.Include(co => co.PrimaryIndustry).ToList();
            }

            else if (c.searchType == "Exact")
            {
                var comp = dbNew.Companies.FirstOrDefault(co => co.name == c.searchName);

                if (comp == null)
                {
                    return(View(c));
                }
                //var l = new List<Company>();
                //l.Add(comp);
                //c.companies = l;
                return(RedirectToAction("EditCompany", "Companies", new { @id = comp.Id }));

                // return View("EditCompany", comp);
            }
            else if (c.searchType == "By Parts")
            {
                if (c.searchName == "")
                {
                    return(View(c));
                }

                var parts = c.searchName.Split(' ');
                c.companies = dbNew.Companies
                              .Include(co => co.PrimaryIndustry)
                              .Where(co => parts.Where(p => p.Length > 1)
                                     .All(p => co.name.Contains(p))).ToList();
            }

            /*else c.companies = (dbNew.Companies.Where(co => co.name == c.searchName));
             * List<SelectListItem> listSelectListItems = new List<SelectListItem>();
             * foreach (Company comp in dbNew.Companies)
             * {
             *  listSelectListItems.Add(new SelectListItem()
             *  {
             *      Text = comp.name,
             *      Value = comp.Id.ToString(),
             *      Selected = false
             *  });
             * }
             * c.companiesList = listSelectListItems;*/

            return(View(c));
        }
コード例 #2
0
        public ActionResult DeleteCompany(int id)
        {
            Company co = dbNew.Companies.Find(id);

            if (co == null)
            {
                return(HttpNotFound());
            }
            dbNew.Companies.Remove(co);
            dbNew.SaveChanges();
            var cs = new CompaniesSearchView();

            cs.searchType = "All";
            return(RedirectToAction("Index"));
        }