Пример #1
0
        public IQueryable <Animal> GetAnimals(AnimalFilteringViewModel model)
        {
            var result = _Context.Animal.AsQueryable();

            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.Nome))
                {
                    result = result.Where(x => x.Nome.Contains(model.Nome));
                }
                if (!string.IsNullOrEmpty(model.Especie))
                {
                    result = result.Where(x => x.Especie.Contains(model.Especie));
                }
                if (!string.IsNullOrEmpty(model.Porte))
                {
                    result = result.Where(x => x.Porte.Contains(model.Porte));
                }
                if (model.CidadeId.HasValue)
                {
                    result = result.Where(x => x.CidadeId == model.CidadeId);
                }
                if (model.Disponibilidade == "adotado")
                {
                    result = result.Where(x => x.Adotado);
                }
                else
                {
                    result = result.Where(x => !x.Adotado);
                }
                result = result.OrderBy(x => x.Data_Cadastro.TimeOfDay).ThenBy(x => x.Data_Cadastro.Date).ThenBy(x => x.Data_Cadastro.Year);
            }
            return(result);
        }
Пример #2
0
        public async Task <IActionResult> Index(AnimalFilteringViewModel model)
        {
            var list = _AnimalService.GetAnimals(model);

            foreach (Animal animal in list)
            {
                animal.Cidade = await _CidadeService.FindByIdAsync(animal.CidadeId);

                animal.Usuario = await UserManager.FindByIdAsync(animal.UsuarioId);
            }
            model.Animals = list;
            model.Cidades = await _CidadeService.FindAllAsync();

            return(View(model));
        }