public async Task <IActionResult> PutAnimalCategory(int id, AnimalCategory animalCategory) { if (id != animalCategory.AnimalCategoryId) { return(BadRequest()); } _context.Entry(animalCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(new JsonResult(animalCategory)); } catch (DbUpdateConcurrencyException) { if (!AnimalCategoryExists(id)) { return(NotFound()); } else { throw; } } }
// This is the requested function with the optional parameter. It uses a // nullable boolean where null represents no parameter supplied, in which case // it will not filter based on the tail. public AnimalCollection Categorise(AnimalCategory category, bool?hasTail = null) { // hasTail can be safely cast to a bool because operator short-circuiting on the || will // have caught any nulls. Beware if you need to change this. return(new AnimalCollection(this.Where(x => x.Category == category && (hasTail == null || (bool)hasTail == x.HasTail)))); }
public async Task <ActionResult <AnimalCategory> > PostAnimalCategory(AnimalCategory animalCategory) { await _context.AnimalCategories.AddAsync(animalCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAnimalCategory", new { id = animalCategory.AnimalCategoryId }, animalCategory)); }
/// <summary> /// Initialize the list of animals, based on which category is selected. /// </summary> /// <param name="category"></param> /// <exception cref="ArgumentOutOfRangeException"></exception> private void InitObjectChoser(AnimalCategory category) { switch (category) { case AnimalCategory.Bird: lbxAnimalObject.DataSource = new List <string>(Enum.GetNames(typeof(Birds))); break; case AnimalCategory.Mammal: lbxAnimalObject.DataSource = new List <string>(Enum.GetNames(typeof(Mammals))); break; case AnimalCategory.All: var birds = new List <string>(Enum.GetNames(typeof(Birds))); var mammals = new List <string>(Enum.GetNames(typeof(Mammals))); var choices = new List <string>(birds); choices.AddRange(mammals); lbxAnimalObject.DataSource = choices; break; default: throw new ArgumentOutOfRangeException(); } }
public AnimalCollection Categorise(AnimalCategory category, bool hasTail) { return(Categorise(category, (bool?)hasTail)); }
public AnimalCollection Categorise(AnimalCategory category) { return(Categorise(category, null)); }
public static Animal[] FindAnimals(AnimalCategory category, AnimalRarity rarity, TerrainType terrainType, bool isProtected) => AvailableAnimals.FindAll(x => x.Category == category && x.Rarity == rarity && x.TerrainType == terrainType && x.IsProtected == isProtected).ToArray();
public static Animal[] FindAnimals(AnimalCategory category, AnimalRarity rarity, TerrainType terrainType) => AvailableAnimals.FindAll(x => x.Category == category && x.Rarity == rarity && x.TerrainType == terrainType).ToArray();
public static Animal[] FindAnimals(AnimalCategory category, bool isProtected) => AvailableAnimals.FindAll(x => x.Category == category && x.IsProtected == isProtected).ToArray();
public static Animal[] FindAnimals(AnimalCategory category, AnimalRarity rarity) => AvailableAnimals.FindAll(x => x.Category == category && x.Rarity == rarity).ToArray();
public static Animal[] FindAnimals(AnimalCategory category) => AvailableAnimals.FindAll(x => x.Category == category).ToArray();
public Animal(string name, AnimalCategory category, bool hasTail) { Name = name; Category = category; HasTail = hasTail; }