public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function GetExportLog processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsAdmin(keyWord))
            {
                _logger.LogWarning("GetExportLog called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }


            IEnumerable <ExportLogItem> exportLog;

            if (null == tenant)
            {
                exportLog = await _cosmosRepository.GetItems(l => (l.Tenant ?? String.Empty) == String.Empty);
            }
            else
            {
                exportLog = await _cosmosRepository.GetItems(l => l.Tenant.Equals(tenant));
            }
            IEnumerable <ExportLogItem> orderedList = exportLog.OrderByDescending(l => l.RequestDate);

            return(new OkObjectResult(orderedList));
        }
Exemple #2
0
        public async Task <NotificationSubscription> WriteNotificationSubscription(NotificationSubscription subscription)
        {
            // Check if there is already a subscription
            NotificationSubscription storedSubscription = (await _cosmosDbRepository.GetItems(s => s.Url.Equals(subscription.Url))).FirstOrDefault();

            if (null != storedSubscription)
            {
                subscription.Id = storedSubscription.Id;
            }
            subscription.TimeToLive = Constants.SUBSCRIPTION_TTL;

            return(await _cosmosDbRepository.UpsertItem(subscription));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function CopyWeeklysToNextWeek processed a request.");

            // Get a list of all CalendarItems and filter all applicable ones
            DateTime compareDate = DateTime.Today;
            IEnumerable <CalendarItem> rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.StartDate > compareDate && d.StartDate < compareDate.AddHours(24.0) && d.Weekly && !d.IsCopiedToNextWeek);

            int counter = 0;

            foreach (CalendarItem cal in rawListOfCalendarItems)
            {
                ++counter;
                // First mark current item as processed
                cal.IsCopiedToNextWeek = true;
                await _cosmosRepository.UpsertItem(cal);

                // Create new item in next week
                cal.Id = null;
                cal.IsCopiedToNextWeek = false;
                cal.IsCanceled         = false;
                cal.StartDate          = cal.StartDate.AddDays(7.0);
                cal.PublishDate        = cal.PublishDate.AddDays(7.0);
                await _cosmosRepository.UpsertItem(cal);
            }

            return(new OkObjectResult(new BackendResult(true, $"Copied {counter} weeklys for today")));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetExtendedInfoItem/{id}")] HttpRequest req, string id)
        {
            _logger.LogInformation("C# HTTP trigger function GetExtendedInfoItem processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !(serverSettings.IsUser(keyWord)))
            {
                _logger.LogWarning("GetExtendedInfoItem called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            // Get CalendarItem by id
            InfoItem rawInfoItem = await _cosmosRepository.GetItem(id);

            if (null == rawInfoItem)
            {
                return(new BadRequestErrorMessageResult("No InfoItem with given id found."));
            }
            ExtendedInfoItem extendedItem = new ExtendedInfoItem(rawInfoItem);

            // Read all comments
            extendedItem.CommentsList = await _commentRepository.GetItems(c => c.CalendarItemId.Equals(extendedItem.Id));

            return(new OkObjectResult(extendedItem));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function GetAllExtendedCalendarItems processed a request.");
            string         tenant         = req.Headers[Constants.HEADER_TENANT];
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsAdmin(keyWord))
            {
                _logger.LogWarning("GetAllExtendedCalendarItems called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            // Get a list of all CalendarItems

            IEnumerable <CalendarItem> rawListOfCalendarItems = await _cosmosRepository.GetItems();

            List <ExtendedCalendarItem> resultCalendarItems = new List <ExtendedCalendarItem>(50);

            foreach (CalendarItem item in rawListOfCalendarItems)
            {
                ExtendedCalendarItem extendedItem = new ExtendedCalendarItem(item);
                resultCalendarItems.Add(extendedItem);
                // Read all participants for this calendar item
                extendedItem.ParticipantsList = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(extendedItem.Id));

                // Read all comments
                extendedItem.CommentsList = await _commentRepository.GetItems(c => c.CalendarItemId.Equals(extendedItem.Id));
            }
            IEnumerable <ExtendedCalendarItem> orderedList = resultCalendarItems.OrderBy(d => d.StartDate);

            return(new OkObjectResult(orderedList));
        }
Exemple #6
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function AddCommentToCalendarItem processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsUser(keyWord))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string          requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            CalendarComment comment     = JsonConvert.DeserializeObject <CalendarComment>(requestBody);

            // Get and check corresponding CalendarItem
            if (String.IsNullOrEmpty(comment.CalendarItemId))
            {
                return(new OkObjectResult(new BackendResult(false, "Terminangabe fehlt.")));
            }
            CalendarItem calendarItem = await _calendarRepository.GetItem(comment.CalendarItemId);

            if (null == calendarItem)
            {
                return(new OkObjectResult(new BackendResult(false, "Angegebenen Termin nicht gefunden.")));
            }
            ExtendedCalendarItem extendedCalendarItem = new ExtendedCalendarItem(calendarItem);

            // Read all participants for this calendar item
            extendedCalendarItem.ParticipantsList = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(extendedCalendarItem.Id));

            // Set TTL for comment the same as for CalendarItem
            System.TimeSpan diffTime = calendarItem.StartDate.Subtract(DateTime.Now);
            comment.TimeToLive = serverSettings.AutoDeleteAfterDays * 24 * 3600 + (int)diffTime.TotalSeconds;
            // Checkindate to track bookings
            comment.CommentDate = DateTime.Now;
            if (!String.IsNullOrWhiteSpace(tenant))
            {
                comment.Tenant = tenant;
            }

            comment = await _cosmosRepository.UpsertItem(comment);

            if (!String.IsNullOrEmpty(comment.Comment))
            {
                await _subscriptionRepository.NotifyParticipants(extendedCalendarItem, comment.AuthorFirstName, comment.AuthorLastName, comment.Comment);
            }

            BackendResult result = new BackendResult(true);

            return(new OkObjectResult(result));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function GetExtendedInfoItems processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsUser(keyWord))
            {
                _logger.LogWarning("GetExtendedInfoItems called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            IEnumerable <InfoItem> rawListOfInfoItems;

            if (null == tenant)
            {
                rawListOfInfoItems = await _cosmosRepository.GetItems(d => (d.Tenant ?? String.Empty) == String.Empty);
            }
            else
            {
                rawListOfInfoItems = await _cosmosRepository.GetItems(d => d.Tenant.Equals(tenant));
            }
            List <ExtendedInfoItem> resultInfoItems = new List <ExtendedInfoItem>(10);

            foreach (InfoItem item in rawListOfInfoItems)
            {
                // Create ExtendedInfoItem and get comments
                ExtendedInfoItem extendedItem = new ExtendedInfoItem(item);
                resultInfoItems.Add(extendedItem);
                // Read all comments
                extendedItem.CommentsList = await _commentRepository.GetItems(c => c.CalendarItemId.Equals(extendedItem.Id));
            }
            IEnumerable <ExtendedInfoItem> orderedList = resultInfoItems.OrderBy(d => d.OrderId);

            return(new OkObjectResult(orderedList));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function DeleteCalendarItem processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsUser(keyWord))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string       requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            CalendarItem calendarItem = JsonConvert.DeserializeObject <CalendarItem>(requestBody);

            if (String.IsNullOrEmpty(calendarItem.Id))
            {
                return(new OkObjectResult(new BackendResult(false, "Die Id des Kalendar-Eintrags fehlt.")));
            }
            await _cosmosRepository.DeleteItemAsync(calendarItem.Id);

            // Delete all participants
            IEnumerable <Participant> participants = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(calendarItem.Id));

            foreach (Participant p in participants)
            {
                await _participantRepository.DeleteItemAsync(p.Id);
            }

            // Delete all comments
            IEnumerable <CalendarComment> comments = await _commentRepository.GetItems(c => c.CalendarItemId.Equals(calendarItem.Id));

            foreach (CalendarComment c in comments)
            {
                await _commentRepository.DeleteItemAsync(c.Id);
            }

            return(new OkObjectResult(new BackendResult(true)));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function GetCalendarItems processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsUser(keyWord))
            {
                _logger.LogWarning("GetCalendarItems called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string privateKeywordsString = req.Query["privatekeywords"];

            string[] privateKeywords = null;
            if (!String.IsNullOrEmpty(privateKeywordsString))
            {
                privateKeywords = privateKeywordsString.Split(';');
            }

            // Get a list of all CalendarItems and filter all applicable ones
            DateTime compareDate = DateTime.Now.AddHours((-serverSettings.CalendarItemsPastWindowHours));

            IEnumerable <CalendarItem> rawListOfCalendarItems;

            if (null == tenant)
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.StartDate > compareDate && (d.Tenant ?? String.Empty) == String.Empty);
            }
            else
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.StartDate > compareDate && d.Tenant.Equals(tenant));
            }
            List <CalendarItem> resultCalendarItems = new List <CalendarItem>(10);

            foreach (CalendarItem item in rawListOfCalendarItems)
            {
                if (!serverSettings.IsAdmin(keyWord) && item.PublishDate.CompareTo(DateTime.UtcNow) > 0)
                {
                    // If calendar item is not ready for publishing skip it
                    continue;
                }
                if (String.IsNullOrEmpty(item.PrivateKeyword))
                {
                    // No private keyword for item ==> use it
                    resultCalendarItems.Add(item);
                }
                else if (null != privateKeywords)
                {
                    // Private keyword for item ==> check given keyword list against it
                    foreach (string keyword in privateKeywords)
                    {
                        if (keyword.Equals(item.PrivateKeyword))
                        {
                            resultCalendarItems.Add(item);
                            break;
                        }
                    }
                }
            }
            IEnumerable <CalendarItem> orderedList = resultCalendarItems.OrderBy(d => d.StartDate);

            return(new OkObjectResult(orderedList));
        }
