Ejemplo n.º 1
0
        public async Task <IActionResult> Agenda(string datestart = null)
        {
            DateTime DateStart;

            if (String.IsNullOrWhiteSpace(datestart) || !DateTime.TryParse(datestart, out DateStart) || DateStart == DateTime.MinValue)
            {
                DateStart = DateTime.Now;
            }

            try
            {
                List <AgendaResponse> agendaResponses = new List <AgendaResponse>();
                for (int i = 0; i <= 7; i++)
                {
                    agendaResponses.Add(new AgendaResponse()
                    {
                        Date   = DateStart.AddDays(i),
                        Wod    = await _wodService.GetWodByDate(DateStart.AddDays(i)),
                        IsRest = await _restdayService.IsRestDay(DateStart.AddDays(i))
                    });
                }

                agendaResponses = agendaResponses.OrderBy(x => x.Date).ToList();
                return(Ok(agendaResponses));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Agenda error: {ex.Message} - Date: {DateStart.ToLongDateString()}");
                return(BadRequest());
            }
        }