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)); }
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 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))); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req) { _logger.LogInformation("GetServerSettings"); string tenant = req.Headers[Constants.HEADER_TENANT]; if (String.IsNullOrWhiteSpace(tenant)) { tenant = null; } TenantSettings tenantSettings; if (null == tenant) { tenantSettings = await _tenantRepository.GetFirstItemOrDefault(t => t.TenantKey == null); } else { tenantSettings = await _tenantRepository.GetFirstItemOrDefault(t => t.TenantKey.Equals(tenant)); } if (tenantSettings.LocalAdministrationDisabled) { return(new BadRequestErrorMessageResult("Administration in MeetUpPlanner is disabled.")); } ServerSettings serverSettings = await _cosmosRepository.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")); } return(new OkObjectResult(serverSettings)); }
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)); }
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 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 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)); }
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)); }
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 = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger CheckKeyword function 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]; KeywordCheck keywordCheck = new KeywordCheck(); if (!String.IsNullOrEmpty(keyword)) { keywordCheck.IsUser = keyword.Equals(serverSettings.UserKeyword); keywordCheck.IsAdmin = keyword.Equals(serverSettings.AdminKeyword); } if (keywordCheck.IsAdmin) { // Admin is user, too keywordCheck.IsUser = true; } return(new OkObjectResult(keywordCheck)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req) { _logger.LogInformation("C# HTTP trigger function NotificationSubscription 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(); NotificationSubscription notificationSubscription = JsonConvert.DeserializeObject <NotificationSubscription>(requestBody); if (null != tenant) { notificationSubscription.Tenant = tenant; } notificationSubscription = await _subscriptionRepository.WriteNotificationSubscription(notificationSubscription); return(new OkObjectResult(notificationSubscription)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req) { _logger.LogInformation("WriteServerSettings"); string tenant = req.Headers[Constants.HEADER_TENANT]; if (String.IsNullOrWhiteSpace(tenant)) { tenant = null; } TenantSettings tenantSettings; if (null == tenant) { tenantSettings = await _tenantRepository.GetFirstItemOrDefault(t => t.TenantKey == null); } else { tenantSettings = await _tenantRepository.GetFirstItemOrDefault(t => t.TenantKey.Equals(tenant)); } if (tenantSettings.LocalAdministrationDisabled) { return(new BadRequestErrorMessageResult("Administration in MeetUpPlanner is disabled.")); } ServerSettings 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(); ServerSettings newServerSettings = JsonConvert.DeserializeObject <ServerSettings>(requestBody); if (null != tenant) { newServerSettings.Tenant = tenant; } newServerSettings = await _serverSettingsRepository.WriteServerSettings(newServerSettings); return(new OkObjectResult(newServerSettings)); }
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 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, "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, "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)); }
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 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)); }
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, "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)); }