// GET: Animals based on search criteria public async Task <IActionResult> Index(string animalType, string searchString) { //OBS: we could search by type and breed as well when we have the database and classes //info about this in the tutorial //defined linq query IQueryable <string> typeQuery = from a in _context.Animal orderby a.Type select a.Type; var animals = from animal in _context.Animal select animal; if (!String.IsNullOrEmpty(searchString)) { animals = animals.Where(p => p.RFID.Contains(searchString)); } if (!string.IsNullOrEmpty(animalType)) { animals = animals.Where(x => x.Type == animalType); } var animalTypeVM = new AnimalTypeViewModel { Type = new SelectList(await typeQuery.Distinct().ToListAsync()), Animal = await animals.ToListAsync() }; return(View(animalTypeVM)); }
public async Task <IActionResult> Rename(AnimalTypeViewModel model) { await _animalTypeService.RenameAnimalType(model.AnimalTypeId, model.TypeName); return(NoContent()); }