コード例 #1
0
        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));
            }
        }
コード例 #2
0
        public ActionResult Modificar(int restauranteId, int telefoneId, int enderecoId)
        {
            Restaurante restaurante = rep.Busca(restauranteId);

            Telefone telefone = trep.Busca(telefoneId);

            Endereco endereco = erep.Busca(enderecoId);

            if (restaurante == null)
            {
                return(HttpNotFound());
            }
            restaurante.Endereco = endereco;
            restaurante.Telefone = telefone;
            return(View(restaurante));
        }