Exemple #10
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function AddParticipantToCalendarItem processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !(serverSettings.IsUser(keyWord) || _serverSettingsRepository.IsInvitedGuest(keyWord)))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string      requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            Participant participant = JsonConvert.DeserializeObject <Participant>(requestBody);

            // Get and check corresponding CalendarItem
            if (String.IsNullOrEmpty(participant.CalendarItemId))
            {
                return(new OkObjectResult(new BackendResult(false, "Terminangabe fehlt.")));
            }
            CalendarItem calendarItem = await _calendarRepository.GetItem(participant.CalendarItemId);

            if (null == calendarItem)
            {
                return(new OkObjectResult(new BackendResult(false, "Angegebenen Termin nicht gefunden.")));
            }
            // Get participant list to check max registrations and if caller is already registered.
            IEnumerable <Participant> participants = await _cosmosRepository.GetItems(p => p.CalendarItemId.Equals(calendarItem.Id));

            int counter = calendarItem.WithoutHost ? 0 : 1;

            foreach (Participant p in participants)
            {
                if (p.ParticipantFirstName.Equals(participant.ParticipantFirstName) && p.ParticipantLastName.Equals(participant.ParticipantLastName))
                {
                    return(new OkObjectResult(new BackendResult(false, "Bereits registriert.")));
                }
                ++counter;
            }
            int maxRegistrationCount = calendarItem.MaxRegistrationsCount;

            if (serverSettings.IsAdmin(keyWord))
            {
                // Admin can "overbook" a meetup to be able to add some extra guests
                maxRegistrationCount *= Constants.ADMINOVERBOOKFACTOR;
            }
            if (counter >= maxRegistrationCount)
            {
                return(new OkObjectResult(new BackendResult(false, "Maximale Anzahl Registrierungen bereits erreicht.")));
            }
            // Set TTL for participant the same as for CalendarItem
            System.TimeSpan diffTime = calendarItem.StartDate.Subtract(DateTime.Now);
            participant.TimeToLive = serverSettings.AutoDeleteAfterDays * 24 * 3600 + (int)diffTime.TotalSeconds;
            // Checkindate to track bookings
            participant.CheckInDate = DateTime.Now;
            if (null != tenant)
            {
                participant.Tenant = tenant;
            }

            participant = await _cosmosRepository.UpsertItem(participant);

            BackendResult result = new BackendResult(true);

            return(new OkObjectResult(result));
        }
