Example #1
0
    public static void CalculateMeals(DateTime timeArrived, DateTime timeExit)
    {
        // Number of full days
        int      fullDaysNumber = (timeExit - timeArrived).Days;
        DayMeals dayMeals       = new DayMeals();

        for (int i = 0; i <= fullDaysNumber; i++)
        {
            if (timeExit.Day > timeArrived.Day)
            {
                dayMeals.AddFullDay();
                // A trick to make the cycle work the next time
                // You can use a different variable if you want to keep timeArrived unchanged
                timeArrived = timeArrived.AddDays(1);
            }
            else if (timeExit.Day < timeArrived.Day)
            {
                break;
            }
            else
            {
                dayMeals.CountMealsForADay(timeArrived, timeExit);
            }
        }
        dayMeals.PrintMealsCount();
    }
Example #2
0
        public IActionResult GetAll(int dayid)
        {
            try
            {
                DayMeals = dayMealData.GetRelated(dayid).ToList();

                if (!DayMeals.Any())
                {
                    return(NotFound());
                }
                DayMealDTOs = ApiRepository.DayMealsToDto(DayMeals);

                return(Ok(DayMealDTOs));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }