public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); // var functionName = "VilcapShareWithCom"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //When an item is created in Diligence and Selection: var em = check.Field <EmailItemField>(ids.GetFieldId("Diligence and Selection|Shared Email")); var m = "Please rate this application"; var email = em; var updateMe = new Item() { ItemId = check.ItemId }; updateMe.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Status")).OptionText = "Not Scored"; await podio.UpdateItem(updateMe, true); var serv = new GrantService(podio); //Send email var people = new List <Ref>(); var person = new Ref { Type = "mail", Id = email }; people.Add(person); var message = m; await serv.CreateGrant("item", check.ItemId, people, "rate", message); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapShareWithEnt"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //When an item is created in Entrepreneurs: var email = check.Field <EmailItemField>(ids.GetFieldId("Entrepreneurs|Entrepreneur Email")).Value.First().Value; var m = $"Please create an account and tell us about your time at {check.Field<AppItemField>(ids.GetFieldId("Entrepreneurs|Company")).Items.First().Title}"; var serv = new GrantService(podio); //Send email var people = new List <Ref>(); var person = new Ref { Type = "mail", Id = email }; people.Add(person); var message = m; await serv.CreateGrant("item", check.ItemId, people, "view", message); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); var functionName = "CreateSetAdminKey"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //When a new item in Admin is created: var updateMe = new Item() { ItemId = check.ItemId }; //Field to update: var searchKey = updateMe.Field <TextItemField>(ids.GetFieldId("Admin|Search Key")); searchKey.Value = "vilcapadmin"; await podio.UpdateItem(updateMe, true); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { #region >> Setup << var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); //Item item = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var item = await podio.GetItem(Convert.ToInt32("1131694213")); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); var saasyDocs = new SaasafrasGoogleDocsService(); var functionName = "VilcapApplicationPdf"; lockValue = await saasafrasClient.LockFunction(functionName, item.ItemId.ToString()); #endregion try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {item.ItemId}"); return; } // USING PDFSHARP //var exId = item.ExternalId; //context.Logger.LogLine($"--- Making PDFdoc for item with XID={exId}"); //var pdf = new PdfSharp.Pdf.PdfDocument(); //context.Logger.LogLine($"--- Created PDFdoc"); //var page = pdf.AddPage(); //context.Logger.LogLine($"--- Created PDFpage"); //var graphics = XGraphics.FromPdfPage(page); //context.Logger.LogLine($"--- Created Xgraphic"); ////var font = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 10.0f); Gets this far //var font = new System.Drawing.Font("Arial", 10.0f); //context.Logger.LogLine($"--- Created Font"); //var xfont = new XFont(font); //context.Logger.LogLine($"--- Created Xfont"); //graphics.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormat.Center); //context.Logger.LogLine($"--- Drew Something"); //var fileService = new PodioCore.Services.FileService(podio); //var attachment = await fileService.UploadFile(filename, pdf.AcroForm.Stream.Value, "application/pdf"); //item.Files.Add(attachment); // USING GDRIVE var document = new Document(); //document. // END CONTENT #region >> Closeout << } catch (Exception ex) { context.Logger.LogLine($"!!! Outer Exception: {ex.Message}"); throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, item.ItemId.ToString(), lockValue); } #endregion }
public async Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { string lockValue; var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); podio = factory.ForClient(e.clientId, e.environmentId); //context.Logger.LogLine("Getting Podio Instance"); check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); context.Logger.LogLine($"Got item with ID: {check.ItemId}"); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); //context.Logger.LogLine("Getting BBC Client Instance"); dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); //context.Logger.LogLine("Got dictionary"); var functionName = "newVilcapCopyFileToGoogleDrive"; var serviceAcccount = Environment.GetEnvironmentVariable("GOOGLE_SERVICE_ACCOUNT"); var cred = GoogleCredential.FromJson(serviceAcccount).CreateScoped(Scopes).UnderlyingCredential; service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = cred, ApplicationName = ApplicationName, }); //context.Logger.LogLine("Established google connection"); //context.Logger.LogLine($"App: {check.App.Name}"); google = new GoogleIntegration(); var saasGoogleIntegration = new SaasafrasGoogleIntegration(); pre = new PreSurvAndExp(); ids = new GetIds(dictChild, dictMaster, e.environmentId); var comm = new CommentService(podio); var s = new Survey(); // Main Process // var revision = await podio.GetRevisionDifference(Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision); var firstRevision = revision.First(); context.Logger.LogLine($"Last Revision field: {firstRevision.Label}"); var buttonPresser = check.CurrentRevision.CreatedBy; //context.Logger.LogLine($"Item updated by {buttonPresser.Name} (Should be 'Vilcap Admin')"); if (buttonPresser.Id.GetValueOrDefault() != 4610903) { context.Logger.LogLine("User ' https://podio.com/users/" + buttonPresser.Id + " ' is not authorized to perform this action."); return; } switch (firstRevision.Label) { case "WS Batch": #region // Create Workshops // var wsBatchId = ids.GetFieldId("Admin|WS Batch"); if (check.Field <CategoryItemField>(wsBatchId).Options.Any()) { context.Logger.LogLine($"Running 'WS Batch {check.Field<CategoryItemField>(wsBatchId).Options.First().Text}'"); var nextBatch = -1; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } context.Logger.LogLine($"Lock Value: {lockValue}"); var wm = new WorkshopModules2(); nextBatch = await wm.CreateWorkshopModules2(this); if (nextBatch > 1) { commentText = $"WS Batch {nextBatch - 1} Completed."; check.Field <CategoryItemField>(ids.GetFieldId("Admin|WS Batch")).OptionText = $"{nextBatch}"; await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); await comm.AddCommentToObject("item", check.ItemId, commentText, hook : true); //await podio.UpdateItem(check, hook: true); return; } else if (nextBatch == -1) { commentText = $":loudspeaker: All WS Batches Completed!"; await comm.AddCommentToObject("item", check.ItemId, commentText, hook : false); } } catch (Exception ex) { context.Logger.LogLine($"Exception Details: {ex} - {ex.Data} - {ex.HelpLink} - {ex.HResult} - {ex.InnerException} " + $"- {ex.Message} - {ex.Source} - {ex.StackTrace} - {ex.TargetSite}"); commentText = "Sorry, something went wrong. Please try again in 5 minutes or contact the administrator."; await comm.AddCommentToObject("item", check.ItemId, $":loudspeaker: {commentText}", hook : false); } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } } break; #endregion case "Deploy Addons": #region // Deploy Addon Modules // var aoBatchId = ids.GetFieldId("Admin|Deploy Addons"); if (check.Field <CategoryItemField>(aoBatchId).Options.Any()) { context.Logger.LogLine($"Running 'WS Batch {check.Field<CategoryItemField>(aoBatchId).Options.First().Text}'"); var nextBatch = -1; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } context.Logger.LogLine($"Lock Value: {lockValue}"); var ao = new Addons(); nextBatch = await ao.CreateAddons(context, podio, check, e, service, ids, google, pre); break; } catch (Exception ex) { context.Logger.LogLine($"Exception Details: {ex} - {ex.Data} - {ex.HelpLink} - {ex.HResult} - {ex.InnerException} " + $"- {ex.Message} - {ex.Source} - {ex.StackTrace} - {ex.TargetSite}"); commentText = "Sorry, something went wrong. Please try again in 5 minutes or contact the administrator."; await comm.AddCommentToObject("item", check.ItemId, $":loudspeaker: {commentText}", hook : false); } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } } break; #endregion //case "Deploy Task List": // var deploy = ids.GetFieldId("Admin|Deploy Task List"); // if (check.Field<CategoryItemField>(deploy).Options.Any()); // break; case "TL Batch": #region // Create Task List // var tlBatchId = ids.GetFieldId("Admin|TL Batch"); if (check.Field <CategoryItemField>(tlBatchId).Options.Any()) { context.Logger.LogLine($"Running 'TL Batch {check.Field<CategoryItemField>(tlBatchId).Options.First().Text}'"); var nextBatch = -1; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } context.Logger.LogLine($"Lock Value: {lockValue}"); var tl = new TaskList2(); nextBatch = await tl.CreateTaskLists(context, podio, check, e, service, ids, google, pre); if (nextBatch > 1) { commentText = $"TL Batch {nextBatch - 1} Completed."; check.Field <CategoryItemField>(ids.GetFieldId("Admin|TL Batch")).OptionText = $"{nextBatch}"; await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); await comm.AddCommentToObject("item", check.ItemId, commentText, hook : true); //await podio.UpdateItem(check, hook: true); return; } else if (nextBatch == -1) { commentText = $":loudspeaker: All TL Batches Completed!"; await comm.AddCommentToObject("item", check.ItemId, commentText, hook : false); } } catch (Exception ex) { context.Logger.LogLine($"Exception Details: {ex} - {ex.Data} - {ex.HelpLink} - {ex.HResult} - {ex.InnerException} " + $"- {ex.Message} - {ex.Source} - {ex.StackTrace} - {ex.TargetSite}"); commentText = "Sorry, something went wrong. Please try again in 5 minutes or contact the administrator."; await comm.AddCommentToObject("item", check.ItemId, $":loudspeaker: {commentText}", hook : false); } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } } break; #endregion default: context.Logger.LogLine($"NO ACTION: Value '{firstRevision.Label}' not Recognized."); break; } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapShareAppWithApplicant"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var fieldIdToSearch = ids.GetFieldId("Admin"); var newOptions = new FilterOptions { Limit = 1 }; context.Logger.LogLine("Checking for duplicates"); var items = await podio.FilterItems(ids.GetFieldId("Admin"), newOptions); var AdminOptionToCheck = await podio.GetItem(items.Items.First().ItemId); var serv = new GrantService(podio); //Create Email: var recipient = check.Field <EmailItemField>(ids.GetFieldId("Applications|Email")).Value.First().Value; var orgName = AdminOptionToCheck.Field <TextItemField>(ids.GetFieldId("Admin|Organization Name")).Value; var m = $"Invitation to Complete Your Application with {orgName}. " + "This application will automatically save as you work on it. You are advised " + "to either save your invitation email or bookmark your in-progress application for easy access. " + "You can view all of your Podio items by following the following link : <https://podio.com/vilcapcom/organization/grants>"; //Send email var email = recipient; var people = new List <Ref>(); var person = new Ref { Type = "mail", Id = email }; people.Add(person); var message = m; await serv.CreateGrant("item", check.ItemId, people, "view", message); var updateMe = new Item() { ItemId = check.ItemId }; updateMe.Field <CategoryItemField>(ids.GetFieldId("Applications|Application Status")).OptionText = "New Application"; await podio.UpdateItem(updateMe, true); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { //var awsClient = new Amazon.Lambda.AmazonLambdaClient(); //InvokeRequest request = new InvokeRequest { FunctionName = "FunctionHandler" }; //await awsClient.InvokeAsync(request); context.Logger.LogLine("---Recieved Routed Podio Event"); var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var saasafrasClient = new SaasafrasClient( Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY") ); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); var ids = new GetIds(dictChild, dictMaster, e.environmentId); //string functionName = "VilcapDateAssignTask"; var taskServ = new TaskService(podio); var itemServ = new ItemService(podio); var fieldIdToSearch = ids.GetFieldId("Task List|Date"); var filterValue = DateTime.Now.AddDays(7).Ticks; var viewServ = new ViewService(podio); context.Logger.LogLine("Got View Service ..."); var views = await viewServ.GetViews(22708289); var view = from v in views where v.Name == "[TaskAutomation]" select v; context.Logger.LogLine($"Got View '[TaskAutomation]' ..."); var op = new FilterOptions { Filters = view.First().Filters }; var filter = await podio.FilterItems(22708289, op); context.Logger.LogLine($"Items in filter:{filter.Items.Count()}"); foreach (var item in filter.Items) { var responsibleMember = item.Field <ContactItemField>(ids.GetFieldId("Task List|Responsible Member")); var title = item.Field <TextItemField>(ids.GetFieldId("Task List|Title")); var date = item.Field <DateItemField>(ids.GetFieldId("Task List|Date")); var description = item.Field <TextItemField>(ids.GetFieldId("Task List|Description")); var t = new TaskCreateUpdateRequest { Description = description.Value, Private = false, RefType = "item", Id = item.ItemId, DueDate = date.Start.GetValueOrDefault(), Text = title.Value }; IEnumerable <int> cIds = new List <int>(); foreach (var contact in responsibleMember.Contacts) { cIds.Append(Convert.ToInt32(contact.UserId)); } t.SetResponsible(cIds); //t.SetResponsible(cIds); var tasks = await taskServ.CreateTask(t); foreach (var task in tasks) { await taskServ.AssignTask(Convert.ToInt32(task.TaskId), task.Responsible.UserId); //neccessary? context.Logger.LogLine($"Assigned Task"); } var updateMe = new Item() { ItemId = item.ItemId }; var dupecheck = updateMe.Field <CategoryItemField>(ids.GetFieldId("Task List|Task Assigned?")); dupecheck.OptionText = "Yes"; await itemServ.UpdateItem(updateMe, hook : false); context.Logger.LogLine($"Updated Item"); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapShareWorkshopWithMentor"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //When an item is created in Entrepreneurs: var email = check.Field <EmailItemField>(ids.GetFieldId("Program Support|Email")).Value.First().Value; var serv = new GrantService(podio); //Send email var relationshipFieldId = ids.GetFieldId("Program Support|Workshop Sessions"); var relationshipField = check.Field <AppItemField>(relationshipFieldId); List <Item> items = (List <Item>)relationshipField.Items; var people = new List <Ref>(); var person = new Ref { Type = "mail", Id = email }; people.Add(person); if (items.Any() == false) { context.Logger.LogLine("No workshop session listed."); } foreach (var item in items) { var message = $"Event Attendance Confirmation: {item.Field<TextItemField>(ids.GetFieldId("Workshop Modules|Title")).Value}"; var itemId = item.ItemId; await serv.CreateGrant("item", item.ItemId, people, "view", message); } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(System.Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), System.Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapConfirmAppEmail"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); var complete = check.Field <CategoryItemField>(ids.GetFieldId("Applications|Complete This Application")); if (firstRevision.FieldId == complete.FieldId) { if (complete.Options.Any() && complete.Options.First().Text == "Submit") { var recipient = check.Field <EmailItemField>(ids.GetFieldId("Applications|Email")).Value.First().Value; //get admin item to get program manager name var items = await podio.FilterItems(ids.GetFieldId("Admin"), new FilterOptions() { Limit = 1 }); var adminItem = await podio.GetItem(items.Items.First().ItemId); var fromName = adminItem.Field <ContactItemField>(ids.GetFieldId("Admin|Program Manager")).Contacts.First().Name; //var subject = "Thank you for submitting your application!"; var messageBody = $"Thank you for submitting your application to {ids.GetLongName( $"{e.environmentId}-FN" )}'s Future of Work" + " and Learning Program 2019. We will be reviewing your application and following up in the " + "coming weeks regarding next steps. If you do have questions, please feel free to email me at " + "[[email protected]](mailto: [email protected])"; var comm = new CommentService(podio); await comm.AddCommentToObject("item", check.ItemId, messageBody); } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var submittedApplication = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapCreateCompanyProfile"; lockValue = await saasafrasClient.LockFunction(functionName, submittedApplication.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {submittedApplication.ItemId}"); return; } //When an item is updated in Applications: var revision = await podio.GetRevisionDifference ( Convert.ToInt32(submittedApplication.ItemId), submittedApplication.CurrentRevision.Revision - 1, submittedApplication.CurrentRevision.Revision ); var firstRevision = revision.First(); var completionStatus = submittedApplication.Field <CategoryItemField>(ids.GetFieldId("Applications|Complete This Application")); if (firstRevision.FieldId == completionStatus.FieldId) { if (completionStatus.Options.Any() && completionStatus.Options.First().Text == "Submit") { var companyProfile = new Item(); companyProfile.Field <CategoryItemField>(ids.GetFieldId("Company Profiles|Selection Process")).OptionText = "New Application"; companyProfile.Field <AppItemField>(ids.GetFieldId("Company Profiles|Application")).ItemId = submittedApplication.ItemId; #region >>> Copy Values >>> try { companyProfile.Field <LocationItemField>(ids.GetFieldId("Company Profiles|Location")).Values = submittedApplication.Field <LocationItemField>(ids.GetFieldId("Applications|Location")).Values; companyProfile.Field <PhoneItemField>(ids.GetFieldId("Company Profiles|Phone")).Values = submittedApplication.Field <PhoneItemField>(ids.GetFieldId("Applications|Phone")).Values; companyProfile.Field <EmailItemField>(ids.GetFieldId("Company Profiles|Email")).Values = submittedApplication.Field <EmailItemField>(ids.GetFieldId("Applications|Email")).Values; companyProfile.Field <DateItemField>(ids.GetFieldId("Company Profiles|Company Founding Date")).Values = submittedApplication.Field <DateItemField>(ids.GetFieldId("Applications|Company Founding Date ")).Values; companyProfile.Field <TextItemField>(ids.GetFieldId("Company Profiles|Twitter Handle")).Value = submittedApplication.Field <TextItemField>(ids.GetFieldId("Applications|Twitter Handle")).Value; // BECOMING OBSOLETE companyProfile.Field <TextItemField>(ids.GetFieldId("Company Profiles|LinkedIn Page")).Value = submittedApplication.Field <TextItemField>(ids.GetFieldId("Applications|LinkedIn Page")).Value; // BECOMING OBSOLETE companyProfile.Field <TextItemField>(ids.GetFieldId("Company Profiles|Facebook Page")).Value = submittedApplication.Field <TextItemField>(ids.GetFieldId("Applications|Facebook Page")).Value; // BECOMING OBSOLETE var embedField = companyProfile.Field <EmbedItemField>(ids.GetFieldId("Company Profiles|Website")); var website = submittedApplication.Field <EmbedItemField>(ids.GetFieldId("Applications|Website")).Embeds.FirstOrDefault().ResolvedUrl; website = submittedApplication.Field <EmbedItemField>(ids.GetFieldId("Applications|Company Website")) != null ? submittedApplication.Field <EmbedItemField>(ids.GetFieldId("Applications|Company Website")).Embeds.FirstOrDefault().ResolvedUrl : submittedApplication.Field <EmbedItemField>(ids.GetFieldId("Applications|Website")).Embeds.FirstOrDefault().ResolvedUrl; var em = new Embed { OriginalUrl = website }; embedField.Embeds.Append(em); } catch (Exception ex) { context.Logger.LogLine($"!!! Inner Exception: {ex.Message}"); throw ex; } #endregion await podio.CreateItem(companyProfile, ids.GetFieldId("Company Profiles"), true); } } } catch (Exception ex) { context.Logger.LogLine($"!!! Outer Exception: {ex.Message}"); throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, submittedApplication.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetFullItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); var functionName = "VilcapUpdateCompleteTasks"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); context.Logger.LogLine($"1"); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var serv = new TaskService(podio); var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); context.Logger.LogLine($"Checking Completion Status"); var completionStatus = check.Field <CategoryItemField>(ids.GetFieldId("Task List|Completetion")); context.Logger.LogLine("Checking to see if completion was the last field to be updated"); if (firstRevision.FieldId == completionStatus.FieldId) { context.Logger.LogLine("Checking to see if completion==Complete"); if (completionStatus.Options.Any() && completionStatus.Options.First().Text == "Complete") { //mark item tasks as complete var r = $"item:{check.ItemId}"; var ts = await serv.GetTasks(reference : r); context.Logger.LogLine($"Iterating thru {ts.Count()} task(s)"); foreach (var task in ts) { context.Logger.LogLine($"Attempting to complete task with ID: {task.TaskId}"); await serv.CompleteTask(int.Parse(task.TaskId), true, false); context.Logger.LogLine($"Completed task"); //send to podio? } } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Deploy Curriculum field var functionName = "VilcapCreateFinalSelCards"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //When an item is updated in Company Profiles and: var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); var selectionProcess = check.Field <CategoryItemField>(ids.GetFieldId("Company Profiles|Selection Process")); if (firstRevision.FieldId == selectionProcess.FieldId) { if (selectionProcess.Options.Any() && (selectionProcess.Options.First().Text == "Semi-Finalist" || selectionProcess.Options.First().Text == "Finalist")) { //Get view "Program Support": var viewServ = new ViewService(podio); var filterServ = new ItemService(podio); var selectionRound = ""; var viewName = ""; switch (selectionProcess.Options.First().Text) { case "Finalist": viewName = "Selection Committee - Final"; selectionRound = "Final Round"; break; case "Semi-Finalist": viewName = "Selection Committee - Semi Final"; selectionRound = "Semi-Final Round"; break; } var views = await viewServ.GetViews(ids.GetFieldId("Program Support")); var view = from v in views where v.Name == viewName select v; var viewItems = await filterServ.FilterItemsByView(ids.GetFieldId("Program Support"), int.Parse(view.First().ViewId), limit : 500); foreach (var item in viewItems.Items) { var create = new Item(); create.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Selection Round")).OptionText = selectionRound; create.Field <AppItemField>(ids.GetFieldId("Diligence and Selection|Company")).ItemId = check.ItemId; create.Field <AppItemField>(ids.GetFieldId("Diligence and Selection|Selection Comittee Member")).ItemId = item.ItemId; create.Field <EmailItemField>(ids.GetFieldId("Diligence and Selection|Shared Email")).Value = item.Field <EmailItemField>(ids.GetFieldId("Program Support|Email")).Value; var card = await podio.CreateItem(create, ids.GetFieldId("Diligence and Selection"), true); var serv = new GrantService(podio); //Create Email: var recipient = item.Field <EmailItemField>(ids.GetFieldId("Program Support|Email")).Value.FirstOrDefault().Value; var orgName = create.Field <TextItemField>(ids.GetFieldId("Diligence and Selection|Company")).Value; var m = $"Please Rate the {selectionRound} Company: {orgName}. \n" + "You can view all of your Podio items by at: <https://podio.com/vilcapcom/organization/grants>.\n " + "Please bookmark this link before changing your email notification settings."; //Send email var email = recipient; var people = new List <Ref>(); var person = new Ref { Type = "mail", Id = email }; people.Add(person); await serv.CreateGrant("item", check.ItemId, people, "rate", m); // await serv.CreateGrant("item", card, people, "rate", m); } } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); var functionName = "CreateSetResponsibleRole"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var fieldIdToSearch = ids.GetFieldId("Admin"); var newOptions = new FilterOptions { Limit = 1 }; context.Logger.LogLine("Checking for duplicates"); var items = await podio.FilterItems(ids.GetFieldId("Admin"), newOptions); var AdminOptionToCheck = await podio.GetItem(items.Items.First().ItemId); var CheckScheduleItem = check; var UpdateScheduleItem = new Item() { ItemId = check.ItemId }; var contactids = new List <int>(); var esoMemberRole = CheckScheduleItem.Field <CategoryItemField>(ids.GetFieldId("Task List|ESO Member Role")); if (esoMemberRole.Options.Any()) { var responsibleMember = UpdateScheduleItem.Field <ContactItemField>(ids.GetFieldId("Task List|Responsible Member")); var esoValue = esoMemberRole.Options.First().Text; switch (esoValue) { case "Programs Associate": var programAssociates = AdminOptionToCheck.Field <ContactItemField>(ids.GetFieldId("Admin|Program Associate")); foreach (var contact in programAssociates.Contacts) { contactids.Add(contact.ProfileId); } responsibleMember.ContactIds = contactids; break; case "Investment Analyst": var InvestmentsAnalysts = AdminOptionToCheck.Field <ContactItemField>(ids.GetFieldId("Admin|Investments Analyst")); foreach (var contact in InvestmentsAnalysts.Contacts) { contactids.Add(contact.ProfileId); } responsibleMember.ContactIds = contactids; break; case "Program Manager": var programManagers = AdminOptionToCheck.Field <ContactItemField>(ids.GetFieldId("Admin|Program Manager")); foreach (var contact in programManagers.Contacts) { contactids.Add(contact.ProfileId); } responsibleMember.ContactIds = contactids; break; case "Program Director": var programDirectors = AdminOptionToCheck.Field <ContactItemField>(ids.GetFieldId("Admin|Program Director")); foreach (var contact in programDirectors.Contacts) { contactids.Add(contact.ProfileId); } responsibleMember.ContactIds = contactids; break; } await podio.UpdateItem(UpdateScheduleItem, true); } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapSetNumericScore"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //when an item in diligence and selection is updated: var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); var selectionProcess = check.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Score")); if (firstRevision.FieldId == selectionProcess.FieldId) { var selectionRound = check.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Selection Round")).Options.First().Text; var semiFinalScore = ""; var finalScore = ""; var status = "Complete"; var updateMe = new Item() { ItemId = check.ItemId }; switch (selectionRound) { case "Semi-Final Round": semiFinalScore = check.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Score")).Options.First().Text; finalScore = null; updateMe.Field <NumericItemField>(ids.GetFieldId("Diligence and Selection|Score (Numeric) Semi-Final")).Value = int.Parse(semiFinalScore); updateMe.Field <NumericItemField>(ids.GetFieldId("Diligence and Selection|Score (Numeric) Final")).Status = null; break; case "Final Round": semiFinalScore = null; finalScore = check.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Score")).Options.First().Text; updateMe.Field <NumericItemField>(ids.GetFieldId("Diligence and Selection|Score (Numeric) Semi-Final")).Status = null; updateMe.Field <NumericItemField>(ids.GetFieldId("Diligence and Selection|Score (Numeric) Final")).Value = int.Parse(finalScore); break; } updateMe.Field <CategoryItemField>(ids.GetFieldId("Diligence and Selection|Status")).OptionText = status; await podio.UpdateItem(updateMe, true); } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapDependentTaskDate"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } // When an item is updated in Workshop Modules: var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); var date = check.Field <DateItemField>(ids.GetFieldId("Workshop Modules|Date")); if (firstRevision.FieldId == date.FieldId) { // Get Dep Tasks var depTasks = check.Field <AppItemField>(ids.GetFieldId("Workshop Modules|Dependent Task")); context.Logger.LogLine($"- # of Dep Tasks: {depTasks.Values.Count}"); var oldTime = revision.First().From.First.Value <DateTime>("start"); var diff = date.Start.Value.Subtract(oldTime); context.Logger.LogLine($"Oldtime: {oldTime} Offset: {diff}"); foreach (var depTask in depTasks.Items) { var updateMe = new Item(); context.Logger.LogLine($"- Iterating..."); updateMe = new Item() { ItemId = depTask.ItemId }; var taskDate = updateMe.Field <DateItemField>(ids.GetFieldId("Task List|Date")); var checkDate = updateMe.Field <DateItemField>(ids.GetFieldId("Task List|Date")); var duration = taskDate.End.GetValueOrDefault() - taskDate.Start.GetValueOrDefault(); if (duration.Ticks < 0) { duration = new TimeSpan(0); } context.Logger.LogLine($"Old Task Time: {taskDate.Start.GetValueOrDefault()} Old Task End: {taskDate.End.GetValueOrDefault()}"); taskDate.Start = checkDate.Start.GetValueOrDefault().Add(diff); taskDate.End = checkDate.Start.GetValueOrDefault().Add(diff + duration); context.Logger.LogLine($"New Task Time: {taskDate.Start.GetValueOrDefault()} New Task End: {taskDate.End.GetValueOrDefault()}"); await podio.UpdateItem(updateMe, true); context.Logger.LogLine($"New Task Time: {taskDate.Start.GetValueOrDefault()} New Task End: {taskDate.End.GetValueOrDefault()}"); } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
/// <summary> /// Company Profile|item.create --> /// Pull data from Application & Create Entrepreneurs /// </summary> public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); var functionName = "VilcapCreateSetDefaults"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } // On Creation of a Company Profile: #region >> Get referenced items from applications app >> var checkApp = new Item(); var itemRef = check.Field <AppItemField>(ids.GetFieldId("Company Profiles|Application")); var updateApp = new Item() { ItemId = itemRef.Items.First().ItemId }; updateApp.Field <CategoryItemField>(ids.GetFieldId("Applications|Application Status")).OptionText = "Company Profile Created"; await podio.UpdateItem(updateApp, true); #endregion checkApp = await podio.GetItem(itemRef.Items.First().ItemId); context.Logger.LogLine($"Item ID in foreach: {itemRef.Items.First().ItemId}"); context.Logger.LogLine($"Application Item ID: {checkApp.ItemId}"); var updateCompanyProfile = new Item() { ItemId = check.ItemId }; updateCompanyProfile.Field <PhoneItemField>(ids.GetFieldId("Company Profiles|Phone")).Value = checkApp.Field <PhoneItemField>(ids.GetFieldId("Applications|Phone")).Value; updateCompanyProfile.Field <EmailItemField>(ids.GetFieldId("Company Profiles|Email")).Value = checkApp.Field <EmailItemField>(ids.GetFieldId("Applications|Email")).Value; if (checkApp.Field <DateItemField>(ids.GetFieldId("Applications|Company Founding Date ")).Start != null) { updateCompanyProfile.Field <DateItemField>(ids.GetFieldId("Company Profiles|Company Founding Date")).Start = // BECOMING OBSOLETE checkApp.Field <DateItemField>(ids.GetFieldId("Applications|Company Founding Date ")).Start; // BECOMING OBSOLETE } else if (checkApp.Field <DateItemField>(ids.GetFieldId("Applications|Company Founding Date")).Start != null) { updateCompanyProfile.Field <DateItemField>(ids.GetFieldId("Company Profiles|Company Founding Date")).Start = checkApp.Field <DateItemField>(ids.GetFieldId("Applications|Company Founding Date")).Start; } var emails = checkApp.Field <EmailItemField>(ids.GetFieldId("Applications|Email")).Value; foreach (var email in emails) { var entrepreneur = new Item(); entrepreneur.Field <AppItemField>(ids.GetFieldId("Entrepreneurs|Company")).ItemId = check.ItemId; var emailList = new List <EmailPhoneFieldResult> { email }; entrepreneur.Field <EmailItemField>(ids.GetFieldId("Entrepreneurs|Entrepreneur Email")).Value = emailList; await podio.CreateItem(entrepreneur, ids.GetFieldId("Entrepreneurs"), true); } await podio.UpdateItem(updateCompanyProfile, true); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { const int ADMIN_ID = 4610903; var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "UpdateDeployCurriculum"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var revision = await podio.GetRevisionDifference(Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision); var firstRevision = revision.First(); if (check.CurrentRevision.CreatedBy.Id.GetValueOrDefault() != ADMIN_ID) { context.Logger.LogLine("User 'https://podio.com/users/" + check.CurrentRevision.CreatedBy.Id.GetValueOrDefault() + "' is not authorized to perform this action."); await new CommentService(podio).AddCommentToObject("item", check.ItemId, $":loudspeaker: User ' https://podio.com/users/" + check.CurrentRevision.CreatedBy.Id.GetValueOrDefault() + " ' is not authorized to perform this action.", hook: false); return; } switch (firstRevision.Label) { case "Deploy Task List": var deployField = check.Field <CategoryItemField>(ids.GetFieldId("Admin|Deploy Task List")); if (firstRevision.FieldId == deployField.FieldId && deployField.Options.Any() && deployField.Options.First().Text == "Deploy") { var update = new Item() { ItemId = check.ItemId }; var tlBatch = update.Field <CategoryItemField>(ids.GetFieldId("Admin|TL Batch")); tlBatch.OptionText = "1"; await podio.UpdateItem(update, true); } break; case "Deploy Curriculum": deployField = check.Field <CategoryItemField>(ids.GetFieldId("Admin|Deploy Curriculum")); if (firstRevision.FieldId == deployField.FieldId && deployField.Options.Any() && deployField.Options.First().Text == "Deploy") { var update = new Item() { ItemId = check.ItemId }; var wsBatch = update.Field <CategoryItemField>(ids.GetFieldId("Admin|WS Batch")); wsBatch.OptionText = "1"; await podio.UpdateItem(update, true); } break; } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapKickoffDateChanged"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var date = check.Field <DateItemField>(ids.GetFieldId("Workshop Modules|Date")); var calendarColor = check.Field <CategoryItemField>(ids.GetFieldId("Workshop Modules|Calendar Color")); var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); if (revision.First().Label == "Date" && calendarColor.Options.Any() && (calendarColor.Options.First().Text == "Date Manager" || calendarColor.Options.First().Text == "Addon Date Manager")) { context.Logger.LogLine($"Module Type: {calendarColor.Options.First().Text}"); context.Logger.LogLine($"JSON: {revision.First().From.ToString()}"); { var oldTime = revision.First().From.First.Value <DateTime>("start"); var diff = date.Start.Value.Subtract(oldTime); context.Logger.LogLine($"Got Values"); var fieldIdToSearch = ids.GetFieldId("Workshop Modules|Day #"); var filterValue = check.Field <CategoryItemField>(ids.GetFieldId("Workshop Modules|Day Number")).Options.First().Text; var filter = new Dictionary <int, object> { { fieldIdToSearch, filterValue } }; var newOptions = new FilterOptions { Filters = filter }; context.Logger.LogLine("Checking for duplicates"); var workshopAppId = ids.GetFieldId("Workshop Modules"); var items = await podio.FilterItems(workshopAppId, newOptions); context.Logger.LogLine("Got Items"); foreach (var item in items.Items) { var updateMe = new Item(); var checkCalendarColor = check.Field <CategoryItemField>(ids.GetFieldId("Workshop Modules|Calendar Color")); var foreachItemCalendarColor = item.Field <CategoryItemField>(ids.GetFieldId("Workshop Modules|Calendar Color")); if ( (checkCalendarColor.Options.Any() && checkCalendarColor.Options.First().Text == "Date Manager" && (!foreachItemCalendarColor.Options.Any() || foreachItemCalendarColor.Options.First().Text == "Module")) || (checkCalendarColor.Options.Any() && checkCalendarColor.Options.First().Text == "Addon Date Manager" && foreachItemCalendarColor.Options.Any() && foreachItemCalendarColor.Options.First().Text == "Addon") ) { updateMe = new Item() { ItemId = item.ItemId }; var updateDate = updateMe.Field <DateItemField>(ids.GetFieldId("Workshop Modules|Date")); var checkDate = item.Field <DateItemField>(ids.GetFieldId("Workshop Modules|Date")); var duration = item.Field <DurationItemField>(ids.GetFieldId("Workshop Modules|Duration")); updateDate.Start = checkDate.Start.Value.Add(diff); updateDate.End = checkDate.Start.Value.Add(diff + duration.Value.Value); } await podio.UpdateItem(updateMe, true); } } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapUpdateApplicationStatus"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } //when an item is updated im applications: var revision = await podio.GetRevisionDifference ( Convert.ToInt32(check.ItemId), check.CurrentRevision.Revision - 1, check.CurrentRevision.Revision ); var firstRevision = revision.First(); var completionStatus = check.Field <CategoryItemField>(ids.GetFieldId("Applications|Complete This Application")); if (firstRevision.FieldId == completionStatus.FieldId) { if (completionStatus.Options.Any() && completionStatus.Options.First().Text == "Submit") { var fieldIdToSearch = ids.GetFieldId("Admin"); var newOptions = new FilterOptions { Limit = 1 }; context.Logger.LogLine("Checking for duplicates"); var items = await podio.FilterItems(ids.GetFieldId("Admin"), newOptions); var AdminOptionToCheck = await podio.GetItem(items.Items.First().ItemId); //assign tasks: var taskServ = new TaskService(podio); var programAssociates = AdminOptionToCheck.Field <ContactItemField>(ids.GetFieldId("Admin|Programs Associate")); var title = "Review Completed Application for " + $"{check.Field<TextItemField>(ids.GetFieldId("Applications|Company Name")).Value} here: {check.Link}"; var date = DateTime.Now.AddDays(5); var t = new TaskCreateUpdateRequest { Description = title, Text = "Details", Private = false }; var cId = 0; var random = new Random(); var assignedTo = programAssociates.Contacts.ToArray()[random.Next(programAssociates.Contacts.Count())]; context.Logger.LogLine($"Adding Contact: {assignedTo.Mail.First()} with userID: {assignedTo.UserId}"); cId = Convert.ToInt32(assignedTo.UserId); t.Private = true; // foreach (var contact in programAssociates.Contacts) //{ // context.Logger.LogLine($"Adding Contact: {contact.Mail.First()} with userID: {contact.UserId}"); // cId=Convert.ToInt32(contact.UserId); //} t.RefType = "item"; t.Id = check.ItemId; t.SetResponsible(cId); t.DueDate = date; var task = await taskServ.CreateTask(t, silent : false); context.Logger.LogLine($"Created task: {task.First().TaskId}"); await taskServ.AssignTask(int.Parse(task.First().TaskId), cId, true);//neccessary? context.Logger.LogLine($"Assigned task: {task.First().TaskId} to userID: {cId}"); } } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.environmentId); //Make sure to implement by checking to see if Deploy Curriculum has just changed //Deploy Curriculum field var functionName = "VilcapShareDocument"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } var serv = new GrantService(podio); var people = new List <Ref>(); var entrepreneurs = check.Field <AppItemField>(ids.GetFieldId("Cohort Documents|Entreprenuers")); context.Logger.LogLine($"--- count: {entrepreneurs.Items.Count()}"); foreach (var entrepreneur in entrepreneurs.Items) { var item = await podio.GetItem(entrepreneur.ItemId); var fieldId = ids.GetFieldId("Entrepreneurs|Entrepreneur Email"); var emailField = item.Field <EmailItemField>(fieldId); var email = emailField.Value.FirstOrDefault().Value; var person = new Ref { Type = "mail", Id = email }; people.Add(person); context.Logger.LogLine($"--- Added Email: {email}"); } var description = check.Field <TextItemField>(ids.GetFieldId("Cohort Documents|Docment Desciption")).Value; var message = $"Thank you for sending us your documents {description}. Please follow this link to view your submission."; await serv.CreateGrant("item", check.ItemId, people, "view", message); context.Logger.LogLine("--- Created grant(s)"); if (string.IsNullOrEmpty(description)) { var docName = check.Files[0].Name; var updateMe = new Item() { ItemId = check.ItemId }; description = updateMe.Field <TextItemField>(ids.GetFieldId("Cohort Documents|Docment Desciption")).Value; await podio.UpdateItem(updateMe, true); } context.Logger.LogLine("--- ok"); } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedPodioEvent e, ILambdaContext context) { var factory = new AuditedPodioClientFactory(e.solutionId, e.version, e.clientId, e.environmentId); var podio = factory.ForClient(e.clientId, e.environmentId); var item = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.environmentId, e.solutionId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); var ids = new GetIds(dictChild, dictMaster, e.environmentId); //GoogleIntegration google = new GoogleIntegration(); var drive = new DriveService(); var embedServ = new EmbedService(podio); var functionName = "VilcapCreateWorkbook"; var lockValue = await saasafrasClient.LockFunction(functionName, item.ItemId.ToString()); try { if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {item.ItemId}"); return; } var revision = await podio.GetRevisionDifference ( Convert.ToInt32(item.ItemId), item.CurrentRevision.Revision - 1, item.CurrentRevision.Revision ); var firstRevision = revision.First(); var materials = item.Field <AppItemField>(ids.GetFieldId("Content")); var pages = new List <File>(); var workbook = new File(); foreach (var material in materials.Items) { var matEmbed = material.Field <EmbedItemField>(ids.GetFieldId("Materials|Link to Material")); foreach (var embed in matEmbed.Embeds) { //pages.Add(google.GetOneFile(drive, embed, e)); } } foreach (var page in pages) { //page. //workbook. } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, item.ItemId.ToString(), lockValue); } }
public async System.Threading.Tasks.Task FunctionHandler(RoutedCommentEvent e, ILambdaContext context) { #region //Required code for all Vilcap Lambda Functions// context.Logger.LogLine(Newtonsoft.Json.JsonConvert.SerializeObject(e)); context.Logger.LogLine(Newtonsoft.Json.JsonConvert.SerializeObject(e)); var factory = new AuditedPodioClientFactory(e.appId, e.version, e.clientId, e.currentEnvironment.environmentId); var podio = factory.ForClient(e.clientId, e.currentEnvironment.environmentId); var check = await podio.GetItem(Convert.ToInt32(e.podioEvent.item_id)); var saasafrasClient = new SaasafrasClient(Environment.GetEnvironmentVariable("BBC_SERVICE_URL"), Environment.GetEnvironmentVariable("BBC_SERVICE_API_KEY")); var dictChild = await saasafrasClient.GetDictionary(e.clientId, e.currentEnvironment.environmentId, e.appId, e.version); var dictMaster = await saasafrasClient.GetDictionary("vcadministration", "vcadministration", "vilcap", "0.0"); string lockValue; var ids = new GetIds(dictChild, dictMaster, e.currentEnvironment.environmentId); var functionName = "CommentNextBatch"; lockValue = await saasafrasClient.LockFunction(functionName, check.ItemId.ToString()); #endregion try { #region //Locker// if (string.IsNullOrEmpty(lockValue)) { context.Logger.LogLine($"Failed to acquire lock for {functionName} and id {check.ItemId}"); return; } #endregion var serve = new CommentService(podio); var commentToCheck = await serve.GetComment(int.Parse(e.podioEvent.comment_id)); var fieldId = 0; var commentPieces = commentToCheck.Value.Split(" "); var type = commentPieces[0]; var batch = commentPieces[2]; var isNum = Regex.IsMatch(batch, @"^\d+$"); var updateMe = new Item() { ItemId = check.ItemId }; int currentBatch; if (isNum) { try { int.TryParse(batch, out currentBatch); context.Logger.LogLine($"Current batch: {currentBatch}"); } catch (Exception ex) { context.Logger.LogLine("It seems batch number could not be found"); throw ex; } switch (type) { case "WS": #region //update WS Batch number// context.Logger.LogLine("Type==WS"); context.Logger.LogLine("Getting Field ID"); fieldId = ids.GetFieldId("Admin|WS Batch"); context.Logger.LogLine($"Field ID: {fieldId}"); var wsBatchField = updateMe.Field <CategoryItemField>(fieldId); context.Logger.LogLine("Got Field"); context.Logger.LogLine("Adding 1 to current batch"); wsBatchField.OptionText = (++currentBatch).ToString(); context.Logger.LogLine($"New Batch Value: {currentBatch}"); break; #endregion case "TL": #region //update TL Batch number// context.Logger.LogLine("Type==TL"); context.Logger.LogLine("Getting Field ID"); fieldId = ids.GetFieldId("Admin|TL Batch"); context.Logger.LogLine($"Field ID: {fieldId}"); var tlBatchField = updateMe.Field <CategoryItemField>(fieldId); context.Logger.LogLine("Got Field"); context.Logger.LogLine("Adding 1 to current batch"); tlBatchField.OptionText = (++currentBatch).ToString(); context.Logger.LogLine($"New Batch Value: {currentBatch}"); break; #endregion } context.Logger.LogLine($"Field count on item we're updating: {updateMe.Fields.Count()}"); await podio.UpdateItem(updateMe, true); } } catch (Exception ex) { throw ex; } finally { await saasafrasClient.UnlockFunction(functionName, check.ItemId.ToString(), lockValue); } }