コード例 #1
0
        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")));
        }
コード例 #2
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));
        }
コード例 #3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function AssignNewHostToCalendarItem 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();
            Participant participant = JsonConvert.DeserializeObject <Participant>(requestBody);

            // Check if participant has an id
            if (String.IsNullOrEmpty(participant.Id))
            {
                return(new OkObjectResult(new BackendResult(false, "Id des Teilnehmers fehlt.")));
            }
            if (String.IsNullOrEmpty(participant.ParticipantFirstName) || String.IsNullOrEmpty(participant.ParticipantLastName))
            {
                return(new OkObjectResult(new BackendResult(false, "Name unvollständig.")));
            }
            // 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.")));
            }
            // Assign participant as new host
            calendarItem.HostFirstName  = participant.ParticipantFirstName;
            calendarItem.HostLastName   = participant.ParticipantLastName;
            calendarItem.HostAdressInfo = participant.ParticipantAdressInfo;
            calendarItem.WithoutHost    = false;
            // Set TTL and write CalendarItem to database
            System.TimeSpan diffTime = calendarItem.StartDate.Subtract(DateTime.Now);
            calendarItem.TimeToLive = serverSettings.AutoDeleteAfterDays * 24 * 3600 + (int)diffTime.TotalSeconds;
            calendarItem            = await _calendarRepository.UpsertItem(calendarItem);

            // Delete host as participant
            await _cosmosRepository.DeleteItemAsync(participant.Id);

            BackendResult result = new BackendResult(true);

            return(new OkObjectResult(result));
        }
コード例 #4
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));
        }
コード例 #5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function AddCommentToInfoItem 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.")));
            }
            InfoItem infoItem = await _infoRepository.GetItem(comment.CalendarItemId);

            if (null == infoItem)
            {
                return(new OkObjectResult(new BackendResult(false, "Angegebenen Termin nicht gefunden.")));
            }
            if (!infoItem.CommentsAllowed)
            {
                return(new OkObjectResult(new BackendResult(false, "Keine Kommentare hier erlaubt.")));
            }
            if (infoItem.CommentsLifeTimeInDays > 0)
            {
                comment.TimeToLive = infoItem.CommentsLifeTimeInDays * 24 * 3600;
            }
            comment.CommentDate = DateTime.Now;
            if (!String.IsNullOrWhiteSpace(tenant))
            {
                comment.Tenant = tenant;
            }
            comment = await _cosmosRepository.UpsertItem(comment);

            BackendResult result = new BackendResult(true);

            return(new OkObjectResult(result));
        }
コード例 #6
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function WriteInfoItem 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.IsAdmin(keyWord))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string   requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            InfoItem infoItem    = JsonConvert.DeserializeObject <InfoItem>(requestBody);

            if (infoItem.InfoLifeTimeInDays > 0)
            {
                infoItem.TimeToLive = infoItem.InfoLifeTimeInDays * 24 * 3600;
            }
            if (null != tenant)
            {
                infoItem.Tenant = tenant;
            }
            infoItem = await _cosmosRepository.UpsertItem(infoItem);

            return(new OkObjectResult(infoItem));
        }
コード例 #7
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function WriteClientSettings 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.AdminKeyword.Equals(keyWord))
            {
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            string         requestBody    = await new StreamReader(req.Body).ReadToEndAsync();
            ClientSettings clientSettings = JsonConvert.DeserializeObject <ClientSettings>(requestBody);

            clientSettings.LogicalKey = Constants.KEY_CLIENT_SETTINGS;
            if (null != tenant)
            {
                clientSettings.LogicalKey += "-" + tenant;
                clientSettings.Tenant      = tenant;
            }
            clientSettings = await _cosmosRepository.UpsertItem(clientSettings);

            return(new OkObjectResult(clientSettings));
        }
コード例 #8
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));
        }
コード例 #9
0
        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));
        }