示例#1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation($"C# HTTP trigger function RemoveParticipantFromCalendarItem 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);

            if (String.IsNullOrEmpty(participant.Id))
            {
                return(new OkObjectResult(new BackendResult(false, "Die Id des Teilnehmers fehlt.")));
            }
            await _cosmosRepository.DeleteItemAsync(participant.Id);

            return(new OkObjectResult(new BackendResult(true)));
        }
示例#2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetExtendedCalendarItem/{id}")] HttpRequest req, string id)
        {
            _logger.LogInformation("C# HTTP trigger function GetExtendedCalendarItem 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)))
            {
                _logger.LogWarning("GetExtendedCalendarItem called with wrong keyword.");
                return(new BadRequestErrorMessageResult("Keyword is missing or wrong."));
            }
            // Get CalendarItem by id
            CalendarItem rawCalendarItem = await _cosmosRepository.GetItem(id);

            if (null == rawCalendarItem)
            {
                return(new BadRequestErrorMessageResult("No CalendarItem with given id found."));
            }
            ExtendedCalendarItem extendedItem = new ExtendedCalendarItem(rawCalendarItem);

            // 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));

            return(new OkObjectResult(extendedItem));
        }
示例#3
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));
        }