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, "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 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)); }
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)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetCalendarItem/{id}")] HttpRequest req, string id) { _logger.LogInformation($"C# HTTP trigger function GetCalendarItem/{id} 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.")); } CalendarItem item = await _cosmosRepository.GetItem(id); return(new OkObjectResult(item)); }
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)); }
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)); }