コード例 #1
0
 private void GetPratos(PratoBll pratoBll, Restaurante restaurante)
 {
     try
     {
         restaurante.Pratos = pratoBll.GetByRestauranteId(restaurante.Id, false);
     }
     catch (ListNoContentException ex)
     {
         //Log.Debug("");
     }
 }
コード例 #2
0
        private List <Prato> SavePratos(List <Prato> pratos, long RestauranteId)
        {
            if (pratos != null)
            {
                PratoBll pratoBll = new PratoBll(_context, false);
                foreach (Prato prato in pratos)
                {
                    prato.RestauranteId = RestauranteId;
                    pratoBll.Save(prato);
                }
            }

            return(pratos);
        }
コード例 #3
0
        public List <Restaurante> GetByNome(string filtro)
        {
            List <Restaurante> restaurantes = _context.Restaurantes.Where(t => t.Nome.ToUpper().IndexOf(filtro.ToUpper()) >= 0).ToList();

            ValidaLista(restaurantes);

            if (restaurantes != null)
            {
                PratoBll pratoBll = new PratoBll(_context);
                foreach (Restaurante item in restaurantes)
                {
                    GetPratos(pratoBll, item);
                }
            }

            return(restaurantes);
        }
コード例 #4
0
        public List <Restaurante> GetAll()
        {
            List <Restaurante> restaurantes = _context.Restaurantes.ToList();

            ValidaLista(restaurantes);

            if (restaurantes != null)
            {
                PratoBll pratoBll = new PratoBll(_context);
                foreach (Restaurante item in restaurantes)
                {
                    GetPratos(pratoBll, item);
                }
            }

            return(restaurantes);
        }
コード例 #5
0
        public Restaurante GetById(long id, bool populaPratos = true)
        {
            Restaurante restaurante = _context.Restaurantes.FirstOrDefault(t => t.Id == id);

            if (restaurante == null)
            {
                throw new EntityNotFoundException(String.Format("Restaurante de id {0} não encontrado!", id));
            }

            // Evitar self reference
            if (populaPratos)
            {
                PratoBll pratoBll = new PratoBll(_context);
                GetPratos(pratoBll, restaurante);
            }
            else
            {
                restaurante.Pratos = null;
            }

            return(restaurante);
        }