public ActionResult RemoveConfirmed(int companyid, int searchid) { CompanyItemCode companyItemCodes = db.CompanyItemCodes.Find(companyid, searchid); db.CompanyItemCodes.Remove(companyItemCodes); db.SaveChanges(); return(RedirectToAction("Details", "DBECompanies", new { id = companyItemCodes.CompanyID })); }
public ActionResult Add(CompanyItemCode companyItemCodes) { if (ModelState.IsValid) { db.CompanyItemCodes.Add(companyItemCodes); db.SaveChanges(); return(RedirectToAction("Details", "DBECompanies", new { id = companyItemCodes.CompanyID })); } return(View("Index")); }
// GET: CompanyNaicsCode/Delete/5 public ActionResult Remove(int?companyid, int?searchid) { if (searchid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CompanyItemCode companyItemCode = db.CompanyItemCodes.Find(companyid, searchid); if (companyItemCode == null) { return(HttpNotFound()); } return(View(companyItemCode)); }
//need to send an array rather than individual items...ask Dick about this //public ActionResult SearchResults(Boolean DBE, Boolean ACDBE, Boolean SBE, Boolean MBE, String companylist, String BusinessDescription, String NAICS, String Item, String OwnersFirstName, String OwnersLastName, String City, String State, String Zip, String AreaCode, String County) public ActionResult SearchResults(CompanySearchViewModel searchData) { int? CompanyId2 = 1; int? ItemCode = 805; CompanyItemCode stuff = db.CompanyItemCodes.Find(CompanyId2, ItemCode); if (stuff != null) { Console.WriteLine("wooHoo!"); } IQueryable <DBECompany> searchquery = db.DBECompanies; if (searchData != null) { if (!(searchData.DBE)) { searchquery = searchquery.Where(s => s.DBE != true); } if (!(searchData.ACDBE)) { searchquery = searchquery.Where(s => s.ACDBE != true); } if (!(searchData.MBE)) { searchquery = searchquery.Where(s => s.MBE != true); } if (!(searchData.SBE)) { searchquery = searchquery.Where(s => s.SBP != true); } if (!String.IsNullOrEmpty(searchData.Company)) { searchquery = searchquery.Where(c => c.CompanyName.Contains(searchData.Company)).Select(c => c); } if (!String.IsNullOrEmpty(searchData.BusinessDescription)) { IQueryable <DBECompany> dBECompanies = searchquery.Join(db.CompanyNAICSCodes, a => a.CompanyId, b => b.Companyid, (a, b) => new { a, b }) .Join(db.NAICSCodes, c => c.b.NAICSCode, d => d.NAICSCode1, (c, d) => new { c, d }) .Where(e => e.d.Description.Contains(searchData.BusinessDescription)) .Select(g => g.c.a); IQueryable <DBECompany> NAICSCompanies = searchquery.Join(db.CompanyItemCodes, a => a.CompanyId, b => b.CompanyID, (a, b) => new { a, b }) .Join(db.ItemCodes, c => c.b.ItemCode, d => d.ItemCode1, (c, d) => new { c, d }) .Where(e => e.d.Description.Contains(searchData.BusinessDescription)) .Select(g => g.c.a); searchquery = dBECompanies.Union(NAICSCompanies); } if (searchData.NAICS != null && searchData.NAICS.Count > 0 && !String.IsNullOrEmpty(searchData.NAICS[0])) { //var searchCodes = searchData.NAICS.Select(p => p.Substring(0, 6)).ToList(); searchquery = from company in searchquery join compNAICSCode in db.CompanyNAICSCodes on company.CompanyId equals compNAICSCode.Companyid join searchCode in searchData.NAICS /*searchCodes*/ on compNAICSCode.NAICSCode equals searchCode select company; } if (searchData.ItemCode != null && searchData.ItemCode.Count > 0 && searchData.ItemCode[0] > 0) { //var searchCodes = searchData.ItemCode.Select(p => p.Substring(0, 6)).ToList(); searchquery = from company in searchquery join compItemCodeCode in db.CompanyItemCodes on company.CompanyId equals compItemCodeCode.CompanyID join searchCode in searchData.ItemCode /*searchCodes*/ on compItemCodeCode.ItemCode equals searchCode select company; } if (!String.IsNullOrEmpty(searchData.OwnerFirstName)) { searchquery = searchquery.Where(c => c.OwnersFirstName.Contains(searchData.OwnerFirstName)).Select(c => c); } if (!String.IsNullOrEmpty(searchData.OwnerLastName)) { searchquery = searchquery.Where(c => c.OwnersLastName.Contains(searchData.OwnerLastName)).Select(c => c); } if (searchData.Cities != null && searchData.Cities.Count > 0 && !String.IsNullOrEmpty(searchData.Cities[0])) { searchquery = searchquery.Join(searchData.Cities, a => a.City, b => b, (a, b) => a).Select(c => c); } if (searchData.States != null && searchData.States.Count > 0 && !String.IsNullOrEmpty(searchData.States[0])) { searchquery = searchquery.Join(searchData.States, a => a.State, b => b, (a, b) => a).Select(c => c); } if (searchData.OwnerZipCodes != null && searchData.OwnerZipCodes.Count > 0 && !String.IsNullOrEmpty(searchData.OwnerZipCodes[0])) { searchquery = searchquery.Join(searchData.OwnerZipCodes, a => a.Zip, b => b, (a, b) => a).Select(c => c); } if (!string.IsNullOrEmpty(searchData.AreaCode)) { searchquery = searchquery.Where(c => c.Phone.StartsWith(searchData.AreaCode)); //Area Code is not split out in DB Need to string length check first???? } //if (!(string.IsNullOrEmpty(County))) //currently, county does not exist in the database //{ //} //done with the querybuilding List <DBECompany> results = searchquery.Distinct().ToList(); //var results = db.DBECompany.Where(c => c.CompanyName.ToUpper().Contains(companylist.ToUpper())).Select(c => c).ToArray(); return(PartialView("~/Views/DBECompany/_SearchResults.cshtml", results)); } return(View()); }