protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: GetNextProjectRequestNumber", DateTime.Now.ToLongTimeString()); //Get Project field var projectToCreate = new caps_Project(); var projectId = service.Create(projectToCreate); //get project Id Microsoft.Xrm.Sdk.Query.ColumnSet columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("caps_projectcode"); var projectRecord = service.Retrieve(caps_Project.EntityLogicalName, projectId, columns) as caps_Project; var projectNumber = projectRecord.caps_ProjectCode; tracingService.Trace("Project Number:{0}", projectNumber); projectRequestNumber.Set(executionContext, projectNumber); //delete project service.Delete(caps_Project.EntityLogicalName, projectId); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: ValidateProjectRequest", DateTime.Now.ToLongTimeString()); var recordId = context.PrimaryEntityId; tracingService.Trace("{0}", "Loading data"); //get Project Request var projectRequest = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true)) as caps_Project; //get Submission Category var submissionCategory = service.Retrieve(projectRequest.caps_SubmissionCategory.LogicalName, projectRequest.caps_SubmissionCategory.Id, new ColumnSet(true)) as caps_SubmissionCategory; caps_Submission capitalPlan = new caps_Submission(); caps_CallForSubmission callForSubmission = new caps_CallForSubmission(); if (projectRequest.caps_Submission != null) { //get Capital Plan capitalPlan = service.Retrieve(projectRequest.caps_Submission.LogicalName, projectRequest.caps_Submission.Id, new ColumnSet("caps_callforsubmission")) as caps_Submission; //get Call for Submission callForSubmission = service.Retrieve(capitalPlan.caps_CallforSubmission.LogicalName, capitalPlan.caps_CallforSubmission.Id, new ColumnSet("caps_capitalplanyear")) as caps_CallForSubmission; } //VALIDATION STARTS HERE bool isValid = true; StringBuilder validationMessage = new StringBuilder(); decimal totalProjectCost = projectRequest.caps_TotalProjectCost.GetValueOrDefault(0); #region Check if Published //check if published if (!projectRequest.caps_PublishProject.GetValueOrDefault(false)) { isValid = false; validationMessage.AppendLine("Project Request needs to be published in order to be submitted."); } #endregion tracingService.Trace("{0}", "Run Schedule B"); #region Run Schedule B //Run Schedule B for any project requests that require it if (projectRequest.caps_RequiresScheduleB.GetValueOrDefault(false)) { //Run Schedule B try { totalProjectCost = CalculateScheduleB.RunCalculation(tracingService, context, service, recordId); if (projectRequest.caps_TotalProjectCost != totalProjectCost) { //need to update project request var recordToUpdate = new caps_Project(); recordToUpdate.Id = projectRequest.Id; recordToUpdate.caps_TotalProjectCost = totalProjectCost; recordToUpdate.caps_ScheduleBTotal = totalProjectCost; service.Update(recordToUpdate); } } catch (Exception ex) { isValid = false; validationMessage.AppendLine("Preliminary Budget failed to run sucessfully. Please manually trigger the process by clicking the button to see the detailed error."); } } #endregion #region Check Cash Fully Allocated //Check that cash flow is fully allocated if needed if (submissionCategory.caps_RequireCostAllocation.GetValueOrDefault(false)) { //Get Estimated Expenditures using (var crmContext = new CrmServiceContext(service)) { decimal?estimatedExpenditures = crmContext.caps_EstimatedYearlyCapitalExpenditureSet.Where(r => r.StateCode == caps_EstimatedYearlyCapitalExpenditureState.Active && r.caps_Project.Id == recordId).AsEnumerable().Sum(r => r.caps_YearlyExpenditure); if (Math.Round(totalProjectCost) != estimatedExpenditures) { tracingService.Trace("Total Project Cost: {0}", totalProjectCost); tracingService.Trace("Total Estimated Expenditures: {0}", estimatedExpenditures); isValid = false; validationMessage.AppendLine("Total Project Cost is not fully allocated."); } } } #endregion tracingService.Trace("{0}", "Check Cash Only in Current and Future Years based on Capital Plan year"); #region Check Cash Only in Current and Future Years based on Capital Plan year if (submissionCategory.caps_type.Value == (int)caps_submissioncategory_type.Major) { if (projectRequest.caps_Submission != null && projectRequest.caps_Projectyear != callForSubmission.caps_CapitalPlanYear) { //get capital plan year var capitalPlanYear = service.Retrieve(callForSubmission.caps_CapitalPlanYear.LogicalName, callForSubmission.caps_CapitalPlanYear.Id, new ColumnSet("edu_startyear")) as edu_Year; int startYear = capitalPlanYear.edu_StartYear.Value; tracingService.Trace("Start Year: {0}", startYear); var fetchXML = "<fetch version = '1.0' output-format = 'xml-platform' mapping = 'logical' distinct = 'false' >" + "<entity name = 'caps_estimatedyearlycapitalexpenditure' >" + "<attribute name = 'caps_estimatedyearlycapitalexpenditureid' />" + "<attribute name = 'caps_name' />" + "<attribute name = 'createdon' />" + "<order attribute = 'caps_name' descending = 'false' />" + "<filter type = 'and' >" + "<condition attribute = 'statecode' operator= 'eq' value = '0' />" + "<condition attribute = 'caps_project' operator= 'eq' value = '{" + recordId + "}' />" + // "<condition attribute = 'caps_yearlyexpenditure' operator='not-null' />" + "<condition attribute = 'caps_yearlyexpenditure' operator='gt' value='0' />" + "</filter>" + "<link-entity name='edu_year' from='edu_yearid' to='caps_year' link-type='inner' alias='ad' >" + "<filter type = 'and' >" + "<condition attribute = 'edu_startyear' operator= 'lt' value='" + startYear + "' />" + "<condition attribute = 'edu_type' operator= 'eq' value = '757500000' />" + "</filter></link-entity></entity></fetch>"; //Find out if there is cash flow in any of those 5 years var estimatedExpenditures = service.RetrieveMultiple(new FetchExpression(fetchXML)); tracingService.Trace("Record Count: {0}", estimatedExpenditures.Entities.Count()); if (estimatedExpenditures.Entities.Count() > 0) { isValid = false; validationMessage.AppendLine("There is cashflow entered in years preceeding the Capital Plan Start Year. Please adjust or remove the project request from the capital plan."); } } } #endregion tracingService.Trace("{0}", "Facility is BEP Eligible"); #region Check if Facility is BEP Eligible if (submissionCategory.caps_CategoryCode == "BEP") { //check if related facility still set as BEP Eligible var facility = service.Retrieve(projectRequest.caps_Facility.LogicalName, projectRequest.caps_Facility.Id, new ColumnSet("caps_bepeligible")) as caps_Facility; if (!facility.caps_BEPEligible.GetValueOrDefault(false)) { isValid = false; validationMessage.AppendLine("This BEP project request is for a facility that is not eligible."); } } #endregion #region Check if BUS is eligible for replacement //Check if BUS is eligible for replacement if (submissionCategory.caps_CategoryCode == "BUS" && projectRequest.caps_bus != null) { //get related bus record var bus = service.Retrieve(projectRequest.caps_bus.LogicalName, projectRequest.caps_bus.Id, new ColumnSet("caps_nonreplaceable")) as caps_Bus; tracingService.Trace("{0}:{1}", "Check if Bus is replaceable", bus.caps_NonReplaceable); if (!bus.caps_NonReplaceable.GetValueOrDefault(true)) { isValid = false; validationMessage.AppendLine("This Bus project request is for a bus that is not eligible for replacement."); } } #endregion #region Check if SEP and CNCP have at least one Facility selected if (submissionCategory.caps_CategoryCode == "CNCP" || submissionCategory.caps_CategoryCode == "SEP") { if (projectRequest.caps_MultipleFacilities.GetValueOrDefault(false)) { //check that there is at least 1 related facility QueryExpression query = new QueryExpression("caps_project_caps_facility"); //query.ColumnSet.AddColumns(true); query.Criteria = new FilterExpression(); query.Criteria.AddCondition(caps_Project_caps_Facility.Fields.caps_projectid, ConditionOperator.Equal, recordId); EntityCollection relatedFacilities = service.RetrieveMultiple(query); if (relatedFacilities.Entities.Count() < 1) { isValid = false; validationMessage.AppendLine("Project request needs at least one facility in order to be submitted."); } } } #endregion tracingService.Trace("{0}", "Minor & AFG in correct year"); #region Check if minor project year matches call for submission //Check if minor projects' project year matches call for submission if (submissionCategory.caps_CallforSubmissionType.Value == (int)caps_CallforSubmissionType.Minor || submissionCategory.caps_CallforSubmissionType.Value == (int)caps_CallforSubmissionType.AFG) { if (projectRequest.caps_Submission != null && projectRequest.caps_Projectyear.Id != callForSubmission.caps_CapitalPlanYear.Id) { tracingService.Trace("Project Year: {0}", projectRequest.caps_Projectyear.Id); tracingService.Trace("Capital Plan Year: {0}", callForSubmission.caps_CapitalPlanYear.Id); //Project request is not in correct year isValid = false; if (submissionCategory.caps_CallforSubmissionType.Value == (int)caps_CallforSubmissionType.Minor) { validationMessage.AppendLine("Minor project requests added to a capital plan must start in same year as the plan in order to be submitted."); } else { validationMessage.AppendLine("AFG project requests added to an expenditure plan must start in same year as the plan in order to be submitted."); } } } #endregion tracingService.Trace("{0}", "Check if Major Project has cash flow in first 5 years and not lease"); #region Check if Major Project has cash flow in first 5 years and not lease //Check if Major Project has cash flow in first 5 years and not lease if (submissionCategory.caps_type.Value == (int)caps_submissioncategory_type.Major && submissionCategory.caps_CategoryCode != "LEASE") { if (projectRequest.caps_Submission != null && projectRequest.caps_Projectyear != callForSubmission.caps_CapitalPlanYear) { //get capital plan year var capitalPlanYear = service.Retrieve(callForSubmission.caps_CapitalPlanYear.LogicalName, callForSubmission.caps_CapitalPlanYear.Id, new ColumnSet("edu_startyear")) as edu_Year; int startYear = capitalPlanYear.edu_StartYear.Value; var fetchXML = "<fetch version = '1.0' output-format = 'xml-platform' mapping = 'logical' distinct = 'false' >" + "<entity name = 'caps_estimatedyearlycapitalexpenditure' >" + "<attribute name = 'caps_estimatedyearlycapitalexpenditureid' />" + "<attribute name = 'caps_name' />" + "<attribute name = 'createdon' />" + "<order attribute = 'caps_name' descending = 'false' />" + "<filter type = 'and' >" + "<condition attribute = 'statecode' operator= 'eq' value = '0' />" + "<condition attribute = 'caps_project' operator= 'eq' value = '{" + recordId + "}' />" + "<condition attribute = 'caps_yearlyexpenditure' operator='not-null' />" + "<condition attribute = 'caps_yearlyexpenditure' operator='gt' value='0' />" + "</filter>" + "<link-entity name='edu_year' from='edu_yearid' to='caps_year' link-type='inner' alias='ad' >" + "<filter type = 'and' >" + "<condition attribute = 'edu_startyear' operator= 'ge' value='" + startYear + "' />" + "<condition attribute = 'edu_startyear' operator= 'le' value = '" + (startYear + 4) + "' />" + "<condition attribute = 'edu_type' operator= 'eq' value = '757500000' />" + "</filter></link-entity></entity></fetch>"; //Find out if there is cash flow in any of those 5 years var estimatedExpenditures = service.RetrieveMultiple(new FetchExpression(fetchXML)); if (estimatedExpenditures.Entities.Count() < 1) { isValid = false; validationMessage.AppendLine("There are no estimated yearly expenditures in the first 5 years. Please adjust or remove the project request from the capital plan."); } } } #endregion tracingService.Trace("{0}", "Check if Major Project has occupancy year before anticipated start year"); #region Check if Major Project has occupancy year before anticipated start year if (submissionCategory.caps_type.Value == (int)caps_submissioncategory_type.Major && projectRequest.caps_AnticipatedOccupancyYear != null && projectRequest.caps_Projectyear != null) { //get both anticipated occupancy year and project year var anticipatedOccupancyYear = service.Retrieve(projectRequest.caps_AnticipatedOccupancyYear.LogicalName, projectRequest.caps_AnticipatedOccupancyYear.Id, new ColumnSet("edu_startyear")) as edu_Year; var anticipatedStartYear = service.Retrieve(projectRequest.caps_Projectyear.LogicalName, projectRequest.caps_Projectyear.Id, new ColumnSet("edu_startyear")) as edu_Year; if (anticipatedOccupancyYear.edu_StartYear < anticipatedStartYear.edu_StartYear) { isValid = false; validationMessage.AppendLine("Anticipated Occupancy Year should be equal or After Anticipated Project Start Year."); } } #endregion tracingService.Trace("{0}", "Check if major project has any prfs options with a start date before the capital plan year"); #region Check if major project has any prfs options with a start date before the capital plan year if (submissionCategory.caps_type.Value == (int)caps_submissioncategory_type.Major) { if (projectRequest.caps_Submission != null) { //get capital plan year var capitalPlanYear = service.Retrieve(callForSubmission.caps_CapitalPlanYear.LogicalName, callForSubmission.caps_CapitalPlanYear.Id, new ColumnSet("edu_startyear")) as edu_Year; int startYear = capitalPlanYear.edu_StartYear.Value; var fetchXMLPRFS = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" + "<entity name=\"caps_prfsalternativeoption\" > " + "<attribute name=\"caps_prfsalternativeoptionid\" /> " + "<attribute name=\"caps_name\" /> " + "<attribute name=\"createdon\" /> " + " <order attribute=\"caps_name\" descending=\"false\" /> " + "<filter type=\"and\" > " + "<condition attribute = \"statuscode\" operator=\"eq\" value = \"1\" /> " + "<condition attribute = \"caps_projectrequest\" operator= \"eq\" value = '{" + recordId + "}' /> " + "</filter > " + "<link-entity name = \"edu_year\" from = \"edu_yearid\" to = \"caps_anticipatedoptionstartyear\" link-type = \"inner\" alias = \"ad\" > " + " <filter type = \"and\" > " + " <condition attribute = \"edu_startyear\" operator= \"lt\" value = \"" + startYear + "\" /> " + " </filter > " + "</link-entity > " + "</entity > " + "</fetch > "; //Find out if there are any PRFSs with early start dates var prfsOptions = service.RetrieveMultiple(new FetchExpression(fetchXMLPRFS)); if (prfsOptions.Entities.Count() > 0) { isValid = false; validationMessage.AppendLine("There is one or more PRFS Alternative Option with an Anticipated Option Start Year before the Capital Plan Year. Please adjust or remove the Concept Plan Alternative Option from the Project Request."); } } } #endregion tracingService.Trace("{0}", "Check if Lease occupancy year on or after submission year"); #region Check if Lease occupancy year on or after submission year if (submissionCategory.caps_CategoryCode == "LEASE" && projectRequest.caps_Submission != null && projectRequest.caps_AnticipatedOccupancyYear != callForSubmission.caps_CapitalPlanYear) { //get occupancy year var occupancyYear = service.Retrieve(projectRequest.caps_AnticipatedOccupancyYear.LogicalName, projectRequest.caps_AnticipatedOccupancyYear.Id, new ColumnSet("edu_startyear")) as edu_Year; //get capital plan year var capitalPlanYear = service.Retrieve(callForSubmission.caps_CapitalPlanYear.LogicalName, callForSubmission.caps_CapitalPlanYear.Id, new ColumnSet("edu_startyear")) as edu_Year; int startYear = capitalPlanYear.edu_StartYear.Value; if (occupancyYear.edu_StartYear.HasValue && capitalPlanYear.edu_StartYear.HasValue) { if (occupancyYear.edu_StartYear.Value < capitalPlanYear.edu_StartYear.Value) { isValid = false; validationMessage.AppendLine("Lease project requests added to a capital plan must have an Anticipated Occupancy Year on or after the Capital Plan Start Year."); } } } #endregion tracingService.Trace("{0}", "Check if any Procurement Analysis Questions aren't marked as complete on Major Projects"); #region Check if any Procurement Analysis Questions aren't marked as complete on Major Projects if (submissionCategory.caps_type.Value == (int)caps_submissioncategory_type.Major && projectRequest.caps_Submission != null) { //get capital plan year var capitalPlanYear = service.Retrieve(callForSubmission.caps_CapitalPlanYear.LogicalName, callForSubmission.caps_CapitalPlanYear.Id, new ColumnSet("edu_startyear")) as edu_Year; int startYear = capitalPlanYear.edu_StartYear.Value; var fetchXML = "<fetch version = '1.0' output-format = 'xml-platform' mapping = 'logical' distinct = 'false' >" + "<entity name = 'caps_estimatedyearlycapitalexpenditure' >" + "<attribute name = 'caps_estimatedyearlycapitalexpenditureid' />" + "<attribute name = 'caps_name' />" + "<attribute name = 'createdon' />" + "<order attribute = 'caps_name' descending = 'false' />" + "<filter type = 'and' >" + "<condition attribute = 'statecode' operator= 'eq' value = '0' />" + "<condition attribute = 'caps_project' operator= 'eq' value = '{" + recordId + "}' />" + "<condition attribute = 'caps_yearlyexpenditure' operator='not-null' />" + "<condition attribute = 'caps_yearlyexpenditure' operator='gt' value='0' />" + "</filter>" + "<link-entity name='edu_year' from='edu_yearid' to='caps_year' link-type='inner' alias='ad' >" + "<filter type = 'and' >" + "<condition attribute = 'edu_startyear' operator= 'ge' value='" + startYear + "' />" + "<condition attribute = 'edu_startyear' operator= 'le' value = '" + (startYear + 2) + "' />" + "<condition attribute = 'edu_type' operator= 'eq' value = '757500000' />" + "</filter></link-entity></entity></fetch>"; //Find out if there is cash flow in any of those 3 years var estimatedExpenditures = service.RetrieveMultiple(new FetchExpression(fetchXML)); if (estimatedExpenditures.Entities.Count() > 0) { var fetchProcurementAnalysis = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name = 'caps_procurementanalysis' > " + "<attribute name = 'caps_procurementanalysisid' /> " + "<attribute name = 'caps_name' /> " + "<attribute name = 'createdon' /> " + "<order attribute = 'caps_name' descending = 'false' /> " + "<filter type = 'and' > " + "<condition attribute = 'caps_projectrequest' operator= 'eq' value = '{" + recordId + "}' /> " + "<condition attribute = 'caps_complete' operator= 'ne' value = '1' /> " + "<condition attribute = 'statecode' operator= 'eq' value = '0' /> " + "</filter> " + "</entity> " + "</fetch> "; var incompleteAnalysis = service.RetrieveMultiple(new FetchExpression(fetchProcurementAnalysis)); if (incompleteAnalysis.Entities.Count() > 0) { isValid = false; validationMessage.AppendLine("All Procurement Analysis records on the PRFS tab must be marked as Complete."); } } } #endregion this.valid.Set(executionContext, isValid); this.message.Set(executionContext, validationMessage.ToString()); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: CalculateProjectRequestOperatingCapacity", DateTime.Now.ToLongTimeString()); var recordId = context.PrimaryEntityId; var startingDesign_K = 0; var startingDesign_E = 0; var startingDesign_S = 0; var startingOperating_K = 0; var startingOperating_E = 0; var startingOperating_S = 0; //Get Project Request var projectRequestColumns = new ColumnSet("caps_facility", "caps_changeindesigncapacitykindergarten", "caps_changeindesigncapacityelementary", "caps_changeindesigncapacitysecondary", "caps_futurelowestgrade", "caps_futurehighestgrade"); var projectRequest = service.Retrieve(caps_Project.EntityLogicalName, recordId, projectRequestColumns) as caps_Project; if (projectRequest.caps_FutureLowestGrade != null && projectRequest.caps_FutureHighestGrade != null) { //if facility exists, then retrieve it if (projectRequest.caps_Facility != null && projectRequest.caps_Facility.Id != Guid.Empty) { var facility = service.Retrieve(caps_Facility.EntityLogicalName, projectRequest.caps_Facility.Id, new ColumnSet("caps_adjusteddesigncapacitykindergarten", "caps_adjusteddesigncapacityelementary", "caps_adjusteddesigncapacitysecondary", "caps_operatingcapacitykindergarten", "caps_operatingcapacityelementary", "caps_operatingcapacitysecondary")) as caps_Facility; if (facility != null) { startingDesign_K = facility.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0); startingDesign_E = facility.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0); startingDesign_S = facility.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0); startingOperating_K = Convert.ToInt32(facility.caps_OperatingCapacityKindergarten.GetValueOrDefault(0)); startingOperating_E = Convert.ToInt32(facility.caps_OperatingCapacityElementary.GetValueOrDefault(0)); startingOperating_S = Convert.ToInt32(facility.caps_OperatingCapacitySecondary.GetValueOrDefault(0)); } } var changeInDesign_K = startingDesign_K + projectRequest.caps_ChangeinDesignCapacityKindergarten.GetValueOrDefault(0); var changeInDesign_E = startingDesign_E + projectRequest.caps_ChangeinDesignCapacityElementary.GetValueOrDefault(0); var changeInDesign_S = startingDesign_S + projectRequest.caps_ChangeinDesignCapacitySecondary.GetValueOrDefault(0); //Get Operating Capacity Values var capacity = new Services.CapacityFactors(service); Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity); var result = capacityService.Calculate(changeInDesign_K, changeInDesign_E, changeInDesign_S, projectRequest.caps_FutureLowestGrade.Value, projectRequest.caps_FutureHighestGrade.Value); var changeInOperating_K = Convert.ToInt32(result.KindergartenCapacity) - startingOperating_K; var changeInOperating_E = Convert.ToInt32(result.ElementaryCapacity) - startingOperating_E; var changeInOperating_S = Convert.ToInt32(result.SecondaryCapacity) - startingOperating_S; var recordToUpdate = new caps_Project(); recordToUpdate.Id = recordId; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = changeInOperating_K; recordToUpdate.caps_ChangeinOperatingCapacityElementary = changeInOperating_E; recordToUpdate.caps_ChangeinOperatingCapacitySecondary = changeInOperating_S; service.Update(recordToUpdate); } else { //blank out operating capacity var recordToUpdate = new caps_Project(); recordToUpdate.Id = recordId; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = null; recordToUpdate.caps_ChangeinOperatingCapacityElementary = null; recordToUpdate.caps_ChangeinOperatingCapacitySecondary = null; service.Update(recordToUpdate); } }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString()); //Update to run on school district var recordId = context.PrimaryEntityId; try { //Get Global Capacity values var capacity = new Services.CapacityFactors(service); Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity); tracingService.Trace("Section: {0}", "Update Facilities"); #region Update Facilities //get Facilities var fetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\" >" + "<entity name=\"caps_facility\">" + "<attribute name=\"caps_facilityid\" /> " + "<attribute name=\"caps_name\" /> " + "<attribute name=\"caps_lowestgrade\" /> " + "<attribute name=\"caps_highestgrade\" /> " + "<attribute name=\"caps_adjusteddesigncapacitysecondary\" /> " + "<attribute name=\"caps_adjusteddesigncapacitykindergarten\" /> " + "<attribute name=\"caps_adjusteddesigncapacityelementary\" /> " + "<order attribute=\"caps_name\" descending=\"false\" /> " + "<filter type=\"and\" > " + "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /> " + "<condition attribute=\"caps_lowestgrade\" operator=\"not-null\" />" + "<condition attribute=\"caps_highestgrade\" operator=\"not-null\" />" + "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" + "</filter> " + "<link-entity name=\"caps_facilitytype\" from=\"caps_facilitytypeid\" to=\"caps_currentfacilitytype\" link-type=\"inner\" alias=\"ac\" > " + "<filter type=\"and\" > " + "<condition attribute=\"caps_schooltype\" operator=\"not-null\" /> " + "</filter> " + "</link-entity> " + "</entity> " + "</fetch>"; EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchXML)); foreach (caps_Facility facilityRecord in results.Entities) { tracingService.Trace("Facility:{0}", facilityRecord.caps_Name); var kDesign = facilityRecord.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0); var eDesign = facilityRecord.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0); var sDesign = facilityRecord.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0); var lowestGrade = facilityRecord.caps_LowestGrade.Value; var highestGrade = facilityRecord.caps_HighestGrade.Value; var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade); //Update Facility var recordToUpdate = new caps_Facility(); recordToUpdate.Id = facilityRecord.Id; recordToUpdate.caps_OperatingCapacityKindergarten = result.KindergartenCapacity; recordToUpdate.caps_OperatingCapacityElementary = result.ElementaryCapacity; recordToUpdate.caps_OperatingCapacitySecondary = result.SecondaryCapacity; service.Update(recordToUpdate); } #endregion tracingService.Trace("Section: {0}", "Update Capacity Reporting"); #region Update Capacity Reporting //Update Capacity Reporting var capacityFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\" >" + "<entity name=\"caps_capacityreporting\" > " + "<attribute name=\"caps_capacityreportingid\" /> " + "<attribute name=\"caps_secondary_designcapacity\" /> " + "<attribute name=\"caps_kindergarten_designcapacity\" /> " + "<attribute name=\"caps_elementary_designcapacity\" /> " + "<order attribute=\"caps_secondary_designutilization\" descending=\"false\" /> " + "<link-entity name=\"caps_facility\" from=\"caps_facilityid\" to=\"caps_facility\" visible=\"false\" link-type=\"inner\" alias=\"facility\" > " + "<attribute name=\"caps_lowestgrade\" /> " + "<attribute name=\"caps_highestgrade\" /> " + "<filter type=\"and\" > " + "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" + "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" /> " + "<condition attribute=\"caps_lowestgrade\" operator=\"not-null\" />" + "<condition attribute=\"caps_highestgrade\" operator=\"not-null\" />" + "</filter> " + "</link-entity> " + "<link-entity name=\"edu_year\" from=\"edu_yearid\" to=\"caps_schoolyear\" link-type=\"inner\" alias=\"ab\" >" + "<filter type=\"and\"> " + "<condition attribute=\"statuscode\" operator=\"in\">" + "<value>1</value> " + "<value>757500000</value> " + "</condition>" + "</filter>" + "</link-entity>" + "</entity> " + "</fetch> "; tracingService.Trace("Capacity Reporting Fetch: {0}", capacityFetchXML); EntityCollection capacityResults = service.RetrieveMultiple(new FetchExpression(capacityFetchXML)); foreach (caps_CapacityReporting capacityRecord in capacityResults.Entities) { var kDesign = capacityRecord.caps_Kindergarten_designcapacity.GetValueOrDefault(0); var eDesign = capacityRecord.caps_Elementary_designcapacity.GetValueOrDefault(0); var sDesign = capacityRecord.caps_Secondary_designcapacity.GetValueOrDefault(0); tracingService.Trace("Capacity Reporting: {0}", capacityRecord.Id); tracingService.Trace("Lowest: {0}", ((AliasedValue)capacityRecord["facility.caps_lowestgrade"]).Value); tracingService.Trace("Highest: {0}", ((AliasedValue)capacityRecord["facility.caps_highestgrade"]).Value); var lowestGrade = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_lowestgrade"]).Value).Value; var highestGrade = ((OptionSetValue)((AliasedValue)capacityRecord["facility.caps_highestgrade"]).Value).Value; tracingService.Trace("Start Calculate: {0}", capacityRecord.Id); var result = capacityService.Calculate(kDesign, eDesign, sDesign, lowestGrade, highestGrade); tracingService.Trace("End Calculate: {0}", capacityRecord.Id); //Update Capacity Reporting var recordToUpdate = new caps_CapacityReporting(); recordToUpdate.Id = capacityRecord.Id; recordToUpdate.caps_Kindergarten_operatingcapacity = result.KindergartenCapacity; recordToUpdate.caps_Elementary_operatingcapacity = result.ElementaryCapacity; recordToUpdate.caps_Secondary_operatingcapacity = result.SecondaryCapacity; service.Update(recordToUpdate); } #endregion tracingService.Trace("Section: {0}", "Update Draft Project Requests"); #region Update Draft Project Requests //Update Draft Project Requests var projectRequestFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" + "<entity name=\"caps_project\" > " + "<attribute name=\"caps_facility\" /> " + "<attribute name=\"caps_changeindesigncapacitykindergarten\" /> " + "<attribute name=\"caps_changeindesigncapacityelementary\" /> " + "<attribute name=\"caps_changeindesigncapacitysecondary\" /> " + "<attribute name=\"caps_futurelowestgrade\" /> " + "<attribute name=\"caps_futurehighestgrade\" /> " + "<order attribute=\"caps_projectcode\" descending=\"false\" /> " + "<filter type=\"and\" > " + "<condition attribute=\"statuscode\" operator=\"eq\" value=\"1\" /> " + "<condition attribute=\"caps_schooldistrict\" operator=\"eq\" value=\"{" + recordId + "}\" />" + "<filter type=\"or\" > " + "<condition attribute=\"caps_changeinoperatingcapacitykindergarten\" operator=\"not-null\" /> " + "<condition attribute=\"caps_changeinoperatingcapacityelementary\" operator=\"not-null\" /> " + "<condition attribute=\"caps_changeinoperatingcapacitysecondary\" operator=\"not-null\" /> " + "</filter> " + "</filter> " + "</entity> " + "</fetch> "; EntityCollection projectResults = service.RetrieveMultiple(new FetchExpression(projectRequestFetchXML)); foreach (caps_Project projectRecord in projectResults.Entities) { if (projectRecord.caps_FutureLowestGrade != null && projectRecord.caps_FutureHighestGrade != null) { var startingDesign_K = 0; var startingDesign_E = 0; var startingDesign_S = 0; //if facility exists, then retrieve it if (projectRecord.caps_Facility != null && projectRecord.caps_Facility.Id != Guid.Empty) { var facility = service.Retrieve(caps_Facility.EntityLogicalName, projectRecord.caps_Facility.Id, new ColumnSet("caps_adjusteddesigncapacitykindergarten", "caps_adjusteddesigncapacityelementary", "caps_adjusteddesigncapacitysecondary")) as caps_Facility; if (facility != null) { startingDesign_K = facility.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0); startingDesign_E = facility.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0); startingDesign_S = facility.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0); } } var changeInDesign_K = startingDesign_K + projectRecord.caps_ChangeinDesignCapacityKindergarten.GetValueOrDefault(0); var changeInDesign_E = startingDesign_E + projectRecord.caps_ChangeinDesignCapacityElementary.GetValueOrDefault(0); var changeInDesign_S = startingDesign_S + projectRecord.caps_ChangeinDesignCapacitySecondary.GetValueOrDefault(0); var result = capacityService.Calculate(changeInDesign_K, changeInDesign_E, changeInDesign_S, projectRecord.caps_FutureLowestGrade.Value, projectRecord.caps_FutureHighestGrade.Value); var recordToUpdate = new caps_Project(); recordToUpdate.Id = projectRecord.Id; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = Convert.ToInt32(result.KindergartenCapacity); recordToUpdate.caps_ChangeinOperatingCapacityElementary = Convert.ToInt32(result.ElementaryCapacity); recordToUpdate.caps_ChangeinOperatingCapacitySecondary = Convert.ToInt32(result.SecondaryCapacity); service.Update(recordToUpdate); } else { //blank out operating capacity var recordToUpdate = new caps_Project(); recordToUpdate.Id = projectRecord.Id; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = null; recordToUpdate.caps_ChangeinOperatingCapacityElementary = null; recordToUpdate.caps_ChangeinOperatingCapacitySecondary = null; service.Update(recordToUpdate); } } #endregion this.error.Set(executionContext, false); } catch (Exception ex) { tracingService.Trace("Error Details: {0}", ex.Message); //might want to also include error message this.error.Set(executionContext, true); this.errorMessage.Set(executionContext, ex.Message); } tracingService.Trace("{0}{1}", "End Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString()); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString()); var recordId = context.PrimaryEntityId; try { //Get Global Capacity values var capacity = new Services.CapacityFactors(service); Services.OperatingCapacity capacityService = new Services.OperatingCapacity(service, tracingService, capacity); #region Update Draft Project Requests //Update Draft Project Requests var projectRequestFetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" + "<entity name=\"caps_project\" > " + "<attribute name=\"caps_facility\" /> " + "<attribute name=\"caps_changeindesigncapacitykindergarten\" /> " + "<attribute name=\"caps_changeindesigncapacityelementary\" /> " + "<attribute name=\"caps_changeindesigncapacitysecondary\" /> " + "<attribute name=\"caps_futurelowestgrade\" /> " + "<attribute name=\"caps_futurehighestgrade\" /> " + "<order attribute=\"caps_projectcode\" descending=\"false\" /> " + "<filter type=\"and\" > " + "<condition attribute=\"statuscode\" operator=\"eq\" value=\"1\" /> " + "<filter type=\"or\" > " + "<condition attribute=\"caps_changeinoperatingcapacitykindergarten\" operator=\"not-null\" /> " + "<condition attribute=\"caps_changeinoperatingcapacityelementary\" operator=\"not-null\" /> " + "<condition attribute=\"caps_changeinoperatingcapacitysecondary\" operator=\"not-null\" /> " + "</filter> " + "</filter> " + "</entity> " + "</fetch> "; EntityCollection projectResults = service.RetrieveMultiple(new FetchExpression(projectRequestFetchXML)); foreach (caps_Project projectRecord in projectResults.Entities) { if (projectRecord.caps_FutureLowestGrade != null && projectRecord.caps_FutureHighestGrade != null) { var startingDesign_K = 0; var startingDesign_E = 0; var startingDesign_S = 0; //if facility exists, then retrieve it if (projectRecord.caps_Facility != null && projectRecord.caps_Facility.Id != Guid.Empty) { var facility = service.Retrieve(caps_Facility.EntityLogicalName, projectRecord.caps_Facility.Id, new ColumnSet("caps_adjusteddesigncapacitykindergarten", "caps_adjusteddesigncapacityelementary", "caps_adjusteddesigncapacitysecondary")) as caps_Facility; if (facility != null) { startingDesign_K = facility.caps_AdjustedDesignCapacityKindergarten.GetValueOrDefault(0); startingDesign_E = facility.caps_AdjustedDesignCapacityElementary.GetValueOrDefault(0); startingDesign_S = facility.caps_AdjustedDesignCapacitySecondary.GetValueOrDefault(0); } } var changeInDesign_K = startingDesign_K + projectRecord.caps_ChangeinDesignCapacityKindergarten.GetValueOrDefault(0); var changeInDesign_E = startingDesign_E + projectRecord.caps_ChangeinDesignCapacityElementary.GetValueOrDefault(0); var changeInDesign_S = startingDesign_S + projectRecord.caps_ChangeinDesignCapacitySecondary.GetValueOrDefault(0); var result = capacityService.Calculate(changeInDesign_K, changeInDesign_E, changeInDesign_S, projectRecord.caps_FutureLowestGrade.Value, projectRecord.caps_FutureHighestGrade.Value); var recordToUpdate = new caps_Project(); recordToUpdate.Id = recordId; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = Convert.ToInt32(result.KindergartenCapacity); recordToUpdate.caps_ChangeinOperatingCapacityElementary = Convert.ToInt32(result.ElementaryCapacity); recordToUpdate.caps_ChangeinOperatingCapacitySecondary = Convert.ToInt32(result.SecondaryCapacity); service.Update(recordToUpdate); } else { //blank out operating capacity var recordToUpdate = new caps_Project(); recordToUpdate.Id = recordId; recordToUpdate.caps_ChangeinOperatingCapacityKindergarten = null; recordToUpdate.caps_ChangeinOperatingCapacityElementary = null; recordToUpdate.caps_ChangeinOperatingCapacitySecondary = null; service.Update(recordToUpdate); } } #endregion this.error.Set(executionContext, false); } catch (Exception ex) { tracingService.Trace("Error Details: {0}", ex.Message); //might want to also include error message this.error.Set(executionContext, true); this.errorMessage.Set(executionContext, ex.Message); } tracingService.Trace("{0}{1}", "End Custom Workflow Activity: SetOperatingCapacity", DateTime.Now.ToLongTimeString()); }
internal static decimal RunCalculation(ITracingService tracingService, IWorkflowContext context, IOrganizationService service, Guid recordId) { tracingService.Trace("{0}{1}", "Regarding Record ID: ", recordId); var columns = new ColumnSet("caps_schooltype" , "caps_projecttype" , "caps_includenlc" , "caps_communitylocation" , "caps_municipalfees" , "caps_constructioncostsspir" , "caps_hostschooldistrict" , "caps_changeindesigncapacitykpositive" , "caps_changeindesigncapacityepositive" , "caps_changeindesigncapacityspositive" , "caps_changeindesigncapacityknegative" , "caps_changeindesigncapacityenegative" , "caps_changeindesigncapacitysnegative" , "caps_facility" , "caps_demolitioncost" , "caps_abnormaltopographycost" , "caps_temporaryaccommodationcost" , "caps_othercost" , "caps_schbadditionalspaceallocation"); var projectRequestRecord = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, columns) as caps_Project; var projectTypeRecord = service.Retrieve(projectRequestRecord.caps_ProjectType.LogicalName, projectRequestRecord.caps_ProjectType.Id, new ColumnSet("caps_budgetcalculationtype")) as caps_ProjectType; var communityLocationRecord = service.Retrieve(projectRequestRecord.caps_CommunityLocation.LogicalName, projectRequestRecord.caps_CommunityLocation.Id, new ColumnSet("caps_projectlocationfactor")) as caps_BudgetCalc_CommunityLocation; var hostSchoolDistrictRecord = service.Retrieve(projectRequestRecord.caps_HostSchoolDistrict.LogicalName, projectRequestRecord.caps_HostSchoolDistrict.Id, new ColumnSet("caps_freightrateallowance")) as edu_schooldistrict; int adjustedDesignK = 0; int adjustedDesignE = 0; int adjustedDesignS = 0; if (projectRequestRecord.caps_Facility != null) { tracingService.Trace("Facility: {0}", projectRequestRecord.caps_Facility.Id); var facilityColumnSet = new ColumnSet("caps_designcapacitykindergarten" , "caps_strongstartcapacitykindergarten" , "caps_designcapacityelementary" , "caps_strongstartcapacityelementary" , "caps_designcapacitysecondary" , "caps_strongstartcapacitysecondary"); var facilityRecord = service.Retrieve(projectRequestRecord.caps_Facility.LogicalName, projectRequestRecord.caps_Facility.Id, new ColumnSet(true)) as caps_Facility; adjustedDesignK = (int)facilityRecord.caps_DesignCapacityKindergarten.GetValueOrDefault(0) + facilityRecord.caps_StrongStartCapacityKindergarten.GetValueOrDefault(0); adjustedDesignE = (int)facilityRecord.caps_DesignCapacityElementary.GetValueOrDefault(0) + facilityRecord.caps_StrongStartCapacityElementary.GetValueOrDefault(0); adjustedDesignS = (int)facilityRecord.caps_DesignCapacitySecondary.GetValueOrDefault(0) + facilityRecord.caps_StrongStartCapacitySecondary.GetValueOrDefault(0); } int increaseDesignK = (int)projectRequestRecord.caps_ChangeinDesignCapacityKPositive.GetValueOrDefault(0); int increaseDesignE = (int)projectRequestRecord.caps_ChangeinDesignCapacityEPositive.GetValueOrDefault(0); int increaseDesignS = (int)projectRequestRecord.caps_ChangeinDesignCapacitySPositive.GetValueOrDefault(0); int decreaseDesignK = (int)projectRequestRecord.caps_ChangeinDesignCapacityKNegative.GetValueOrDefault(0); int decreaseDesignE = (int)projectRequestRecord.caps_ChangeinDesignCapacityENegative.GetValueOrDefault(0); int decreaseDesignS = (int)projectRequestRecord.caps_ChangeinDesignCapacitySNegative.GetValueOrDefault(0); int subtotalDesignK = adjustedDesignK + decreaseDesignK; int subtotalDesignE = adjustedDesignE + decreaseDesignE; int subtotalDesignS = adjustedDesignS + decreaseDesignS; tracingService.Trace("CalculateScheduleB: {0}", "Populate Variable"); var scheduleB = new ScheduleB(service, tracingService); //set parameters scheduleB.SchoolType = projectRequestRecord.caps_SchoolType.Id; scheduleB.BudgetCalculationType = projectTypeRecord.caps_BudgetCalculationType.Value; scheduleB.IncludeNLC = projectRequestRecord.caps_IncludeNLC.GetValueOrDefault(false); scheduleB.ProjectLocationFactor = communityLocationRecord.caps_ProjectLocationFactor.GetValueOrDefault(1); tracingService.Trace("Facility - K:{0} E:{1} S:{2}", adjustedDesignK, adjustedDesignE, adjustedDesignS); tracingService.Trace("Subtotal - K:{0} E:{1} S:{2}", subtotalDesignK, subtotalDesignE, subtotalDesignS); tracingService.Trace("Approved - K:{0} E:{1} S:{2}", subtotalDesignK + increaseDesignK, subtotalDesignE + increaseDesignE, subtotalDesignS + increaseDesignS); scheduleB.ExistingAndDecreaseDesignCapacity = new Services.DesignCapacity(subtotalDesignK, subtotalDesignE, subtotalDesignS); scheduleB.ExtraSpaceAllocation = projectRequestRecord.caps_SchBAdditionalSpaceAllocation; scheduleB.ApprovedDesignCapacity = new Services.DesignCapacity(subtotalDesignK + increaseDesignK, subtotalDesignE + increaseDesignE, subtotalDesignS + increaseDesignS); scheduleB.MunicipalFees = projectRequestRecord.caps_MunicipalFees.GetValueOrDefault(0); //scheduleB.ConstructionNonStructuralSeismicUpgrade = projectRequestRecord.caps_ConstructionCostsNonStructuralSeismicUpgr; scheduleB.ConstructionSeismicUpgrade = projectRequestRecord.caps_ConstructionCostsSPIR; //scheduleB.ConstructionSPIRAdjustment = projectRequestRecord.caps_ConstructionCostsSPIRAdjustments; //scheduleB.SPIRFees = projectRequestRecord.caps_SeismicProjectIdentificationReportFees; scheduleB.FreightRateAllowance = hostSchoolDistrictRecord.caps_FreightRateAllowance.GetValueOrDefault(0); //Supplemental Items scheduleB.Demolition = projectRequestRecord.caps_DemolitionCost.GetValueOrDefault(0); scheduleB.AbnormalTopography = projectRequestRecord.caps_AbnormalTopographyCost.GetValueOrDefault(0); scheduleB.TempAccommodation = projectRequestRecord.caps_TemporaryAccommodationCost.GetValueOrDefault(0); scheduleB.OtherSupplemental = projectRequestRecord.caps_OtherCost.GetValueOrDefault(0); //call Calculate tracingService.Trace("CalculateScheduleB: {0}", "Call Calculate Function"); CalculationResult result = scheduleB.Calculate(); //Update PRFS Option with Calculations var recordToUpdate = new caps_Project(); recordToUpdate.Id = recordId; //Section 2 recordToUpdate.caps_SchBSpaceAllocationNewReplacement = result.SpaceAllocationNewReplacement; recordToUpdate.caps_SchBTotalSpaceAllocation = result.SpaceAllocationNewReplacement + projectRequestRecord.caps_SchBAdditionalSpaceAllocation.GetValueOrDefault(0); //recordToUpdate.caps_SchBSpaceAllocationNLC = result.SpaceAllocationNLC; //Section 3 recordToUpdate.caps_SchBBaseBudgetRate = result.BaseBudgetRate; recordToUpdate.caps_SchBProjectSizeFactor = result.ProjectSizeFactor; recordToUpdate.caps_SchBProjectLocationFactor = result.ProjectLocationFactor; recordToUpdate.caps_SchBUnitRate = result.UnitRate; //Section 4 recordToUpdate.caps_SchBConstructionNewSpaceReplacement = result.ConstructionNewReplacement; recordToUpdate.caps_SchBConstructionRenovations = result.ConstructionRenovation; recordToUpdate.caps_SchBSiteDevelopmentAllowance = result.SiteDevelopmentAllowance; recordToUpdate.caps_SchBSiteDevelopmentLocationAllowance = result.SiteDevelopmentLocationAllowance; //Section 5 recordToUpdate.caps_schbdesignfees = result.DesignFees; recordToUpdate.caps_SchBPostContractNewReplacement = result.PostContractNewReplacement; recordToUpdate.caps_SchBPostContractRenovations = result.PostContractRenovation; recordToUpdate.caps_SchBPostContractSeismic = result.PostContractSeismic; //recordToUpdate.caps_SchBMunicipalFees = result.MunicipalFees; recordToUpdate.caps_SchBEquipmentNew = result.EquipmentNew; recordToUpdate.caps_SchBEquipmentReplacement = result.EquipmentReplacement; recordToUpdate.caps_SchBProjectManagementFees = result.ProjectManagement; recordToUpdate.caps_SchBLiabilityInsurance = result.LiabilityInsurance; recordToUpdate.caps_SchBPayableTaxes = result.PayableTaxes; recordToUpdate.caps_SchBRiskReserve = result.RiskReserve; recordToUpdate.caps_SchBRiskReservePercent = result.RiskReservePercent; recordToUpdate.caps_SchBNLCBudgetAmount = result.NLCBudgetAmount; service.Update(recordToUpdate); return(result.Total); }