Esempio n. 1
0
        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);
            }
        }
        //creates ehome dictionary item
        public override async System.Threading.Tasks.Task InnerHandler(RoutedPodioEvent e, ILambdaContext lambda_ctx)
        {
            lambda_ctx.Logger.LogLine($"Lambda_ctx: {lambda_ctx.Identity}");
            System.Environment.SetEnvironmentVariable("PODIO_PROXY_URL", Config.PODIO_PROXY_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_URL", Config.BBC_SERVICE_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_API_KEY", Config.BBC_SERVICE_API_KEY);

            string url          = Config.LOCKER_URL;
            string key          = Config.BBC_SERVICE_API_KEY;
            var    functionName = "mpactproEhomeCreateDictItemFunction";
            var    uniqueId     = e.podioEvent.type; //this is using the ehome id for now since we dont have a unique item id
            var    client       = new BbcServiceClient(url, key);
            var    lockValue    = await client.LockFunction(functionName, uniqueId);

            if (string.IsNullOrEmpty(lockValue))
            {
                lambda_ctx.Logger.LogLine($"Failed to acquire lock for {functionName} and id {uniqueId}");
                return;
            }
            try
            {
                var factory     = new AuditedPodioClientFactory(e.appId, e.version, e.clientId, e.currentEnvironment.environmentId);
                var podioClient = factory.Client();

                //eHome landing dictionary
                EhomeDictionary dict = new EhomeDictionary();
                _deployedSpacesEhome = dict.Dictionary;
                var  ehomeId   = e.podioEvent.type; //TODO: update if key gets assigned to a new property
                var  appId     = 20806986;          //will always be the same
                Item ehomeItem = new Item();

                void setField(string fieldName, string fieldValue)
                {
                    var fieldId       = GetFieldIdEhome($"*eHome America Landing Space|eHome America Profile Dictionary|{fieldName}");
                    var textItemField = ehomeItem.Field <TextItemField>(fieldId);

                    textItemField.Value = fieldValue;
                }

                setField("Client ID", e.clientId);
                setField("Environment ID", e.currentEnvironment.environmentId);
                setField("eHome Profile ID", ehomeId);

                await podioClient.CreateItem(ehomeItem, appId, true);

                lambda_ctx.Logger.LogLine("eHome dict item has ben created!");
            }
            catch (Exception ex)
            {
                lambda_ctx.Logger.LogLine($"The function {functionName} failed");
                lambda_ctx.Logger.LogLine($"Exception: {ex}");
            }
            finally
            {
                await client.UnlockFunction(functionName, uniqueId, lockValue);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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");
            }
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
        public override async System.Threading.Tasks.Task InnerHandler(RoutedPodioEvent e, ILambdaContext lambda_ctx)
        {
            lambda_ctx.Logger.LogLine("EHome Data Status = Push 2");
            lambda_ctx.Logger.LogLine($"Podio Routed Event Version and AppId: {e.version}, {e.appId}");
            lambda_ctx.Logger.LogLine($"Lambda_ctx: {lambda_ctx.Identity}");
            System.Environment.SetEnvironmentVariable("PODIO_PROXY_URL", Config.PODIO_PROXY_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_URL", Config.BBC_SERVICE_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_API_KEY", Config.BBC_SERVICE_API_KEY);

            string url  = Config.LOCKER_URL;
            string url2 = Config.BBC_SERVICE_URL;
            string key  = Config.BBC_SERVICE_API_KEY;
            // eHome Landing Dictionary
            EhomeDictionary dict = new EhomeDictionary();

            _deployedSpacesEhome = dict.Dictionary;
            // Authenticate
            if (e.appId != null)
            {
                lambda_ctx.Logger.LogLine($"AppId: |{e.appId}|");
            }
            if (e.version != null)
            {
                lambda_ctx.Logger.LogLine($"Version: |{e.version}|");
            }
            if (e.clientId != null)
            {
                lambda_ctx.Logger.LogLine($"clientId |{e.clientId}|");
            }
            var app         = "mpactprobeta";
            var version     = "3.0";
            var level       = "admin";
            var factory     = new AuditedPodioClientFactory(app, version, level, level);
            var podioClient = factory.Client();

            // Get revision from Podio update
            var revision = await podioClient.GetRevisionDifference(Convert.ToInt32(e.podioEvent.item_id), e.currentItem.CurrentRevision.Revision - 1, e.currentItem.CurrentRevision.Revision);

            var fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|eHome Data Status");

            // If eHome Data Status was updated to Push 2
            if (e.currentItem.Field <CategoryItemField>(fieldId).Options.First().Text == "Push 2" && revision.First().FieldId == fieldId)
            {
                var functionName = "mpactproEhomeAmericaInboundPush2Function";
                var uniqueId     = e.currentItem.ItemId.ToString();
                var client       = new BbcServiceClient(url, key);
                var lockValue    = await client.LockFunction(functionName, uniqueId);

                try
                {
                    if (string.IsNullOrEmpty(lockValue))
                    {
                        lambda_ctx.Logger.LogLine($"Failed to acquire lock for {functionName} and id {uniqueId}");
                        return;
                    }
                    lambda_ctx.Logger.LogLine($"Lock Value: {lockValue}");

                    var appId = GetFieldIdEhome("*eHome America Landing Space|eHome America Profile Dictionary");
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Podio ID");

                    // Search eHome America Profile Dictionary for client's Podio ID
                    var searchService = new PodioCore.Services.SearchService(podioClient);
                    var eHomeProfileDictionarySearch = await searchService.SearchInApp(appId, e.currentItem.Field <TextItemField>(fieldId).Value);

                    // Get item from eHome Dictionary
                    var ehomeProfileDictionaryGetItem = await podioClient.GetItem(eHomeProfileDictionarySearch.First().Id);

                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Profile Dictionary|Environment ID");
                    var envId = ehomeProfileDictionaryGetItem.Field <TextItemField>(fieldId).Value;
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Profile Dictionary|Client ID");
                    var clientId = ehomeProfileDictionaryGetItem.Field <TextItemField>(fieldId).Value;
                    lambda_ctx.Logger.LogLine($"clientId: {clientId}");
                    lambda_ctx.Logger.LogLine($"envId: {envId}");

                    // Create service and Get deployments
                    lambda_ctx.Logger.LogLine($"Url: {url2}");

                    var bbcservice = new BbcServiceClient(url2, key);
                    var envs       = await bbcservice.GetEnvironment(clientId, envId);

                    //var deployments = await bbcservice.GetDeployments(clientId, envId);//, "mpactprobeta");
                    var deployment = envs.deployments.First(); // TODO: find better way of getting app than first()
                    _deployedSpaces = deployment.deployedSpaces;

                    // Creation of eHome America Lead && setting all of the fields !
                    lambda_ctx.Logger.LogLine($"Creating eHome Item");
                    var ehomeItem = new Item();

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Are you a Veteran?");
                    var catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Veteran");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Yes")
                    {
                        catField.OptionText = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "No")
                    {
                        catField.OptionText = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }
                    else
                    {
                        catField.OptionText = "Not Available";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Are you active Military?");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Active Military");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Yes")
                    {
                        catField.OptionText = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "No")
                    {
                        catField.OptionText = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }
                    else
                    {
                        catField.OptionText = "Not Available";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|English Proficiency Level");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|English Speaking");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Household is Limited English Proficient")
                    {
                        catField.OptionText = "a. Household is Limited English Proficient";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Household is not Limited English Proficient")
                    {
                        catField.OptionText = "b . Household is not Limited English Proficient";
                    }
                    else
                    {
                        catField.OptionText = "c. Chose not to respond";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Current Household");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Current Household Type");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Rent")
                    {
                        catField.OptionText = "1.  Rent";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Homeless")
                    {
                        catField.OptionText = "2.  Homeless";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Not Paying Rent")
                    {
                        catField.OptionText = "4.  Not Paying Rent";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Homeowner with Mortage Paid Off")
                    {
                        catField.OptionText = "5.  Homeowner with Mortage Paid Off";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Disability");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Disability");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Yes")
                    {
                        catField.OptionText = "Yes";
                    }
                    else
                    {
                        catField.OptionText = "No";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Ethnicity");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Ethnicity");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Hispanic")
                    {
                        catField.OptionText = "a.  Hispanic";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Not Hispanic")
                    {
                        catField.OptionText = "b.  Not Hispanic";
                    }
                    else
                    {
                        catField.OptionText = "c.  Chose not to respond";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Gender");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Gender");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Male")
                    {
                        catField.OptionText = "Male";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Female")
                    {
                        catField.OptionText = "Female";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Have you met with a lender about getting a home loan?");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Met Lender");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Yes")
                    {
                        catField.OptionText = "Yes";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "No")
                    {
                        catField.OptionText = "No";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Highest Level of Education");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Highest Level of Education");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Below High School Diploma")
                    {
                        catField.OptionText = "1. Below High School Diploma";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "High School Diploma or Equivalent")
                    {
                        catField.OptionText = "2. High School Diploma or Equivalent";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Two-Year College")
                    {
                        catField.OptionText = "3. Two-Year College";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Bachelors Degree")
                    {
                        catField.OptionText = "4. Bachelors Degree";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Masters Degree")
                    {
                        catField.OptionText = "5. Masters Degree";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Above Masters Degree")
                    {
                        catField.OptionText = "6. Above Masters Degree";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Household Type");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Household Type");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Female headed single parent household")
                    {
                        catField.OptionText = "1. Female headed single parent household";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Male headed single parent household")
                    {
                        catField.OptionText = "2. Male headed single parent household";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Single adult")
                    {
                        catField.OptionText = "3. Single adult";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Two or more unrelated adults")
                    {
                        catField.OptionText = "4. Two or more unrelated adults";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Married with children")
                    {
                        catField.OptionText = "5. Married with children";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Married without children")
                    {
                        catField.OptionText = "6. Married without children";
                    }
                    else
                    {
                        catField.OptionText = "7. Other";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Marital Status");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Marital Status");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value == "Single")
                    {
                        catField.OptionText = "Single";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Married")
                    {
                        catField.OptionText = "Married";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Divorced")
                    {
                        catField.OptionText = "Divorced";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Separated")
                    {
                        catField.OptionText = "Separated";
                    }
                    else if (e.currentItem.Field <TextItemField>(fieldId).Value == "Widowed")
                    {
                        catField.OptionText = "Widowed";
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Race");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Race");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "American Indian/Alaskan Native":
                        catField.OptionText = "a. American Indian/Alaskan Native";
                        break;

                    case "Asian":
                        catField.OptionText = "b. Asian";
                        break;

                    case "Black or African American":
                        catField.OptionText = "c. Black or African American";
                        break;

                    case "Native Hawaiian or Other Pacific Islander":
                        catField.OptionText = "d. Native Hawaiian or Other Pacific Islander";
                        break;

                    case "White":
                        catField.OptionText = "e. White";
                        break;

                    case "American Indian or Alaska Native and White":
                        catField.OptionText = "f. American Indian or Alaska Native and White";
                        break;

                    case "Asian and White":
                        catField.OptionText = "g. Asian and White";
                        break;

                    case "Black or African American and White":
                        catField.OptionText = "h. Black or African American and White";
                        break;

                    case "American Indian or Alaska Native and Black or African American":
                        catField.OptionText = "i. American Indian or Alaska Native and Black or African American";
                        break;

                    case "Other multiple race":
                    case "Other":
                        catField.OptionText = "j. Other multiple race";
                        break;

                    default:
                        catField.OptionText = "k. Chose not to respond";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|U.S. Citizen");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|U.S. Citizen");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "Yes":
                        catField.OptionText = "4 - Myself and parents and grandparents were all born inside US";
                        break;

                    case "No":
                        catField.OptionText = "3 - I was born outside the US";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|I am taking this course to:");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Course Reason");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "Meet my lender's qualifications":
                        catField.OptionText = "Meet my lender's qualifications";
                        break;

                    case "Become more educated about the homebuying process":
                        catField.OptionText = "Become more educated about the homebuying process";
                        break;

                    case "Determing if owning a home is the right decision":
                        catField.OptionText = "Determing if owning a home is the right decision";
                        break;

                    case "Learn how much I can spend on purchasing a home":
                        catField.OptionText = "Learn how much I can spend on purchasing a home";
                        break;

                    default:
                        catField.OptionText = "Meet my lender's qualifications";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Loan Type");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Rural Area Status");
                    var ruralStatus = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Education Client Type");
                    var educationClientType = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Loan Type");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "Conventional":
                        catField.OptionText            = "Conventional";
                        ruralStatus.OptionText         = "a. Household lives in a rural area";
                        educationClientType.OptionText = "Facilitated Education";
                        break;

                    case "FHA":
                        catField.OptionText            = "FHA";
                        ruralStatus.OptionText         = "a. Household lives in a rural area";
                        educationClientType.OptionText = "Facilitated Education";
                        break;

                    case "USDA":
                        catField.OptionText            = "USDA";
                        ruralStatus.OptionText         = "b. Household does not live in a rural area";
                        educationClientType.OptionText = "USDA Follow-Up";
                        break;

                    case "Neighborhood Stabilization Program (NSP)":
                        catField.OptionText            = "Neighborhood Stabilization Program (NSP)";
                        ruralStatus.OptionText         = "a. Household lives in a rural area";
                        educationClientType.OptionText = "Facilitated Education";
                        break;

                    case "Down Payment Assistance":
                        catField.OptionText            = "Down Payment Assistance";
                        ruralStatus.OptionText         = "a. Household lives in a rural area";
                        educationClientType.OptionText = "Facilitated Education";
                        break;

                    default:
                        catField.OptionText            = "Other";
                        ruralStatus.OptionText         = "a. Household lives in a rural area";
                        educationClientType.OptionText = "Facilitated Education";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|How did you hear about eHome America?");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Hear About eHome");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "Advertisement":
                        catField.OptionText = "Advertisement";
                        break;

                    case "Housing Counseling Agency":
                        catField.OptionText = "Housing Counseling Agency";
                        break;

                    case "Lender":
                        catField.OptionText = "Lender";
                        break;

                    case "Real Estate Professional":
                        catField.OptionText = "Real Estate Professional";
                        break;

                    case "Website":
                        catField.OptionText = "Website";
                        break;

                    case "Word of Mouth":
                        catField.OptionText = "Word of Mouth";
                        break;

                    case "Zillow":
                        catField.OptionText = "Zillow";
                        break;

                    case "Downpaymentresource.com":
                        catField.OptionText = "Downpaymentresource.com";
                        break;

                    default:
                        catField.OptionText = "Other";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Are you a First-Time Homebuyer?");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|First Time Homebuyer");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "No":
                        catField.OptionText = "No";
                        break;

                    default:
                        catField.OptionText = "Yes";
                        break;
                    }

                    fieldId  = GetFieldId("3. Home Purchase|eHome America Lead|Have you been pre-approved for a loan up to a certain amount?");
                    catField = ehomeItem.Field <CategoryItemField>(fieldId);
                    fieldId  = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Approved Loan");
                    switch (e.currentItem.Field <TextItemField>(fieldId).Value)
                    {
                    case "Yes":
                        catField.OptionText = "Yes";
                        break;

                    default:
                        catField.OptionText = "No";
                        break;
                    }

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Phone");
                    var phoneItemField = ehomeItem.Field <PhoneItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client Phone Number");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        phoneItemField.Value = new List <EmailPhoneFieldResult>
                        {
                            new EmailPhoneFieldResult {
                                Type = "other", Value = e.currentItem.Field <TextItemField>(fieldId).Value
                            }
                        };
                    }

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Total Annual Family Income");
                    var numericItemField = ehomeItem.Field <NumericItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Total Annual Family Income");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        var income = e.currentItem.Field <TextItemField>(fieldId).Value.Replace(",", "");
                        income = StripHTML(income);
                        numericItemField.Value = Convert.ToDouble(income);
                    }

                    fieldId          = GetFieldId("3. Home Purchase|eHome America Lead|Number in Household");
                    numericItemField = ehomeItem.Field <NumericItemField>(fieldId);
                    fieldId          = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Number in Household");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        var income = e.currentItem.Field <TextItemField>(fieldId).Value.Replace(",", "");
                        income = StripHTML(income);
                        numericItemField.Value = Convert.ToDouble(income);
                    }

                    fieldId          = GetFieldId("3. Home Purchase|eHome America Lead|If you have been pre-approved, how much were you pre-approved for?");
                    numericItemField = ehomeItem.Field <NumericItemField>(fieldId);
                    fieldId          = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Approved Loan Amount");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        var income = e.currentItem.Field <TextItemField>(fieldId).Value.Replace(",", "");
                        income = StripHTML(income);
                        numericItemField.Value = Convert.ToDouble(income);
                    }

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Date of Birth");
                    var dateItemField = ehomeItem.Field <DateItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Date of Birth");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        var date      = StripHTML(e.currentItem.Field <TextItemField>(fieldId).Value);
                        var dateSplit = date.Split('-');
                        if (dateSplit[0].Count() < 2)
                        {
                            dateSplit[0] = 0 + dateSplit[0];
                        }
                        dateItemField.Start = Convert.ToDateTime(dateSplit[2] + "-" + dateSplit[0] + "-" + dateSplit[1]);
                    }

                    fieldId             = GetFieldId("3. Home Purchase|eHome America Lead|Create Home Purchase Case");
                    catField            = ehomeItem.Field <CategoryItemField>(fieldId);
                    catField.OptionText = "No";

                    fieldId             = GetFieldId("3. Home Purchase|eHome America Lead|Completed");
                    catField            = ehomeItem.Field <CategoryItemField>(fieldId);
                    catField.OptionText = "New";

                    fieldId             = GetFieldId("3. Home Purchase|eHome America Lead|Are you a First-Time Homebuyer?");
                    catField            = ehomeItem.Field <CategoryItemField>(fieldId);
                    catField.OptionText = "No";

                    fieldId             = GetFieldId("3. Home Purchase|eHome America Lead|Completed eHome Course?");
                    catField            = ehomeItem.Field <CategoryItemField>(fieldId);
                    catField.OptionText = "Registration";

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Legal First Name");
                    var textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client First Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Legal Last Name");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client Last Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Street Number");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Street Number");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Street Name");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Street Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|State");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|State");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|County");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|County");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|City");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|City");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Zip Code");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Zip");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|eHome Profile ID");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|eHome Profile ID");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Lender Name");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Lender Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId   = GetFieldId("3. Home Purchase|eHome America Lead|Loan Officer's Name");
                    textField = ehomeItem.Field <TextItemField>(fieldId);
                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Loan Officer Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value;
                    }

                    fieldId        = GetFieldId("3. Home Purchase|eHome America Lead|Loan Officer's Phone Number");
                    phoneItemField = ehomeItem.Field <PhoneItemField>(fieldId);
                    fieldId        = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Loan Officer Phone Number");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        phoneItemField.Value = new List <EmailPhoneFieldResult>
                        {
                            new EmailPhoneFieldResult {
                                Type = "other", Value = StripHTML(e.currentItem.Field <TextItemField>(fieldId).Value)
                            }
                        };
                    }

                    fieldId        = GetFieldId("3. Home Purchase|eHome America Lead|Loan Officer's Fax Number");
                    phoneItemField = ehomeItem.Field <PhoneItemField>(fieldId);
                    fieldId        = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Loan Officer Fax Number");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        phoneItemField.Value = new List <EmailPhoneFieldResult>
                        {
                            new EmailPhoneFieldResult {
                                Type = "other", Value = StripHTML(e.currentItem.Field <TextItemField>(fieldId).Value)
                            }
                        };
                    }

                    fieldId          = GetFieldId("3. Home Purchase|eHome America Lead|Household Family Size");
                    numericItemField = ehomeItem.Field <NumericItemField>(fieldId);
                    fieldId          = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Number in Household");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        numericItemField.Value = Convert.ToDouble(StripHTML(e.currentItem.Field <TextItemField>(fieldId).Value));
                    }

                    fieldId = GetFieldId("3. Home Purchase|eHome America Lead|Email Address");
                    var emailItemField = ehomeItem.Field <EmailItemField>(fieldId);
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client Email Address");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null)
                    {
                        emailItemField.Value = new List <EmailPhoneFieldResult>
                        {
                            new EmailPhoneFieldResult {
                                Type = "other", Value = e.currentItem.Field <TextItemField>(fieldId).Value
                            }
                        };
                    }

                    appId = GetFieldId("3. Home Purchase|eHome America Lead");
                    var itemId = await podioClient.CreateItem(ehomeItem, appId, false);

                    lambda_ctx.Logger.LogLine($"eHome item: {itemId} has been created :)");

                    var landingSpace = new Item {
                        ItemId = e.currentItem.ItemId
                    };

                    fieldId         = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Local Item ID");
                    textField       = landingSpace.Field <TextItemField>(fieldId);
                    textField.Value = itemId.ToString();

                    fieldId             = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Local Item Status");
                    catField            = landingSpace.Field <CategoryItemField>(fieldId);
                    catField.OptionText = "Item Created";

                    await podioClient.UpdateItem(landingSpace, true);

                    lambda_ctx.Logger.LogLine($"Local Item ID has been set");
                }
                catch (Exception ex)
                {
                    lambda_ctx.Logger.LogLine($"{ex}");
                    var errorItem = new Item();

                    fieldId = GetFieldIdEhome("*eHome America Landing Space|Error Log|Error Log");
                    var textField = errorItem.Field <TextItemField>(fieldId);
                    textField.Value = ex.Message.ToString();

                    fieldId   = GetFieldIdEhome("*eHome America Landing Space|Error Log|Client Name");
                    textField = errorItem.Field <TextItemField>(fieldId);
                    var clientFirstNameFieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client First Name");
                    fieldId = GetFieldIdEhome("*eHome America Landing Space|eHome America Landing Space|Client Last Name");
                    if (e.currentItem.Field <TextItemField>(fieldId).Value != null && e.currentItem.Field <TextItemField>(clientFirstNameFieldId).Value != null)
                    {
                        textField.Value = e.currentItem.Field <TextItemField>(fieldId).Value + ", " + e.currentItem.Field <TextItemField>(clientFirstNameFieldId).Value;
                    }

                    var appId = GetFieldIdEhome("*eHome America Landing Space|Error Log");
                    await podioClient.CreateItem(errorItem, appId, true);
                }
                finally
                {
                    await client.UnlockFunction(functionName, uniqueId, lockValue);
                }
            }
            else
            {
                lambda_ctx.Logger.LogLine("Failed if statement");
            }
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        public override async System.Threading.Tasks.Task InnerHandler(RoutedPodioEvent e, ILambdaContext lambda_ctx)
        {
            System.Environment.SetEnvironmentVariable("PODIO_PROXY_URL", Config.PODIO_PROXY_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_URL", Config.BBC_SERVICE_URL);
            System.Environment.SetEnvironmentVariable("BBC_SERVICE_API_KEY", Config.BBC_SERVICE_API_KEY);

            _deployedSpaces = e.currentEnvironment.deployments.First(a => a.appId == "mpactprobeta").deployedSpaces;
            var factory     = new AuditedPodioClientFactory(e.appId, e.version, e.clientId, e.currentEnvironment.environmentId);
            var podioClient = factory.ForClient(e.clientId, e.currentEnvironment.environmentId);

            lambda_ctx.Logger.LogLine($"Podio Routed Event Version and AppId: {e.version}, {e.appId}");
            lambda_ctx.Logger.LogLine($"Lambda_ctx: {lambda_ctx.Identity}");

            string url = Config.LOCKER_URL;
            string key = Config.BBC_SERVICE_API_KEY;

            lambda_ctx.Logger.LogLine($"URL: {url}");
            var functionName = "mpactproAMICalcFunction";
            var uniqueId     = e.currentItem.ItemId.ToString();
            var client       = new BbcServiceClient(url, key);
            var lockValue    = await client.LockFunction(functionName, uniqueId);

            if (string.IsNullOrEmpty(lockValue))
            {
                lambda_ctx.Logger.LogLine($"Failed to acquire lock for {functionName} and id {uniqueId}");
                return;
            }
            try
            {
                var  app  = e.currentItem.App.Name; //Podio App Name
                Item item = new Item {
                    ItemId = e.currentItem.ItemId
                };
                double?incomeLimit = 0;
                var    householdIncomeBandField = e.currentItem.Field <CategoryItemField>(0);
                var    incomeLevel    = e.currentItem.Field <CategoryItemField>(0);
                var    incomeCategory = e.currentItem.Field <CategoryItemField>(0);
                var    size           = e.currentItem.Field <NumericItemField>(0);
                var    ami            = e.currentItem.Field <NumericItemField>(0);
                var    income         = e.currentItem.Field <MoneyItemField>(0);

                var fieldId   = 0;
                var workspace = "";
                lambda_ctx.Logger.LogLine("Checking for app");
                lambda_ctx.Logger.LogLine($"App: {app}");

                if (app == "Intake")
                {
                    lambda_ctx.Logger.LogLine("App is Intake");
                    var items = await podioClient.GetReferringItems(e.currentItem.ItemId);

                    lambda_ctx.Logger.LogLine($"Referring Items: {items.Count()}");
                    e.currentItem = await podioClient.GetItem(items.First().Items.First().ItemId);

                    item = new Item {
                        ItemId = e.currentItem.ItemId
                    };
                    lambda_ctx.Logger.LogLine($"Found MCP with item ID: {item.ItemId}");
                    fieldId = GetFieldId("1. Client Profile|Master Client Profile|Household Income Band");
                    householdIncomeBandField = item.Field <CategoryItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Income Levels");
                    incomeLevel = item.Field <CategoryItemField>(fieldId);
                    workspace   = "1. Client Profile|Master Client Profile";
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Household Size");
                    size        = e.currentItem.Field <NumericItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Annual Family or Household Income");
                    income      = e.currentItem.Field <MoneyItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|County 100% Income Limit (AMI)");
                    ami         = e.currentItem.Field <NumericItemField>(fieldId);
                }
                if (app == "Master Client Profile")
                {
                    fieldId = GetFieldId("1. Client Profile|Master Client Profile|Household Income Band");
                    householdIncomeBandField = item.Field <CategoryItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Income Levels");
                    incomeLevel = item.Field <CategoryItemField>(fieldId);
                    workspace   = "1. Client Profile|Master Client Profile";
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Household Size");
                    size        = e.currentItem.Field <NumericItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|Annual Family or Household Income");
                    income      = e.currentItem.Field <MoneyItemField>(fieldId);
                    fieldId     = GetFieldId("1. Client Profile|Master Client Profile|County 100% Income Limit (AMI)");
                    ami         = e.currentItem.Field <NumericItemField>(fieldId);
                }

                else if (app == "Home Purchase Case")
                {
                    fieldId = GetFieldId("3. Home Purchase|Home Purchase Case|Household Income Band");
                    householdIncomeBandField = item.Field <CategoryItemField>(fieldId);
                    workspace = "3. Home Purchase|Home Purchase Case";
                    fieldId   = GetFieldId("3. Home Purchase|Home Purchase Case|Household Family Size");
                    size      = e.currentItem.Field <NumericItemField>(fieldId);
                    fieldId   = GetFieldId("3. Home Purchase|Home Purchase Case|Household Annual Family Income");
                    income    = e.currentItem.Field <MoneyItemField>(fieldId);
                    fieldId   = GetFieldId("3. Home Purchase|Home Purchase Case|County 100% Income Limit (AMI)");
                    ami       = e.currentItem.Field <NumericItemField>(fieldId);
                }

                else if (app == "Homeowner Services Case")
                {
                    fieldId = GetFieldId("7. Home Owner Services|Homeowner Services Case|Household Income Band");
                    householdIncomeBandField = item.Field <CategoryItemField>(fieldId);
                    workspace = "7. Home Owner Services|Homeowner Services Case";
                    fieldId   = GetFieldId("7. Home Owner Services|Homeowner Services Case|Household Family Size");
                    size      = e.currentItem.Field <NumericItemField>(fieldId);
                    fieldId   = GetFieldId("7. Home Owner Services|Homeowner Services Case|Household Annual Family Income");
                    income    = e.currentItem.Field <MoneyItemField>(fieldId);
                    fieldId   = GetFieldId("7. Home Owner Services|Homeowner Services Case|County 100% Income Limit (AMI)");
                    ami       = e.currentItem.Field <NumericItemField>(fieldId);
                }

                else if (app == "Mortgage Modification Case")
                {
                    fieldId = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|Household Income Band");
                    householdIncomeBandField = item.Field <CategoryItemField>(fieldId);
                    fieldId        = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|Income Level");
                    incomeLevel    = item.Field <CategoryItemField>(fieldId);
                    fieldId        = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|Income Category");
                    incomeCategory = item.Field <CategoryItemField>(fieldId);
                    workspace      = "4. Mortgage Modification|Mortgage Modification Case";
                    fieldId        = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|Household Family Size");
                    size           = e.currentItem.Field <NumericItemField>(fieldId);
                    fieldId        = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|Household Annual Family Income");
                    income         = e.currentItem.Field <MoneyItemField>(fieldId);
                    fieldId        = GetFieldId("4. Mortgage Modification|Mortgage Modification Case|County 100% Income Limit (AMI)");
                    ami            = e.currentItem.Field <NumericItemField>(fieldId);
                }

                lambda_ctx.Logger.LogLine($"Destination {workspace}");
                lambda_ctx.Logger.LogLine("If Statement Starting");

                if (ami.Value != null && size.Value != null && income.Value != null)
                {
                    if (e.currentItem.Revisions != null)
                    {
                        var revision = await podioClient.GetRevisionDifference(Convert.ToInt32(e.currentItem.ItemId), e.currentItem.CurrentRevision.Revision - 1, e.currentItem.CurrentRevision.Revision);

                        lambda_ctx.Logger.LogLine("Passed if statement");
                        if (revision.Count > 0 && revision.First().FieldId != ami.FieldId && revision.First().FieldId != size.FieldId && revision.First().FieldId != income.FieldId)
                        {
                            return;
                        }
                    }
                }
                lambda_ctx.Logger.LogLine("Calculating incomeLimit");
                lambda_ctx.Logger.LogLine($"AMI: {ami.Value}");
                lambda_ctx.Logger.LogLine($"Size: {size.Value}");
                lambda_ctx.Logger.LogLine($"Income: {income.Value}");
                if (size.Value > 0)
                {
                    var medianIncome = ami.Value / 2;

                    if (size.Value > 4)
                    {
                        var overNumber = size.Value - 4;
                        var overOffSet = overNumber * 0.08;
                        var offSet     = medianIncome * (1 + overOffSet);
                        ami.Value   = offSet * 2;
                        incomeLimit = Convert.ToDouble(income.Value) / ami.Value;
                    }
                    else if (size.Value < 4)
                    {
                        var underNumber = size.Value - 4;
                        var underOffSet = underNumber * 0.1;
                        var offSet      = medianIncome * (1 + underOffSet);
                        ami.Value   = offSet * 2;
                        incomeLimit = incomeLimit = Convert.ToDouble(income.Value) / ami.Value;
                    }
                    else if (size.Value == 4)
                    {
                        incomeLimit = incomeLimit = Convert.ToDouble(income.Value) / ami.Value;
                    }
                }

                //gets household income band to set and income limit based on app name
                lambda_ctx.Logger.LogLine($"calculated value: {incomeLimit}");
                //sets household income band based on income limit
                lambda_ctx.Logger.LogLine("Setting values");
                if (incomeLimit < .5)
                {
                    incomeCategory.OptionText = "A - Less than 50% of AMI";
                }

                if (incomeLimit > 0 && incomeLimit < .3)
                {
                    householdIncomeBandField.OptionText = "1. Below 30% of AMI";
                    incomeLevel.OptionText = "a. < 30% of Area Median Income (AMI)";
                }
                else if (incomeLimit >= .3 && incomeLimit < .5)
                {
                    householdIncomeBandField.OptionText = "2. 30% - 49% of AMI";
                    incomeLevel.OptionText = "b . 30 - 49% of AMI";
                }
                else if (incomeLimit >= .5 && incomeLimit < .8)
                {
                    householdIncomeBandField.OptionText = "3. 50% - 79% of AMI";
                    incomeLevel.OptionText    = "c. 50 - 79% of AMI";
                    incomeCategory.OptionText = "B - 50%-79% AMI";
                }
                else if (incomeLimit >= .8 && incomeLimit <= 1)
                {
                    householdIncomeBandField.OptionText = "4. 80% - 100% of AMI";
                    incomeLevel.OptionText    = "d. 80 - 100% of AMI";
                    incomeCategory.OptionText = "C - 80-100% AMI";
                }
                else if (incomeLimit > 1)
                {
                    householdIncomeBandField.OptionText = "5. 101% - 120% of AMI";
                    incomeLevel.OptionText    = "e. > 100% AMI";
                    incomeCategory.OptionText = "D - Greater than 100% AMI";
                }
                else
                {
                    householdIncomeBandField.OptionText = "f. Chose not to respond";
                    incomeLevel.OptionText = "f. Chose not to respond";
                }
                await podioClient.UpdateItem(item, false);
            }
            catch (Exception ex)
            {
                lambda_ctx.Logger.LogLine($"Exception: {ex}");
            }
            finally
            {
                await client.UnlockFunction(functionName, uniqueId, lockValue);
            }
        }
Esempio n. 18
0
        /// <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);
            }
        }
Esempio n. 19
0
        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);
            }
        }
Esempio n. 20
0
        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);
            }
        }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
        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);
            }
        }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
        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);
            }
        }