Skip to content

Commit

Permalink
using Ditionary and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Nov 13, 2023
1 parent 9e607d2 commit 4372f92
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
@using OrchardCore.Workflows.Helpers
@using OrchardCore.Roles.Workflows.Activities
@using OrchardCore.Roles.Workflows.ViewModels

@model ActivityViewModel<GetUsersByRoleTask>

<header>
<h4>
<i class="fa-solid fa-user" aria-hidden="true"></i>@Model.Activity.GetTitleOrDefault(() => T["Get users in roles"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using OrchardCore.Roles.Workflows.ViewModels

@model GetUsersByRoleTaskViewModel

<div class="mb-3" asp-validation-class-for="OutputKeyName">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
@using OrchardCore.Workflows.Helpers
@using OrchardCore.Roles.Workflows.Activities
@using OrchardCore.Roles.Workflows.ViewModels

@model ActivityViewModel<UnassignUserRoleTask>

<header>
<h4>
<i class="fa-solid fa-user" aria-hidden="true"></i>@Model.Activity.GetTitleOrDefault(() => T["Unassign user from roles"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace OrchardCore.Roles.Workflows.Activities;

public class GetUsersByRoleTask : TaskActivity
public class GetUsersByRoleTask : TaskActivity<GetUsersByRoleTask>
{
private readonly UserManager<IUser> _userManager;
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
Expand All @@ -25,8 +25,6 @@ public GetUsersByRoleTask(UserManager<IUser> userManager, IWorkflowExpressionEva
S = localizer;
}

public override string Name => nameof(GetUsersByRoleTask);

public override LocalizedString DisplayText => S["Get Users by Role Task"];

public override LocalizedString Category => S["User"];
Expand All @@ -49,11 +47,12 @@ public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContex

public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
var propKeyName = await _expressionEvaluator.EvaluateAsync(OutputKeyName, workflowContext, null);
var outputKeyName = await _expressionEvaluator.EvaluateAsync(OutputKeyName, workflowContext, null);

if (!string.IsNullOrEmpty(propKeyName))
{
var usersInRole = new List<User>();
var usersInRole = new Dictionary<string, User>();

foreach (var role in Roles)
{
foreach(var u in await _userManager.GetUsersInRoleAsync(role))
Expand All @@ -63,15 +62,13 @@ public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti
continue;
}

usersInRole.Add(user);
usersInRole.TryAdd(user.UserId, user);
}
}
if (usersInRole.Count > 0)
{
workflowContext.Output[propKeyName] = usersInRole;

workflowContext.Output[outputKeyName] = usersInRole.Values;

return Outcomes("Done");
}
return Outcomes("Done");
}

return Outcomes("Failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace OrchardCore.Roles.Workflows.Activities;

public class UnassignUserRoleTask : TaskActivity
public class UnassignUserRoleTask : TaskActivity<UnassignUserRoleTask>
{
private readonly UserManager<IUser> _userManager;
private readonly IUserService _userService;
Expand All @@ -28,8 +28,6 @@ public UnassignUserRoleTask(UserManager<IUser> userManager, IUserService userSer
S = localizer;
}

public override string Name => nameof(UnassignUserRoleTask);

public override LocalizedString DisplayText => S["Unassign User Role Task"];

public override LocalizedString Category => S["User"];
Expand Down

0 comments on commit 4372f92

Please sign in to comment.