Exemple #11
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            string tenantBadge = null == tenant ? "default" : tenant;

            _logger.LogInformation($"GetScopedCalendarItems for tenant <{tenantBadge}>");
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string scope          = req.Query["scope"];
            string scopeToCompare = scope.ToLowerInvariant();

            if (String.IsNullOrEmpty(scope))
            {
                _logger.LogWarning($"GetScopedCalendarItems <{tenantBadge}> called without scope.");
                return(new BadRequestErrorMessageResult("scope is misssing.."));
            }
            _logger.LogInformation($"GetScopedCalendarItems<{tenantBadge}>(scope={scope})");

            // Get a list of all CalendarItems and filter all applicable ones
            DateTime compareDate = DateTime.Now.AddHours((-serverSettings.CalendarItemsPastWindowHours));
            IEnumerable <CalendarItem> rawListOfCalendarItems;

            if (null == tenant)
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.StartDate > compareDate && d.GuestScope != null && (d.Tenant ?? String.Empty) == String.Empty);
            }
            else
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.StartDate > compareDate && d.GuestScope != null && d.Tenant.Equals(tenant));
            }
            List <ExtendedCalendarItem> resultCalendarItems = new List <ExtendedCalendarItem>(10);

            foreach (CalendarItem item in rawListOfCalendarItems)
            {
                // Create ExtendedCalendarItem and get comments and participants
                ExtendedCalendarItem extendedItem = new ExtendedCalendarItem(item);
                if (extendedItem.PublishDate.CompareTo(DateTime.UtcNow) > 0)
                {
                    // If calendar item is not ready for publishing skip it
                    continue;
                }
                if (!extendedItem.GuestScope.ToLowerInvariant().Equals(scopeToCompare))
                {
                    continue;
                }
                resultCalendarItems.Add(extendedItem);
                // Read all participants for this calendar item
                extendedItem.ParticipantsList = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(extendedItem.Id));

                // Read all comments
                extendedItem.CommentsList = await _commentRepository.GetItems(c => c.CalendarItemId.Equals(extendedItem.Id));
            }
            IEnumerable <ExtendedCalendarItem> orderedList = resultCalendarItems.OrderBy(d => d.StartDate);

            return(new OkObjectResult(orderedList));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function WriteCalendarItem processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings;

            if (null == tenant)
            {
                serverSettings = await _serverSettingsRepository.GetServerSettings();
            }
            else
            {
                serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);
            }

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsUser(keyWord))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string       requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            CalendarItem calendarItem = JsonConvert.DeserializeObject <CalendarItem>(requestBody);

            System.TimeSpan diffTime = calendarItem.StartDate.Subtract(DateTime.Now);
            calendarItem.TimeToLive = serverSettings.AutoDeleteAfterDays * 24 * 3600 + (int)diffTime.TotalSeconds;
            if (null != tenant)
            {
                calendarItem.Tenant = tenant;
            }
            CalendarItem oldCalendarItem = null;

            if (!String.IsNullOrEmpty(calendarItem.Id))
            {
                oldCalendarItem = await _cosmosRepository.GetItem(calendarItem.Id);
            }
            calendarItem = await _cosmosRepository.UpsertItem(calendarItem);

            if (null != oldCalendarItem)
            {
                string message = null;
                // Compare versions and generate message
                if (oldCalendarItem.IsCanceled != calendarItem.IsCanceled)
                {
                    if (calendarItem.IsCanceled)
                    {
                        message = "Abgesagt!";
                    }
                    else
                    {
                        message = "Absage rückgängig gemacht!";
                    }
                }
                else if (!oldCalendarItem.StartDate.Equals(calendarItem.StartDate))
                {
                    message = "Neue Startzeit!";
                }
                else if (!oldCalendarItem.Title.Equals(calendarItem.Title))
                {
                    message = "Titel geändert;";
                }
                else if (!oldCalendarItem.Place.Equals(calendarItem.Place))
                {
                    message = "Startort geändert!";
                }
                else if (!oldCalendarItem.Summary.Equals(calendarItem.Summary))
                {
                    message = "Neue Infos!";
                }
                if (null != message)
                {
                    ExtendedCalendarItem extendedCalendarItem = new ExtendedCalendarItem(calendarItem);
                    // Read all participants for this calendar item
                    extendedCalendarItem.ParticipantsList = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(extendedCalendarItem.Id));

                    await _subscriptionRepository.NotifyParticipants(extendedCalendarItem, extendedCalendarItem.HostFirstName, extendedCalendarItem.HostLastName, message);
                }
            }

            return(new OkObjectResult(calendarItem));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function ExportTrackingReport processed a request.");
            string tenant = req.Headers[Constants.HEADER_TENANT];

            if (String.IsNullOrWhiteSpace(tenant))
            {
                tenant = null;
            }
            ServerSettings serverSettings = await _serverSettingsRepository.GetServerSettings(tenant);

            string keyWord = req.Headers[Constants.HEADER_KEYWORD];

            if (String.IsNullOrEmpty(keyWord) || !serverSettings.IsAdmin(keyWord))
            {
                _logger.LogWarning("ExportTrackingReport called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            TrackingReportRequest trackingRequest = JsonConvert.DeserializeObject <TrackingReportRequest>(requestBody);

            if (String.IsNullOrEmpty(trackingRequest.RequestorFirstName) || String.IsNullOrEmpty(trackingRequest.RequestorLastName))
            {
                _logger.LogWarning("ExportTrackingReport called without name of requestor.");
                return(new BadRequestErrorMessageResult("Requestor name missing."));
            }
            if (String.IsNullOrEmpty(trackingRequest.TrackFirstName) || String.IsNullOrEmpty(trackingRequest.TrackLastName))
            {
                _logger.LogWarning("ExportTrackingReport called without name of person to track.");
                return(new BadRequestErrorMessageResult("Track name missing."));
            }
            // Get a list of all CalendarItems
            IEnumerable <CalendarItem> rawListOfCalendarItems;

            if (null == tenant)
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => (d.Tenant ?? String.Empty) == String.Empty && !d.IsCanceled);
            }
            else
            {
                rawListOfCalendarItems = await _cosmosRepository.GetItems(d => d.Tenant.Equals(tenant) && !d.IsCanceled);
            }
            List <ExtendedCalendarItem> resultCalendarItems = new List <ExtendedCalendarItem>(50);

            // Filter the CalendarItems that are relevant
            foreach (CalendarItem item in rawListOfCalendarItems)
            {
                // Read all participants for this calendar item
                IEnumerable <Participant> participants = await _participantRepository.GetItems(p => p.CalendarItemId.Equals(item.Id));

                // Only events where the person was part of will be used.
                if (!item.WithoutHost && item.EqualsHost(trackingRequest.TrackFirstName, trackingRequest.TrackLastName) || null != participants.Find(trackingRequest.TrackFirstName, trackingRequest.TrackLastName))
                {
                    ExtendedCalendarItem extendedItem = new ExtendedCalendarItem(item);
                    extendedItem.ParticipantsList = participants;
                    resultCalendarItems.Add(extendedItem);
                }
            }
            IEnumerable <ExtendedCalendarItem> orderedList = resultCalendarItems.OrderBy(d => d.StartDate);
            // Build template for marker list corresponding to orderedList above
            List <CompanionCalendarInfo> relevantCalendarList = new List <CompanionCalendarInfo>(50);
            int calendarSize = 0;

            foreach (ExtendedCalendarItem e in orderedList)
            {
                relevantCalendarList.Add(new CompanionCalendarInfo(e));
                ++calendarSize;
            }

            // Assemble report
            TrackingReport report = new TrackingReport(trackingRequest);

            report.CompanionList = new List <Companion>(50);
            report.CalendarList  = relevantCalendarList;
            int calendarIndex = 0;

            foreach (ExtendedCalendarItem calendarItem in orderedList)
            {
                if (!calendarItem.WithoutHost)
                {
                    report.CompanionList.AddCompanion(calendarItem.HostFirstName, calendarItem.HostLastName, calendarItem.HostAdressInfo, calendarSize, calendarIndex);
                }
                foreach (Participant p in calendarItem.ParticipantsList)
                {
                    report.CompanionList.AddCompanion(p.ParticipantFirstName, p.ParticipantLastName, p.ParticipantAdressInfo, calendarSize, calendarIndex);
                }
                ++calendarIndex;
            }
            report.CreationDate = DateTime.Now;
            ExportLogItem log = new ExportLogItem(trackingRequest);

            log.TimeToLive = Constants.LOG_TTL;
            if (null != tenant)
            {
                log.Tenant = tenant;
            }
            await _logRepository.CreateItem(log);

            return(new OkObjectResult(report));
        }