public IActionResult GetEvents()
        {
            var  headers = HttpContext.Request.Headers["user"];
            bool isAdmin = headers.Contains("admin");

            if (isAdmin)
            {
                var response = new EventsResponse();

                var evtsDbo = _context.Events.ToList();
                if (evtsDbo.Count > 0)
                {
                    // Do not load registration to reduce network traffic _context.Registrations.Load();

                    response.Data = new List <EventResponse>();

                    foreach (var evtDbo in evtsDbo)
                    {
                        response.Data.Add(CreateEventResponse(evtDbo));
                    }
                }
                // PostEvent
                response.AddHref(HrefType.POST, "api/events");

                return(Ok(response));
            }

            return(Unauthorized());
        }
        public IActionResult GetEvents(string key, Guid token)
        {
            Func <EventDbo, bool> comp = null;

            if (key == "event")
            {
                comp = a => a.EventToken == token;
            }
            else if (key == "series")
            {
                comp = a => a.SeriesToken == token;
            }
            if (comp != null)
            {
                var response = new EventsResponse {
                    Data = new List <EventResponse>()
                };

                var matches = _context.Events.Where(comp);
                foreach (EventDbo evtDbo in matches)
                {
                    var evtDto = CreateEventResponse(evtDbo);
                    response.Data.Add(evtDto);
                }

                // PostEvent
                response.AddHref(HrefType.POST, "api/events");

                return(Ok(response));
            }
            return(NotFound());
        }
        public IActionResult GetEventsByEventToken(Guid token)
        {
            var response = new EventsResponse();

            var matches = _context.Events.Where(a => a.EventToken == token);

            if (matches.Any())
            {
                response.Data = new List <EventResponse>();
                foreach (EventDbo evtDbo in matches)
                {
                    var evtDto = CreateEventResponse(evtDbo);
                    response.Data.Add(evtDto);
                }
            }

            // PostEvent
            response.AddHref(HrefType.POST, "api/events");

            return(Ok(response));
        }