Exemple #1
0
        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;
                }
            }
        }
Exemple #2
0
 // 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))));
 }
Exemple #3
0
        public async Task <ActionResult <AnimalCategory> > PostAnimalCategory(AnimalCategory animalCategory)
        {
            await _context.AnimalCategories.AddAsync(animalCategory);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAnimalCategory", new { id = animalCategory.AnimalCategoryId }, animalCategory));
        }
Exemple #4
0
        /// <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();
            }
        }
Exemple #5
0
 public AnimalCollection Categorise(AnimalCategory category, bool hasTail)
 {
     return(Categorise(category, (bool?)hasTail));
 }
Exemple #6
0
 public AnimalCollection Categorise(AnimalCategory category)
 {
     return(Categorise(category, null));
 }
Exemple #7
0
 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();
Exemple #8
0
 public static Animal[] FindAnimals(AnimalCategory category, AnimalRarity rarity, TerrainType terrainType)
 => AvailableAnimals.FindAll(x => x.Category == category && x.Rarity == rarity && x.TerrainType == terrainType).ToArray();
Exemple #9
0
 public static Animal[] FindAnimals(AnimalCategory category, bool isProtected)
 => AvailableAnimals.FindAll(x => x.Category == category && x.IsProtected == isProtected).ToArray();
Exemple #10
0
 public static Animal[] FindAnimals(AnimalCategory category, AnimalRarity rarity)
 => AvailableAnimals.FindAll(x => x.Category == category && x.Rarity == rarity).ToArray();
Exemple #11
0
 public static Animal[] FindAnimals(AnimalCategory category)
 => AvailableAnimals.FindAll(x => x.Category == category).ToArray();
Exemple #12
0
 public Animal(string name, AnimalCategory category, bool hasTail)
 {
     Name     = name;
     Category = category;
     HasTail  = hasTail;
 }