public ActionResult Perfil(int?id) { int index; index = id.GetValueOrDefault(); if (index != 0) { var Usuario = rep.Busca(index); IList <Favorito> favoritos = frep.Lista(); favoritos = favoritos.Where(fav => fav.UsuarioId == Usuario.UsuarioId).ToList(); IList <Restaurante> restaurantes = rrep.Lista(); IList <Restaurante> restaurantesfavoritos = new List <Restaurante>(); foreach (var restaurante in restaurantes) { foreach (var restaurantefav in favoritos) { if (restaurantefav.RestauranteId == restaurante.RestauranteId) { var restaurantefavorito = restaurantes.FirstOrDefault(r => r.RestauranteId == restaurantefav.RestauranteId); restaurantesfavoritos.Add(restaurantefavorito); } } } ViewBag.Favoritos = restaurantesfavoritos; ViewBag.Endereco = erep.Busca(Usuario.EnderecoId); ViewBag.Telefone = trep.Busca(Usuario.TelefoneId); return(View(Usuario)); } else { var Usuario = (Usuario)Session["usuarioLogado"]; IList <Favorito> favoritos = frep.Lista(); favoritos = favoritos.Where(fav => fav.UsuarioId == Usuario.UsuarioId).ToList(); IList <Restaurante> restaurantes = rrep.Lista(); IList <Restaurante> restaurantesfavoritos = new List <Restaurante>(); foreach (var restaurante in restaurantes) { foreach (var restaurantefav in favoritos) { if (restaurantefav.RestauranteId == restaurante.RestauranteId) { var restaurantefavorito = restaurantes.FirstOrDefault(r => r.RestauranteId == restaurantefav.RestauranteId); restaurantesfavoritos.Add(restaurantefavorito); } } } ViewBag.Favoritos = restaurantesfavoritos; ViewBag.Endereco = erep.Busca(Usuario.EnderecoId); ViewBag.Telefone = trep.Busca(Usuario.TelefoneId); return(View(Usuario)); } }
public async Task <ActionResult> Get([FromBody] UsuarioFilter item) { try { //carrega o repositorio using var repository = new UsuarioRepository(); //efetua a consulta var result = await repository.Busca(item); //retorna o resultado return(Ok(result)); } catch (Exception ex) { return(BadRequest(new ValidationModel(ex.Message))); } }
public async Task <ActionResult> Get(int id) { try { //carrega o repositorio using var repository = new UsuarioRepository(); //efetua a consulta var result = await repository.Busca(id); //retorna o resultado if (result != null) { return(Ok(result)); } return(NoContent()); } catch (Exception ex) { return(BadRequest(new ValidationModel(ex.Message))); } }