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

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

            return(new OkObjectResult(new BackendResult(true)));
        }
Exemplo n.º 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));
        }
        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));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddComment([FromHeader(Name = "x-meetup-tenant")] string tenant, [FromHeader(Name = "x-meetup-keyword")] string keyword, [FromBody] CalendarComment comment)
        {
            BackendResult result = await _meetUpFunctions.AddCommentToInfoItem(tenant, keyword, comment);

            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <BackendResult> RemoveCommentFromCalendarItem(string tenant, string keyword, CalendarComment comment)
        {
            BackendResult result = await $"https://{_functionsConfig.FunctionAppName}.azurewebsites.net/api/RemoveCommentFromCalendarItem"
                                   .WithHeader(HEADER_FUNCTIONS_KEY, _functionsConfig.ApiKey)
                                   .WithHeader(HEADER_KEYWORD, keyword)
                                   .WithHeader(HEADER_TENANT, tenant)
                                   .PostJsonAsync(comment)
                                   .ReceiveJson <BackendResult>();

            return(result);
        }