HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Job applicant email system

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
systemapplicantjobemail

Problem

I just wrote this and don't like how bulky it is, also given the fact I will have to add at least another if statement.

I was going to switch it to a case statement but wanted to check if there were even better ways to reduce the clutter.

string emailLetterPath = Server.MapPath("~/emails/rejected.htm");

if (jobApplicantAndJob.Jobs.Title == "Store Sales Manager" || jobApplicantAndJob.Jobs.Title == "Sales Representative")
{
     emailLetterPath = Server.MapPath("~/emails/TC1RejectedP3.htm");
}

if (jobApplicantAndJob.Jobs.Title == "Outside Sales Professional")
{
     emailLetterPath = Server.MapPath("~/emails/TC2RejectedP3.htm");
}


The default option should be the rejected.htm.

Solution

I was going to switch it to a case statement but wanted to check if there were even better ways to reduce the clutter.

You could load the mappings from job titles to emails into a (static) dictionary, and then do a dictionary look-up (using the default value if it's not in the dictionary).

The Dictionary can be initialized with a collection initializer.

Using a (data-driven) dictionary instead of a (hard-coded) switch statement has the additional benefit that users can configure/maintain the behaviour by editing a configuration file (e.g. a tab-delimited 'CSV file' of title/email pairs) or database, instead of editing code.

Context

StackExchange Code Review Q#40982, answer score: 7

Revisions (0)

No revisions yet.