I developed a Code First system in Asp.Net MVC
In this development I created a relationship very much and I want to do a research that includes these relationships in a research, I describe below better in code what I have developed
In addition to the Company and Category that will be searched by TextBox
, I also want to search together with DropDownList
Cities
My idea of Synthesis (Empresa || Categoria) && Cidade
I would also like that in the search of TextBox
if the user type without emphasis the search returns the result, therefore I am having problems of returns in this case.
An example is I have Pharmacies the user types Farma or Pharmacy without accent does not return result.
I have the following classes. Company, Categories and the relationship class CompanyCategories.
Business Class
public class Empresa
{
public int Id { get; set; }
public string Nome { get; set; }
public string Telefone { get; set; }
public string Cidade {get; set;}
public ICollection<EmpresaCategoria> CategoriaEmpresa { get; set; }
}
Class Category
public class Categoria
{
public int Id { get; set; }
public string Nome { get; set; }
public ICollection<EmpresaCategoria> CategoriaEmpresa { get; set; }
}
NxN Relationship Class
public class EmpresaCategoria
{
[Key]
public int Id { get; set; }
[ForeignKey("Categoria")]
public int CategoriaId { get; set; }
[ForeignKey("Empresa")]
public int EmpresaId { get; set; }
public virtual Categoria Categoria { get; set; }
public virtual Empresa Empresa { get; set; }
}
No Controller
I have a search that works, but it searches only Company, I also want to include Category
public ActionResult Resultado(string empresa, string cidade)
{
if (string.IsNullOrEmpty(pesquisaEmpresaOuCategoria))
{
return Redirect("Index");
}
/*
*ADICIONEI UM COMBO BOX COM A CIDADE
*Quero Incluir a categoria nesta pesquisa
*include
*/
//AQUI PREENCHE O COMBO BOX COM CIDADES
ViewBag.cidade = new SelectList(db.Empresa.Select(a => a.Cidade).Distinct());
return View(db.Empresa.Where(x => x.Nome.Contains(empresa) && x.Cidade.Contains(cidade)).ToList());
}