/// <summary> /// Handles the Click event of the delete/archive button in the grid /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param> protected void DeleteStep_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var dataContext = GetDataContext(); var stepService = new StepService(dataContext); var step = stepService.Get(e.RowKeyId); if (step != null) { string errorMessage; if (!stepService.CanDelete(step, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } stepService.Delete(step); dataContext.SaveChanges(); } BindParticipantsGrid(); }
// GET: Step public ActionResult Index() { var service = new StepService(); var model = service.GetAllSteps(); return(View(model)); }
public void Solve(object s) { var size = int.Parse((string)s); Console.Write(StepService.BuildSteps(size, _character)); //var tier = size; //do //{ // var output = ""; // for (var x = 1; x <= size; x++) // { // if (x >= tier) // { // output += _character; // } // else // { // output += " "; // } // } // Console.WriteLine(output); // tier--; //} //while (tier > 0); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var dataContext = new RockContext(); var stepProgramsQry = new StepProgramService(dataContext) .Queryable(); // Filter by: Category if (_categoryGuids.Any()) { stepProgramsQry = stepProgramsQry.Where(a => a.Category != null && _categoryGuids.Contains(a.Category.Guid)); } else { var categoryId = rFilter.GetUserPreference("Category").AsIntegerOrNull(); if (categoryId.HasValue && categoryId > 0) { stepProgramsQry = stepProgramsQry.Where(a => a.CategoryId == categoryId.Value); } } // Filter by: Active var activeFilter = rFilter.GetUserPreference("Active").ToLower(); switch (activeFilter) { case "active": stepProgramsQry = stepProgramsQry.Where(a => a.IsActive); break; case "inactive": stepProgramsQry = stepProgramsQry.Where(a => !a.IsActive); break; } // Sort by: Order stepProgramsQry = stepProgramsQry.OrderBy(b => b.Order); // Retrieve the Step Program data models and create corresponding view models to display in the grid. var stepService = new StepService(dataContext); var completedStepsQry = stepService.Queryable().Where(x => x.StepStatus != null && x.StepStatus.IsCompleteStatus); var stepPrograms = stepProgramsQry.Select(x => new StepProgramListItemViewModel { Id = x.Id, Name = x.Name, IconCssClass = x.IconCssClass, Category = x.Category.Name, StepTypeCount = x.StepTypes.Count, StepCompletedCount = completedStepsQry.Count(y => y.StepType.StepProgramId == x.Id) }) .ToList(); gStepProgram.DataSource = stepPrograms; gStepProgram.DataBind(); }
private StepService CreateStepService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new StepService(userId); return(service); }
/// <summary> /// Delete the current Step. /// </summary> private void DeleteStep() { var step = this.GetStep(); if (step == null) { return; } var dataContext = GetRockContext(); var stepService = new StepService(dataContext); string errorMessage; if (!stepService.CanDelete(step, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } stepService.Delete(step); dataContext.SaveChanges(); GoToSuccessPage(null); }
public void StepProgramProcess() { var attemptsQuery = new AchievementAttemptService(_rockContext).Queryable() .AsNoTracking() .Where(saa => saa.AchievementTypeId == _achievementTypeId && saa.AchieverEntityId == _personAliasId) .OrderBy(saa => saa.AchievementAttemptStartDateTime); // There should be no attempts Assert.That.AreEqual(0, attemptsQuery.Count()); var achievementTypeCache = AchievementTypeCache.Get(_achievementTypeId); var step = new StepService(_rockContext).Queryable().FirstOrDefault(i => i.ForeignKey == KEY); var component = AchievementContainer.GetComponent(ComponentEntityTypeName); component.Process(_rockContext, achievementTypeCache, step); _rockContext.SaveChanges(); var attempts = attemptsQuery.ToList(); Assert.That.IsNotNull(attempts); Assert.That.AreEqual(1, attempts.Count); // The database stores progress with only 2 digits beyond the decimal var progress = decimal.Divide(COMPLETE_COUNT, STEP_TYPE_COUNT); var progressDifference = Math.Abs(progress - attempts[0].Progress); Assert.That.AreEqual(RockDateTime.Today, attempts[0].AchievementAttemptStartDateTime); Assert.That.AreEqual(RockDateTime.Today, attempts[0].AchievementAttemptEndDateTime); Assert.That.IsTrue(progressDifference < .01m); Assert.That.IsFalse(attempts[0].IsClosed); Assert.That.IsFalse(attempts[0].IsSuccessful); }
/// <summary> /// Handles the GetRecipientMergeFields event of the gSteps control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GetRecipientMergeFieldsEventArgs"/> instance containing the event data.</param> protected void gSteps_GetRecipientMergeFields(object sender, GetRecipientMergeFieldsEventArgs e) { Step stepRow = e.DataItem as Step; if (stepRow == null) { return; } var dataContext = GetDataContext(); var step = new StepService(dataContext).Get(stepRow.Id); step.LoadAttributes(); var mergefields = e.MergeValues; e.MergeValues.Add("StepStatus", step.StepStatus.Name); e.MergeValues.Add("StepName", step.StepType.Name); dynamic dynamicAttributeCarrier = new RockDynamic(); foreach (var attributeKeyValue in step.AttributeValues) { dynamicAttributeCarrier[attributeKeyValue.Key] = attributeKeyValue.Value.Value; } e.MergeValues.Add("StepAttributes", dynamicAttributeCarrier); }
/// <summary> /// Get a query for people that have met prerequisites /// </summary> /// <param name="rockContext"></param> /// <param name="stepTypeView"></param> /// <returns></returns> private IQueryable <int> GetPersonIdsThatHaveMetPrerequisitesQuery(RockContext rockContext, StepTypeView stepTypeView) { var stepService = new StepService(rockContext); // We are querying for people that have met all the prerequisites for this step type // This method should not be called for stepTypes that do not have prerequisites // because that would be a query for everyone in the database var firstStepTypeId = stepTypeView.PrerequisiteStepTypeIds.First(); var prerequisiteCount = stepTypeView.PrerequisiteStepTypeIds.Count(); // Aliases that have completed the first prerequisite var query = stepService.Queryable().AsNoTracking() .Where(s => s.StepStatus.IsCompleteStatus && s.StepTypeId == firstStepTypeId) .Select(s => s.PersonAlias.PersonId); for (var i = 1; i < prerequisiteCount; i++) { var stepTypeId = stepTypeView.PrerequisiteStepTypeIds.ElementAt(i); // Aliases that have completed this subsequent prerequisite var subquery = stepService.Queryable().AsNoTracking() .Where(s => s.StepStatus.IsCompleteStatus && s.StepTypeId == stepTypeId) .Select(s => s.PersonAlias.PersonId); // Find the intersection (people in the main query who have also met this prerequisite) query = query.Intersect(subquery); } return(query); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType"></param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { if (string.IsNullOrWhiteSpace(selection)) { return(null); } var values = JsonConvert.DeserializeObject <List <string> >(selection); if (values.Count < 3) { return(null); } var stepProgramGuid = values[0].AsGuid(); var stepTypeGuid = values[1].AsGuid(); var selectedProperty = values[2]; var stepProgram = GetStepProgram(stepProgramGuid); if (stepProgram == null) { return(null); } var stepType = GetStepType(stepTypeGuid); if (stepType == null) { return(null); } var rockContext = ( RockContext )serviceInstance.Context; var entityFields = GetStepAttributes(stepType.Id); var entityField = entityFields.FindFromFilterSelection(selectedProperty); if (entityField == null) { return(null); } // Find matchings Steps. var stepService = new StepService(rockContext); var stepParameterExpression = stepService.ParameterExpression; var attributeFilterValues = values.Skip(3).ToList(); var attributeWhereExpression = GetAttributeExpression(stepService, stepParameterExpression, entityField, attributeFilterValues); var stepQuery = stepService.Queryable() .Where(stepParameterExpression, attributeWhereExpression); // Get Person records associated with the Steps. var personService = new PersonService(rockContext); var personQuery = personService.Queryable() .Where(p => stepQuery.Any(x => x.PersonAlias.PersonId == p.Id)); // Extract the expression. var dataFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(personQuery, parameterExpression, "p"); return(dataFilterExpression); }
public void StepDateKeySavesCorrectly() { var rockContext = new RockContext(); var stepService = new StepService(rockContext); var step = BuildStep(rockContext, Convert.ToDateTime("3/16/2010"), Convert.ToDateTime("3/15/2010"), Convert.ToDateTime("3/17/2010")); stepService.Add(step); rockContext.SaveChanges(); var stepId = step.Id; // We're bypassing the model because the model doesn't user the StepDateKey from the database, // but it still needs to be correct for inner joins to work correctly. var result = rockContext.Database. SqlQuery <int>($"SELECT CompletedDateKey FROM Step WHERE Id = {stepId}").First(); Assert.AreEqual(20100316, result); result = rockContext.Database. SqlQuery <int>($"SELECT StartDateKey FROM Step WHERE Id = {stepId}").First(); Assert.AreEqual(20100315, result); result = rockContext.Database. SqlQuery <int>($"SELECT EndDateKey FROM Step WHERE Id = {stepId}").First(); Assert.AreEqual(20100317, result); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var settings = new FilterSettings(selection); var context = ( RockContext )serviceInstance.Context; // Get the Data View that defines the set of related records from which entities can be selected. var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent(settings.DataViewGuid, context); // Evaluate the Data View that defines the related records. var relatedEntityService = new StepService(context); var relatedEntityQuery = relatedEntityService.Queryable(); if (dataView != null) { relatedEntityQuery = DataComponentSettingsHelper.FilterByDataView(relatedEntityQuery, dataView, relatedEntityService); } // Get all of the People corresponding to the qualifying related records. var personService = new PersonService(( RockContext )serviceInstance.Context); var qry = personService.Queryable() .Where(p => relatedEntityQuery.Any(xx => xx.PersonAlias.PersonId == p.Id)); // Retrieve the Filter Expression. var extractedFilterExpression = FilterExpressionExtractor.Extract <Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Get the target entity. /// </summary> /// <param name="rockContext"></param> /// <param name="entityGuid"></param> /// <returns></returns> protected override IEntity GetTargetEntity(RockContext rockContext, Guid entityGuid) { var stepService = new StepService(rockContext); var step = stepService.Get(entityGuid); return(step); }
/// <summary> /// Sets the edit value from IEntity.Id value /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="id">The identifier.</param> public void SetEditValueFromEntityId(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id) { using (var rockContext = new RockContext()) { var itemGuid = new StepService(rockContext).GetGuid(id ?? 0); string guidValue = itemGuid.HasValue ? itemGuid.ToString() : string.Empty; SetEditValue(control, configurationValues, guidValue); } }
/// <summary> /// Gets the step service. /// </summary> /// <returns></returns> private StepService GetStepService() { if (_stepService == null) { var rockContext = GetRockContext(); _stepService = new StepService(rockContext); } return(_stepService); }
/// <summary> /// Delete the test data /// </summary> private static void DeleteTestData() { using (var rockContext = new RockContext()) { var stepService = new StepService(rockContext); var stepQuery = stepService.Queryable().Where(s => s.ForeignKey == ForeignKey); stepService.DeleteRange(stepQuery); rockContext.SaveChanges(); } using (var rockContext = new RockContext()) { var stepProgramService = new StepProgramService(rockContext); var stepProgramQuery = stepProgramService.Queryable().Where(sp => sp.ForeignKey == ForeignKey); stepProgramService.DeleteRange(stepProgramQuery); rockContext.SaveChanges(); } using (var rockContext = new RockContext()) { var personSearchKeyService = new PersonSearchKeyService(rockContext); var personSearchKeyQuery = personSearchKeyService.Queryable() .Where(psk => psk.PersonAlias.Person.ForeignKey == ForeignKey || PersonGuids.Contains(psk.PersonAlias.Person.Guid)); personSearchKeyService.DeleteRange(personSearchKeyQuery); rockContext.SaveChanges(); } using (var rockContext = new RockContext()) { var personAliasService = new PersonAliasService(rockContext); var personAliasQuery = personAliasService.Queryable() .Where(pa => pa.Person.ForeignKey == ForeignKey || PersonGuids.Contains(pa.Person.Guid)); personAliasService.DeleteRange(personAliasQuery); rockContext.SaveChanges(); } using (var rockContext = new RockContext()) { var personService = new PersonService(rockContext); var personQuery = personService.Queryable() .Where(p => p.ForeignKey == ForeignKey || PersonGuids.Contains(p.Guid)); personService.DeleteRange(personQuery); rockContext.SaveChanges(); } }
public void GetAllStepsTest() { InitData(); steps.Add(step1); StepDaoMock.Setup(f => f.GetAllStep()).Returns(steps); StepService impl = new StepService(StepDaoMock.Object, WorkflowDaoMock.Object, InstanceDaoMock.Object); stepView = impl.GetAllSteps(); Assert.AreEqual(1, stepView.GetData().Count); Assert.AreEqual(SUCCESS, stepView.StatusCode); }
/// <summary> /// Gets the source entities query. This is the set of source entities that should be passed to the process method /// when processing this achievement type. /// </summary> /// <param name="achievementTypeCache">The achievement type cache.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public override IQueryable <IEntity> GetSourceEntitiesQuery(AchievementTypeCache achievementTypeCache, RockContext rockContext) { var stepProgram = GetStepProgramCache(achievementTypeCache); var stepTypes = stepProgram.StepTypes; var service = new StepService(rockContext); var query = service.Queryable(); if (stepTypes?.Any() == true) { var stepTypeIds = stepTypes.Select(st => st.Id); return(query.Where(s => stepTypeIds.Contains(s.StepTypeId))); } return(query); }
/// <summary> /// Launch a specific workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="triggerId">The connection workflow.</param> /// <param name="targetId">The name.</param> private void LaunchWorkflow(int triggerId, int targetId) { var rockContext = this.GetRockContext(); var target = new StepService(rockContext).Get(targetId); var workflowTrigger = new StepWorkflowTriggerService(rockContext).Get(triggerId); bool success = this.LaunchWorkflow(rockContext, target, workflowTrigger); if (success) { ShowReadonlyDetails(); } }
// GET: Step/Details/{id} public ActionResult Details(int id) { var service = new StepService(); try { var model = service.GetStepById(id); return(View(model)); } catch (InvalidOperationException) { TempData["NoResult"] = "The Step could not be found."; return(RedirectToAction("Index")); } }
/// <summary> /// Adds the step. /// </summary> /// <param name="stepTypeId">The step type identifier.</param> /// <param name="stepStatusId">The step status identifier.</param> /// <param name="personAliasId">The person alias identifier.</param> private void AddStep(int stepTypeId, int stepStatusId, int personAliasId) { var rockContext = new RockContext(); var stepService = new StepService(rockContext); var stepProgramService = new StepProgramService(rockContext); // Get the step program with step types and statuses to better calculate the dates for the new step var stepProgram = stepProgramService.Queryable("StepTypes, StepStatuses").FirstOrDefault(sp => sp.StepTypes.Any(st => st.Id == stepTypeId) && sp.StepStatuses.Any(ss => ss.Id == stepStatusId)); var stepType = stepProgram?.StepTypes.FirstOrDefault(st => st.Id == stepTypeId); var stepStatus = stepProgram?.StepStatuses.FirstOrDefault(ss => ss.Id == stepStatusId); if (stepType == null) { ExceptionLogService.LogException($"Error adding step related to an achievement. The step type {stepTypeId} did not resolve."); return; } if (stepStatus == null) { ExceptionLogService.LogException($"Error adding step related to an achievement. The step status {stepStatusId} did not resolve."); return; } // Add the new step var step = new Step { StepTypeId = stepTypeId, StepStatusId = stepStatusId, CompletedDateTime = stepStatus.IsCompleteStatus ? EndDate : null, StartDateTime = StartDate, EndDateTime = stepType.HasEndDate ? EndDate : null, PersonAliasId = personAliasId }; // If the person cannot be added to the step type, then don't add anything since some step types only allow one step // or require pre-requisites if (stepService.CanAdd(step, out _)) { stepService.Add(step); } rockContext.SaveChanges(); }
public void RemoveStepTest() { InitData(); StepDaoMock.Setup(f => f.GetOneStepById(step1)).Returns(step1); StepDaoMock.Setup(f => f.GetOneStepById(step2)).Returns(step3); StepService impl = new StepService(StepDaoMock.Object, WorkflowDaoMock.Object, InstanceDaoMock.Object); stepView = impl.RemoveStep(step4); Assert.AreEqual(FAILTURE, stepView.StatusCode); stepView = impl.RemoveStep(step2); Assert.AreEqual(FAILTURE, stepView.StatusCode); stepView = impl.RemoveStep(step1); Assert.AreEqual(SUCCESS, stepView.StatusCode); }
public void GetStepsByWorkflowIdTest() { InitData(); steps.Add(step1); StepDaoMock.Setup(f => f.GetStepsByWorkflowId(step1.Id)).Returns(steps); StepService impl = new StepService(StepDaoMock.Object, WorkflowDaoMock.Object, InstanceDaoMock.Object); stepView = impl.GetStepsByWorkflowId(step4); Assert.AreEqual(FAILTURE, stepView.StatusCode); stepView = impl.GetStepsByWorkflowId(step1); foreach (Step step in stepView.GetData()) { Assert.AreEqual(step.Id, step1.Id); } Assert.AreEqual(SUCCESS, stepView.StatusCode); }
/// <summary> /// Get the step model /// </summary> /// <returns></returns> private Step GetStep() { if (_step == null) { var stepId = PageParameter(ParameterKey.StepId).AsIntegerOrNull(); if (stepId.HasValue) { var rockContext = GetRockContext(); var service = new StepService(rockContext); _step = service.Get(stepId.Value); } if (_step != null) { hfStepId.Value = _step.Id.ToString(); } } return(_step); }
public object GetIndex(string ElementId, Guid ProcessId) { using (TaskService taskService = new TaskService()) { TaskDTO task = new TaskDTO(taskService.GetInfo(ElementId, ProcessId)); using (DepartmentService departmentService = new DepartmentService()) using (UserService userService = new UserService()) //for access using (LURowService luRowService = new LURowService()) using (DynamicFormService dynamicFormService = new DynamicFormService()) using (ProcessService processService = new ProcessService()) using (StepService stepService = new StepService()) return new { ListSteps = stepService.GetList(task.ID, null).Select(c => new StepDTO(c)).ToList(), AllowEdit = processService.GetInfo(ProcessId).AllowEdit(), RoleAccessTypes = EnumObjHelper.GetEnumList <UserTaskRuleModel.e_RoleAccessType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(), UserAccessTypes = EnumObjHelper.GetEnumList <UserTaskRuleModel.e_UserAccessType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(), UserTypes = EnumObjHelper.GetEnumList <UserTaskRuleModel.e_UserType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(), Departments = departmentService.GetList(true, "", null).Select(c => new QueryModel(c.ID.ToString(), c.Name)).ToList(), Users = userService.GetList("", null).Select(c => new QueryModel(c.ID.ToString(), c.FullName)).ToList(), UsersJson = (task.MarkerTypeLU.HasValue ? userService.GetList("", null) : new List <sysBpmsUser>()).Select(c => new ComboTreeModel() { id = c.ID.ToString(), title = c.FullName }).ToList(), OwnerTypes = luRowService.GetList(sysBpmsLUTable.e_LUTable.LaneOwnerTypeLU.ToString()).Select(c => new QueryModel(c.CodeOf, c.NameOf)).ToList(), RoleNames = luRowService.GetList("DepartmentRoleLU").Select(c => new QueryModel(c.CodeOf, c.NameOf)).ToList(), DynamicForms = dynamicFormService.GetList(ProcessId, null, false, string.Empty, null, null).Select(c => new QueryModel(c.ID.ToString(), c.Name)).ToList(), RoleNamesJson = luRowService.GetList("DepartmentRoleLU").Select(c => new ComboTreeModel() { id = c.CodeOf, title = c.NameOf, }).ToList(), Model = task, }; } }
public void AddStepTest() { InitData(); StepDaoMock.Setup(f => f.GetOneStepByNameAndWorkflowId(step1)).Returns(step1); // StepDaoMock.Setup(f => f.GetOneStepByName(step2)).Returns(step3); // StepDaoMock.Setup(f => f.GetOneStepByNameAndWorkflowId(step1)). //StepDaoMock. StepDaoMock.Setup(f => f.CreateStep(step2)).Returns(true); StepService impl = new StepService(StepDaoMock.Object, WorkflowDaoMock.Object, InstanceDaoMock.Object); // stepView = impl.AddStep(step4); Assert.AreEqual(FAILTURE, stepView.StatusCode); stepView = impl.AddStep(step1); Assert.AreEqual(REPETITION, stepView.StatusCode); //stepView = impl.AddStep(step2); //Assert.AreEqual(SUCCESS, stepView.StatusCode); }
/// <summary> /// These are people that cannot have new step because they already /// have one and are within the minimum date range. /// </summary> /// <param name="stepTypeView">The step type view.</param> /// <param name="rockContext"></param> /// <param name="minDaysBetweenSteps"></param> /// <returns></returns> private IQueryable <int> GetPeopleThatCannotGetStepQuery(RockContext rockContext, StepTypeView stepTypeView, int minDaysBetweenSteps) { var stepService = new StepService(rockContext); var minStepDate = DateTime.MinValue; // We are querying for people that will ultimately be excluded from getting a new // step created from this job. // If duplicates are not allowed, then we want to find anyone with a step ever // If duplicates are allowed and a day range is set, then it is within that timeframe. if (stepTypeView.AllowMultiple && minDaysBetweenSteps >= 1) { minStepDate = RockDateTime.Now.AddDays(0 - minDaysBetweenSteps); } var query = stepService.Queryable().AsNoTracking() .Where(s => s.StepTypeId == stepTypeView.StepTypeId && (!s.CompletedDateTime.HasValue || s.CompletedDateTime.Value >= minStepDate)) .Select(s => s.PersonAlias.PersonId); return(query); }
/// <summary> /// Delete the step with the given Id and then re-render the lists of steps /// </summary> /// <param name="stepId"></param> private void DeleteStep(int stepId) { var rockContext = GetRockContext(); var service = new StepService(rockContext); var step = service.Get(stepId); string errorMessage; if (step == null) { return; } if (!service.CanDelete(step, out errorMessage)) { ShowError(errorMessage); return; } service.Delete(step); rockContext.SaveChanges(); ClearBlockData(); }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = value; Step step = null; using (var rockContext = new RockContext()) { Guid?guid = value.AsGuidOrNull(); if (guid.HasValue) { step = new StepService(rockContext).GetNoTracking(guid.Value); } if (step != null) { formattedValue = step.ToString(); } } return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed)); }
/// <summary> /// Adds the step. /// </summary> /// <param name="stepTypeId">The step type identifier.</param> /// <param name="stepStatusId">The step status identifier.</param> /// <param name="personAliasId">The person alias identifier.</param> private static void AddStep(int stepTypeId, int stepStatusId, int personAliasId) { var rockContext = new RockContext(); var stepService = new StepService(rockContext); var step = new Step { StepTypeId = stepTypeId, StepStatusId = stepStatusId, CompletedDateTime = RockDateTime.Today, PersonAliasId = personAliasId }; // If the person cannot be added to the step type, then don't add anything since some step types only allow one step // or require pre-requisites if (stepService.CanAdd(step, out _)) { stepService.Add(step); } rockContext.SaveChanges(); }