private void GetPratos(PratoBll pratoBll, Restaurante restaurante) { try { restaurante.Pratos = pratoBll.GetByRestauranteId(restaurante.Id, false); } catch (ListNoContentException ex) { //Log.Debug(""); } }
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); }
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); }
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); }
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); }