🪟 Windows TippsWindows 10 weiter stabil - die Nutzerzahlen im August 2026(05.09.2026 um 18:20 Uhr)
🐧 Linux TippsCC2tv #433: Was CachyOS anders macht als Linux Mint 🐧️(29.08.2026 um 10:00 Uhr)
🔧 ProgrammierungArti 2.6.0 released(01.09.2026 um 02:00 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.393.0 (24.08.2026)(24.08.2026 um 17:26 Uhr)
🪟 Windows TippsGitHub Release: dependabot/dependabot-core v0.394.0 (31.08.2026)(31.08.2026 um 17:46 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.4.0 (26.08.2026)(26.08.2026 um 09:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🪟 Windows TippsWindows 10 weiter stabil - die Nutzerzahlen im August 2026(05.09.2026 um 18:20 Uhr)
🐧 Linux TippsCC2tv #433: Was CachyOS anders macht als Linux Mint 🐧️(29.08.2026 um 10:00 Uhr)
🔧 ProgrammierungArti 2.6.0 released(01.09.2026 um 02:00 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.393.0 (24.08.2026)(24.08.2026 um 17:26 Uhr)
🪟 Windows TippsGitHub Release: dependabot/dependabot-core v0.394.0 (31.08.2026)(31.08.2026 um 17:46 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.4.0 (26.08.2026)(26.08.2026 um 09:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 5 Min Lesezeit
0

Simplifying Workflow Execution with Action Mapping in C#

↗ Quelle (dev.to)
🗣️ Stimme:

Efficiently managing workflows in code is essential for maintainability and readability, particularly in complex systems. This shows how to use a "Dictionary" to map keys to corresponding methods for streamlined execution, avoiding repetitive conditional logic. Here is a very brief overview of involving Twilio-based pharmacy communications.



Code Overview

Step 1: Prepare Input Data

The "msg_info" list (a List>), is populated by a helper function named "TwilioFunctions.GetMsgTypeByConv". It retrieves message-specific details from SQL that are then passed into the workflows for further processing. I store the helper function in a common shared class file named "TwilioFunctions".




CODE
List<KeyValuePair<string, string>> msg_info = TwilioFunctions.GetMsgTypeByConv(pat_id.ToString(), accountSid, ConversationSid, "Email");






Step 2: Define the Action Map

Using a Dictionary, I map specific keys to actions that invoke the "ProcessEmailByStoreParam" method with the appropriate parameters. This methodology simplifies the workflow by eliminating verbose if-else or switch statements. Additionally, adding a new action is as simple as adding a new key-value pair to the "actionMap" dictionary.




CODE
var actionMap = new Dictionary<string, Action>
{
{ "SC_TXT_NEWRX_MSG_Y", () => ProcessEmailByStoreParam("Y", msg_info, ConversationSid, patientResponse, accountSid, false) },

{ "SC_TXT_NEWRX_MSG_N", () => ProcessEmailByStoreParam("N", msg_info, ConversationSid, patientResponse, accountSid, false) },

{ "SC_TXT_PREREFILL_MSG_Y", () => ProcessEmailByStoreParam("Y", msg_info, ConversationSid, patientResponse, accountSid, false) },

{ "SC_TXT_PREREFILL_MSG_N", () => ProcessEmailByStoreParam("N", msg_info, ConversationSid, patientResponse, accountSid, false) },

// additional actions can be added as required
};






Step 3: Execute Actions Based on Keys

The "perfaction" parameter (contains the action to perform) is checked against the keys in the "actionMap" dictionary. If a match is found then the associated action is executed; otherwise, an error view is returned.




CODE
// check if the key exists and invoke the associated action
if (actionMap.TryGetValue(perfaction, out var action))
{
action(); // execute the action
}
else
{
// the error to pass to the "ContactPharmacy" view
var model = new ErrorViewModel { ErrorMessage = "general error" };

ViewName = "ContactPharmacy"; // the cshtml view to load
return View(ViewName, model); // basically show the view
}






Step 4: Handle Email Processing Logic

The "ProcessEmailByStoreParam" method performs the heavy lifting by validating inputs and processing the workflow logic based on the "YN" parameter. This method ensures all critical fields are validated before proceeding and handles specific operations based on the "YN" value. It also returns an error view when required fields are missing or invalid.




CODE
public IActionResult ProcessEmailByStoreParam(string YN, List<KeyValuePair<string, string>> msg_keyValuePairs, string ConversationSid, PatientEmailResponse patientResponse, string accountSid, bool IsMulti)
{
string? ChatServiceSid = patientResponse.person?[0].ChatServiceSid;
string? ParticipantSid = patientResponse.person?[0].ParticipantSid;

// Validate essential parameters
if (string.IsNullOrEmpty(ConversationSid) || string.IsNullOrEmpty(ParticipantSid) || string.IsNullOrEmpty(accountSid))
{
var errorModel = new ErrorViewModel { ErrorMessage = "Required fields cannot be null" };
ViewName = "ContactPharmacy";
return View(ViewName, errorModel);
}

// Process based on YN value
if (YN == "N")
{
// logic for "N"
}

if (YN == "Y")
{
// logic for "Y"
}

return View();
}






The "ContactPharmacy" View




CODE
@model CustomAPI.Models.ErrorViewModel

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pharmacy Management System</title>
<link href="@Url.Content("~/css/main.css")" rel="stylesheet" />
</head>
<body>


<div class="image-container">
<table border="0" class="wfull">
<tr>
<td>
<img src="~/images/cppms.png" />
</td>
</tr>

<tr><td class="v60"></td></tr>

<tr>
<td class="patientmessagetext">
@Html.Raw($"An error occurred while processing your request.<br/><br/>Please contact the pharmacy for assistance.")
</td>
</tr>

<tr>
<td class="errortext">
@Html.Raw($"{Model.ErrorMessage}")
</td>
</tr>

<tr><td class="v60"></td></tr>
<tr><td class="v60"></td></tr>
</table>
</div>

</body>
</html>






The Model Definition




CODE
namespace CustomAPI.Models
{
public class ErrorViewModel
{
public string ErrorMessage { get; set; } = string.Empty; // avoid non-nullable property message

public static readonly ErrorViewModel Empty = new ErrorViewModel(); // static field to hold a global empty instance

public bool IsEmpty => string.IsNullOrEmpty(ErrorMessage); // property to check if the ErrorViewModel is "empty"
}
}






Advantages of Using Action Mapping




  1. Maintainability: Encapsulates logic for each action, making it easier to manage and extend.

  2. Readability: Simplifies workflows by eliminating verbose if-else or switch statements.

  3. Scalability: Adding new actions is as simple as extending the dictionary.

  4. Error Handling: Ensures proper validation and error reporting, making the system more robust.



Conclusion

By combining action mapping with methods like "ProcessEmailByStoreParam", I can achieve cleaner, more maintainable code for complex workflows. This simplifies decision-based logic, enhances scalability, and improves error handling, which makes it particularly useful in systems like pharmacy communications, where clarity and reliability are important.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Windows 10 und 11: Update zerschießt Druckfunktion und PDF-Export
1 Quelle
Nvidia killt Windows-10-Support - Bald keine Game-Ready-Treiber mehr
1 Quelle
Windows 10 weiter stabil - die Nutzerzahlen im August 2026
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Simplifying Workflow Execution with Action Mapping in C#

Thematisch verwandte Begriffe: Simplifying, Workflow, Execution, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...