public async Task <IActionResult> GetAllByStore(int storeId,
                                                        CancellationToken cancellationToken = default)
        {
            var aFood = await _foodRepository.FindAll(food => food.StoreId == storeId).FirstOrDefaultAsync(cancellationToken);

            if (aFood == null)
            {
                return(NotFound("No Store Or No Food Found"));
            }

            return(Ok(_mapper.Map <IEnumerable <FoodDTO> >(await _foodRepository.FindAll(storeId).ToListAsync())));
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the total food price of zoo animals.
        /// </summary>
        /// <returns></returns>
        public double GetTotalFoodPrice()
        {
            var foodPrices = _foodRepository.FindAll();
            var animals    = _animalRepository.FindAll();
            var species    = _animalSpecieRepository.FindAll();

            var amount = 0.0;

            foreach (var animal in animals)
            {
                var specie = species.SingleOrDefault(x => x.Specie == animal.Specie);

                if (specie is Omnivore omnivore)
                {
                    omnivore.PricePerKg      = foodPrices[FoodCategory.Meat];
                    omnivore.FruitPricePerKg = foodPrices[FoodCategory.Fruit];
                }
                else
                {
                    specie.PricePerKg = foodPrices[specie is Carnivore ?FoodCategory.Meat: FoodCategory.Fruit];
                }
                amount += specie.GetFoodPrice(animal.Weight);
            }
            return(amount);
        }